{
LOGI("ENTER");
- mOutputLayers.clear();
-
- for (auto& layer :mOutputLayerId) {
- if (layer.second < 0) {
- LOGE("Invalid output layer ID [%d]", layer.second);
- return INFERENCE_ENGINE_ERROR_INVALID_OPERATION;
- }
-
- inference_engine_tensor_info tensor_info;
-
- LOGI("mInterpreter->tensor(%d)->dims name[%s] size[%d] type[%d]",
- layer.second,
- mInterpreter->tensor(layer.second)->name,
- mInterpreter->tensor(layer.second)->dims->size,
- mInterpreter->tensor(layer.second)->type);
-
- std::vector<size_t> shape_nhwc;
- for (int idx = 0; idx < mInterpreter->tensor(layer.second)->dims->size; idx++)
- shape_nhwc.push_back(mInterpreter->tensor(layer.second)->dims->data[idx]);
-
- //tflite only supports NHWC (https://www.tensorflow.org/lite/guide/ops_compatibility).
- tensor_info.shape = shape_nhwc;
- tensor_info.shape_type = INFERENCE_TENSOR_SHAPE_NHWC;
- if (mInterpreter->tensor(layer.second)->type == kTfLiteUInt8) {
- LOGI("type is kTfLiteUInt8");
- tensor_info.data_type = INFERENCE_TENSOR_DATA_TYPE_UINT8;
- } else if (mInterpreter->tensor(layer.second)->type == kTfLiteInt8) {
- LOGI("type is kTfLiteInt8");
- tensor_info.data_type = INFERENCE_TENSOR_DATA_TYPE_INT8;
- } else if (mInterpreter->tensor(layer.second)->type == kTfLiteInt64) {
- LOGI("type is kTfLiteInt64");
- tensor_info.data_type = INFERENCE_TENSOR_DATA_TYPE_INT64;
- } else if (mInterpreter->tensor(layer.second)->type == kTfLiteFloat32) {
- LOGI("type is kTfLiteFloat32");
- tensor_info.data_type = INFERENCE_TENSOR_DATA_TYPE_FLOAT32;
- } else {
- LOGE("Not supported");
- return INFERENCE_ENGINE_ERROR_NOT_SUPPORTED_FORMAT;
- }
- tensor_info.size = 1;
-
- for (auto & dim : tensor_info.shape)
- tensor_info.size *= dim;
-
- mOutputLayers.insert(std::make_pair(mInterpreter->tensor(layer.second)->name, tensor_info));
- }
-
+ SetInterpreterInfo();
property.layers = mOutputLayers;
LOGI("LEAVE");
std::map<std::string, int>& layerId)
{
layers.clear();
- for (auto& layer : layerId) {
+ for (auto& layer : layerId) {
+ const TfLiteTensor *tensor = mInterpreter->tensor(layer.second);
+ if (!tensor) {
+ LOGE("tensor for tensor index(%d) is null", layer.second);
+ return INFERENCE_ENGINE_ERROR_INVALID_OPERATION;
+ }
std::vector<size_t> shape_nhwc;
- for (int idx = 0; idx < mInterpreter->tensor(layer.second)->dims->size; idx++)
- shape_nhwc.push_back(mInterpreter->tensor(layer.second)->dims->data[idx]);
+ for (int idx = 0; idx < tensor->dims->size; idx++)
+ shape_nhwc.push_back(tensor->dims->data[idx]);
+ //tflite only supports NHWC (https://www.tensorflow.org/lite/guide/ops_compatibility).
inference_engine_tensor_info tensor_info {
shape_nhwc, INFERENCE_TENSOR_SHAPE_NHWC,
- INFERENCE_TENSOR_DATA_TYPE_NONE, 1
+ INFERENCE_TENSOR_DATA_TYPE_NONE, 1, 0.0f, 0
};
- switch (mInterpreter->tensor(layer.second)->type) {
+ switch (tensor->type) {
case kTfLiteUInt8:
LOGI("type is kTfLiteUInt8");
tensor_info.data_type = INFERENCE_TENSOR_DATA_TYPE_UINT8;
for (auto& dim : tensor_info.shape)
tensor_info.size *= dim;
- layers.insert(std::make_pair(mInterpreter->tensor(layer.second)->name, tensor_info));
+ if (tensor->quantization.type == kTfLiteAffineQuantization) {
+ auto *quant_parms = reinterpret_cast<TfLiteAffineQuantization *>(tensor->quantization.params);
+
+ if (quant_parms) {
+ tensor_info.scale = quant_parms->scale->data[0];
+ tensor_info.zero_point = quant_parms->zero_point->data[0];
+
+ LOGD("scale of %s : %f", tensor->name, tensor_info.scale);
+ LOGD("zero_point of %s : %d", tensor->name, tensor_info.zero_point);
+ }
+
+ }
+
+ layers.insert(std::make_pair(tensor->name, tensor_info));
}
+
return INFERENCE_ENGINE_ERROR_NONE;
}