Lines Matching refs:model
17 #include "lang_id/common/flatbuffers/model-utils.h"
29 // Returns true if we have clear evidence that |model| fails its checksum.
31 // E.g., if |model| has the crc32 field, and the value of that field does not
35 bool ClearlyFailsChecksum(const Model &model) {
36 if (!flatbuffers::IsFieldPresent(&model, Model::VT_CRC32)) {
38 << "No CRC32, most likely an old model; skip CRC32 check";
41 const mobile::uint32 expected_crc32 = model.crc32();
42 const mobile::uint32 actual_crc32 = ComputeCrc2Checksum(&model);
44 SAFTM_LOG(ERROR) << "Corrupt model: different CRC32: " << actual_crc32
53 const Model *GetVerifiedModelFromBytes(const char *data, size_t num_bytes) {
61 SAFTM_LOG(ERROR) << "Not a valid Model flatbuffer";
64 const Model *model = GetModel(start);
65 if (model == nullptr) {
68 if (ClearlyFailsChecksum(*model)) {
71 return model;
74 const ModelInput *GetInputByName(const Model *model, const string &name) {
75 if (model == nullptr) {
76 SAFTM_LOG(ERROR) << "GetInputByName called with model == nullptr";
79 const auto *inputs = model->inputs();
111 bool FillParameters(const Model &model, mobile::TaskContext *context) {
116 const auto *parameters = model.parameters();
168 mobile::uint32 ComputeCrc2Checksum(const Model *model) {
170 // a CRC32 checksum of the model bytes. Unfortunately, the expected checksum
173 // we traverse |model| and feed into the CRC32 computation those parts we are
176 // Note: storing the checksum outside the Model would be too disruptive for
179 if (model == nullptr) {
183 const auto *parameters = model->parameters();
193 const auto *inputs = model->inputs();