From 2eb8b9af8fe9df169b00b1d1f3d108e3930777fd Mon Sep 17 00:00:00 2001 From: Inki Dae Date: Tue, 5 Nov 2024 11:43:25 +0900 Subject: [PATCH] add scale and zero_point members to tensor info [Version] : 0.5.0 [Issue type] : new feature Add scale and zero_point menbers to tensor info. In case of quantization model, there are some cases that user want to get scale and zero_point values to a given tensor to dequantize the tensor value to floting point data. Change-Id: Ibbb55d97bba639d3069c0133b243746057f8d8bb Signed-off-by: Inki Dae --- include/inference_engine_type.h | 2 ++ packaging/inference-engine-interface.spec | 2 +- test/src/inference_engine_profiler.cpp | 27 ++++++++++++++++------- test/src/inference_engine_tc.cpp | 19 +++++++++++----- tools/src/inference_engine_cltuner.cpp | 4 ++-- 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/include/inference_engine_type.h b/include/inference_engine_type.h index 702c8d7..243af02 100644 --- a/include/inference_engine_type.h +++ b/include/inference_engine_type.h @@ -209,6 +209,8 @@ extern "C" inference_tensor_shape_type_e shape_type; /**< a tensor shape of the layer. */ inference_tensor_data_type_e data_type; /**< a tensor type of the layer. */ size_t size; /** tensor element size. The size should be height * width * channel count */ + float scale; /**< a scale value of the layer. */ + int zero_point; /**< a zero point value of the layer. */ // TODO. } inference_engine_tensor_info; diff --git a/packaging/inference-engine-interface.spec b/packaging/inference-engine-interface.spec index dc65358..f425ebb 100644 --- a/packaging/inference-engine-interface.spec +++ b/packaging/inference-engine-interface.spec @@ -1,6 +1,6 @@ Name: inference-engine-interface Summary: Interface of inference engines -Version: 0.4.10 +Version: 0.5.0 Release: 0 Group: Multimedia/Framework License: Apache-2.0 diff --git a/test/src/inference_engine_profiler.cpp b/test/src/inference_engine_profiler.cpp index c434cf5..15786fb 100644 --- a/test/src/inference_engine_profiler.cpp +++ b/test/src/inference_engine_profiler.cpp @@ -257,7 +257,8 @@ TEST_P(InferenceEngineTfliteTest, Inference) { 1, ch, height, width }, (inference_tensor_shape_type_e) INFERENCE_TENSOR_SHAPE_NCHW, (inference_tensor_data_type_e) tensor_type, - (size_t)(1 * ch * height * width) + (size_t)(1 * ch * height * width), + 0.0f, 0 }; for (auto& layer : input_layers) { @@ -273,7 +274,9 @@ TEST_P(InferenceEngineTfliteTest, Inference) std::vector{1}, INFERENCE_TENSOR_SHAPE_NCHW, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, - 1 + 1, + 0.0f, + 0 }; for (auto& layer : output_layers) { @@ -454,7 +457,8 @@ TEST_P(InferenceEngineTfliteCLTunerTest, Inference) { 1, ch, height, width }, INFERENCE_TENSOR_SHAPE_NCHW, static_cast(tensor_type), - static_cast(1 * ch * height * width) + static_cast(1 * ch * height * width), + 0.0f, 0 }; for (auto& input : input_layers) { @@ -470,7 +474,9 @@ TEST_P(InferenceEngineTfliteCLTunerTest, Inference) std::vector{1}, INFERENCE_TENSOR_SHAPE_NCHW, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, - 1 + 1, + 0.0f, + 0 }; for (auto& layer : output_layers) { @@ -625,7 +631,8 @@ TEST_P(InferenceEngineCaffeTest, Inference) { 1, ch, height, width }, INFERENCE_TENSOR_SHAPE_NCHW, (inference_tensor_data_type_e) tensor_type, - (size_t)(1 * ch * height * width) + (size_t)(1 * ch * height * width), + 0.0f, 0 }; for (auto& layer : input_layers) { @@ -641,7 +648,9 @@ TEST_P(InferenceEngineCaffeTest, Inference) std::vector{1}, INFERENCE_TENSOR_SHAPE_NCHW, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, - 1 + 1, + 0.0f, + 0 }; for (auto& layer : output_layers) { @@ -789,7 +798,8 @@ TEST_P(InferenceEngineDldtTest, Inference) { 1, ch, height, width }, INFERENCE_TENSOR_SHAPE_NCHW, (inference_tensor_data_type_e) tensor_type, - (size_t)(1 * ch * height * width) + (size_t)(1 * ch * height * width), + 0.0f, 0 }; for (auto& layer : input_layers) { @@ -805,7 +815,8 @@ TEST_P(InferenceEngineDldtTest, Inference) { 1, ch, height, width }, INFERENCE_TENSOR_SHAPE_NCHW, (inference_tensor_data_type_e) tensor_type, - (size_t)(1 * ch * height * width) + (size_t)(1 * ch * height * width), + 0.0f, 0 }; for (auto& layer : output_layers) { diff --git a/test/src/inference_engine_tc.cpp b/test/src/inference_engine_tc.cpp index b84ee4f..f8d8bca 100644 --- a/test/src/inference_engine_tc.cpp +++ b/test/src/inference_engine_tc.cpp @@ -329,7 +329,8 @@ TEST_P(InferenceEngineTestCase_G4, SetInputLayer_P) { 1, ch, height, width }, (inference_tensor_shape_type_e) INFERENCE_TENSOR_SHAPE_NCHW, (inference_tensor_data_type_e) tensor_type, - (size_t)(1 * ch * height * width) + (size_t)(1 * ch * height * width), + 0.0f, 0 }; input_property.layers.insert(std::make_pair(layer, tensor_info)); @@ -365,7 +366,8 @@ TEST_P(InferenceEngineTestCase_G5, SetInputLayer_N1) { 1, ch, height, width }, (inference_tensor_shape_type_e) INFERENCE_TENSOR_SHAPE_NCHW, (inference_tensor_data_type_e) tensor_type, - (size_t)(1 * ch * height * width) + (size_t)(1 * ch * height * width), + 0.0f, 0 }; output_property.layers.insert(std::make_pair(layer, tensor_info)); @@ -421,7 +423,8 @@ TEST_P(InferenceEngineTestCase_G4, SetOutputLayer_P) { 1, ch, height, width }, (inference_tensor_shape_type_e) INFERENCE_TENSOR_SHAPE_NCHW, (inference_tensor_data_type_e) tensor_type, - (size_t)(1 * ch * height * width) + (size_t)(1 * ch * height * width), + 0.0f, 0 }; output_property.layers.insert(std::make_pair(layer, tensor_info)); @@ -457,7 +460,8 @@ TEST_P(InferenceEngineTestCase_G5, SetOutputLayer_N1) { 1, ch, height, width }, (inference_tensor_shape_type_e) INFERENCE_TENSOR_SHAPE_NCHW, (inference_tensor_data_type_e) tensor_type, - (size_t)(1 * ch * height * width) + (size_t)(1 * ch * height * width), + 0.0f, 0 }; output_property.layers.insert(std::make_pair(layer, tensor_info)); @@ -570,7 +574,8 @@ TEST_P(InferenceEngineTestCase_G6, Inference_P) { 1, ch, height, width }, (inference_tensor_shape_type_e) INFERENCE_TENSOR_SHAPE_NCHW, (inference_tensor_data_type_e) tensor_type, - (size_t)(1 * ch * height * width) + (size_t)(1 * ch * height * width), + 0.0f, 0 }; for (auto& layer : input_layers) { @@ -585,7 +590,9 @@ TEST_P(InferenceEngineTestCase_G6, Inference_P) inference_engine_tensor_info output_tensor_info = { std::vector{1}, INFERENCE_TENSOR_SHAPE_NCHW, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, - 1}; + 1, + 0.0f, + 0}; for (auto& layer : output_layers) { output_property.layers.insert(std::make_pair(layer, output_tensor_info)); } diff --git a/tools/src/inference_engine_cltuner.cpp b/tools/src/inference_engine_cltuner.cpp index 5c81450..aa082fa 100644 --- a/tools/src/inference_engine_cltuner.cpp +++ b/tools/src/inference_engine_cltuner.cpp @@ -96,7 +96,7 @@ int ConfigureInputInfo(InferenceEngineCommon* backend, Metadata& metadata, inference_engine_layer_property property; for (auto& name : tensorConfig.mInputLayerNames) { - inference_engine_tensor_info tensor_info; + inference_engine_tensor_info tensor_info {}; tensor_info.data_type = tensorConfig.mDataType; tensor_info.shape_type = INFERENCE_TENSOR_SHAPE_NCHW; @@ -166,7 +166,7 @@ int ConfigureOutputInfo(InferenceEngineCommon* backend, Metadata& metadata, inference_engine_layer_property property; inference_engine_tensor_info tensor_info = { std::vector{1}, INFERENCE_TENSOR_SHAPE_NCHW, - INFERENCE_TENSOR_DATA_TYPE_FLOAT32, 1}; + INFERENCE_TENSOR_DATA_TYPE_FLOAT32, 1, 0.0f, 0}; for (auto& name : tensorConfig.mOutputLayerNames) { LOGI("Configure %s layer as output", name.c_str()); -- 2.34.1