MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / QuantizeModel

Method QuantizeModel

tensorflow/lite/python/optimize/calibration_wrapper.cc:190–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188}
189
190PyObject* CalibrationWrapper::QuantizeModel(int input_py_type,
191 int output_py_type,
192 bool allow_float) {
193 TfLiteType input_type = python_utils::TfLiteTypeFromPyType(input_py_type);
194 TfLiteType output_type = python_utils::TfLiteTypeFromPyType(output_py_type);
195 if (input_type == kTfLiteNoType || output_type == kTfLiteNoType) {
196 PyErr_SetString(PyExc_ValueError,
197 "Input/output type cannot be kTfLiteNoType");
198 return nullptr;
199 }
200 auto tflite_model = CreateMutableModel(*model_->GetModel());
201 reader_->AddCalibrationToModel(tflite_model.get(), /*update=*/false);
202 flatbuffers::FlatBufferBuilder builder;
203 auto status = tflite::optimize::QuantizeModel(
204 &builder, tflite_model.get(), TfLiteTypeToSchemaType(input_type),
205 TfLiteTypeToSchemaType(output_type), allow_float, error_reporter_.get());
206 if (status != kTfLiteOk) {
207 error_reporter_->exception();
208 return nullptr;
209 }
210
211 return python_utils::ConvertToPyString(
212 reinterpret_cast<const char*>(builder.GetCurrentBufferPointer()),
213 builder.GetSize());
214}
215
216/*static*/ CalibrationWrapper* CalibrationWrapper::CreateWrapperCPPFromBuffer(
217 PyObject* data) {

Callers 1

Calls 10

TfLiteTypeFromPyTypeFunction · 0.85
CreateMutableModelFunction · 0.85
ConvertToPyStringFunction · 0.85
AddCalibrationToModelMethod · 0.80
exceptionMethod · 0.80
TfLiteTypeToSchemaTypeFunction · 0.70
QuantizeModelFunction · 0.50
GetModelMethod · 0.45
getMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected