| 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_; |
nothing calls this directly
no test coverage detected