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

Method QuantizeTensor

tensorflow/lite/kernels/test_util.h:527–550  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

525 }
526
527 std::vector<int8_t> QuantizeTensor(int index,
528 const std::vector<float>& data) {
529 TfLiteTensor* t = interpreter_->tensor(index);
530 const int length = data.size();
531 std::vector<int8_t> q(length);
532 float min, max, scaling_factor;
533 tensor_utils::SymmetricQuantizeFloats(data.data(), length, q.data(), &min,
534 &max, &scaling_factor);
535 // Update quantization params.
536 t->params.scale = scaling_factor;
537 t->params.zero_point = 0;
538 // Populate the new quantization params.
539 TfLiteQuantizationFree(&t->quantization);
540 t->quantization.type = kTfLiteAffineQuantization;
541 auto* affine_quantization = reinterpret_cast<TfLiteAffineQuantization*>(
542 malloc(sizeof(TfLiteAffineQuantization)));
543 affine_quantization->quantized_dimension = 0;
544 affine_quantization->scale = TfLiteFloatArrayCreate(1);
545 affine_quantization->zero_point = TfLiteIntArrayCreate(1);
546 affine_quantization->scale->data[0] = scaling_factor;
547 affine_quantization->zero_point->data[0] = 0;
548 t->quantization.params = affine_quantization;
549 return q;
550 }
551
552 std::map<int, TensorData> tensor_data_;
553 std::vector<int32_t> inputs_;

Callers

nothing calls this directly

Calls 7

TfLiteQuantizationFreeFunction · 0.85
TfLiteFloatArrayCreateFunction · 0.85
TfLiteIntArrayCreateFunction · 0.85
SymmetricQuantizeFloatsFunction · 0.50
tensorMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected