| 16 | { |
| 17 | |
| 18 | std::vector<char> CreateReduceTfLiteModel(tflite::BuiltinOperator reduceOperatorCode, |
| 19 | tflite::TensorType tensorType, |
| 20 | std::vector<int32_t>& input0TensorShape, |
| 21 | std::vector<int32_t>& input1TensorShape, |
| 22 | const std::vector <int32_t>& outputTensorShape, |
| 23 | std::vector<int32_t>& axisData, |
| 24 | const bool keepDims, |
| 25 | float quantScale = 1.0f, |
| 26 | int quantOffset = 0, |
| 27 | bool kTfLiteNoQuantizationForQuantized = false) |
| 28 | { |
| 29 | using namespace tflite; |
| 30 | flatbuffers::FlatBufferBuilder flatBufferBuilder; |
| 31 | |
| 32 | flatbuffers::Offset<tflite::Buffer> buffers[4] = { |
| 33 | CreateBuffer(flatBufferBuilder), |
| 34 | CreateBuffer(flatBufferBuilder), |
| 35 | CreateBuffer(flatBufferBuilder, |
| 36 | flatBufferBuilder.CreateVector(reinterpret_cast<const uint8_t*>(axisData.data()), |
| 37 | sizeof(int32_t) * axisData.size())), |
| 38 | CreateBuffer(flatBufferBuilder) |
| 39 | }; |
| 40 | |
| 41 | flatbuffers::Offset<tflite::QuantizationParameters> quantizationParametersAxis |
| 42 | = CreateQuantizationParameters(flatBufferBuilder); |
| 43 | |
| 44 | flatbuffers::Offset<tflite::QuantizationParameters> quantizationParameters; |
| 45 | |
| 46 | if (kTfLiteNoQuantizationForQuantized && reduceOperatorCode == BuiltinOperator_REDUCE_PROD) |
| 47 | { |
| 48 | if ((quantScale == 1 || quantScale == 0) && quantOffset == 0) |
| 49 | { |
| 50 | // Creates quantization parameter with quantization.type = kTfLiteNoQuantization |
| 51 | quantizationParameters = CreateQuantizationParameters(flatBufferBuilder); |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | // Creates quantization parameter with quantization.type != kTfLiteNoQuantization |
| 56 | quantizationParameters = CreateQuantizationParameters( |
| 57 | flatBufferBuilder, |
| 58 | 0, |
| 59 | 0, |
| 60 | flatBufferBuilder.CreateVector<float>({quantScale}), |
| 61 | flatBufferBuilder.CreateVector<int64_t>({quantOffset})); |
| 62 | } |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | quantizationParameters = CreateQuantizationParameters( |
| 67 | flatBufferBuilder, |
| 68 | 0, |
| 69 | 0, |
| 70 | flatBufferBuilder.CreateVector<float>({quantScale}), |
| 71 | flatBufferBuilder.CreateVector<int64_t>({quantOffset})); |
| 72 | } |
| 73 | |
| 74 | std::array<flatbuffers::Offset<Tensor>, 3> tensors; |
| 75 | tensors[0] = CreateTensor(flatBufferBuilder, |
no test coverage detected