Those metadata are user unfriendly and difficult to use because of a lack of decscription.
They are changed to string and user can understand what they mean.
The string values are parsed and converted to proper enumerations.
Change-Id: Ia98f29790d68fe2bf2fb38e2e922cc0b9b4d80e4
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
"tensor_info" : [
{
"name" : "input_2",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 224, 224, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
`tensor_info` which has knowledge of an input tensor such as
- `name`: name to an input tensor
-- `shape_type`: shape type of the input tensor on `NCHW = 0` and `NHWC = 1`
+- `shape_type`: shape type of the input tensor on `NCHW` and `NHWC`
- `shape_dims`: shape dimensions based on the `shape_type`
- `data_type`: data type of the input tensor on `MV_INFERENCE_DATA_FLOAT32 = 0` and `MV_INFERENCE_DATA_UINT8 = 1`
- `color_space`: color space of the input tensor.
"tensor_info" : [
{
"name" : "input",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 128, 128, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "normalized_input_image_tensor",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 300, 300, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "input",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 192, 192, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "Placeholder",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 128, 128, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "Placeholder",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 224, 224, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "input",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 299, 299, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "input",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 299, 299, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "input",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 299, 299, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "input",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 224, 224, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "input",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 224, 224, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "input",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 224, 224, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "input",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 224, 224, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "input",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 299, 299, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "Placeholder",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 224, 224, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "input_2",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 224, 224, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "input",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 224, 224, 3],
- "data_type" : 1,
+ "data_type" : "UNIT8",
"color_space" : "RGB888"
}
]
"tensor_info" : [
{
"name" : "normalized_input_image_tensor",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 300, 300, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "normalized_input_image_tensor",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 320, 320, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "image",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 192, 192, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
"tensor_info" : [
{
"name" : "sub_2",
- "shape_type" : 1,
+ "shape_type" : "NHWC",
"shape_dims" : [ 1, 257, 257, 3],
- "data_type" : 0,
+ "data_type" : "FLOAT32",
"color_space" : "RGB888"
}
],
*
* @since_tizen 6.5
*/
- InputMetadata() : parsed(false) {};
+ InputMetadata();
/**
* @brief Destroys an InputMetadata class instance including
int Parse(JsonObject *root);
private:
+ std::map<std::string, inference_tensor_shape_type_e> mSupportedShapeType;
+ std::map<std::string, mv_inference_data_type_e> mSupportedDataType;
+ std::map<std::string, mv_colorspace_e> mSupportedColorSpace;
+
+ template <typename T>
+ static T GetSupportedType(JsonObject* root, std::string typeName,
+ std::map<std::string, T>& supportedTypes);
int GetTensorInfo(JsonObject* root);
int GetPreProcess(JsonObject* root);
- mv_colorspace_e ConvertTypeToMD(const std::string& type);
};
{
namespace inference
{
- mv_colorspace_e InputMetadata::ConvertTypeToMD(const std::string& type)
+ InputMetadata::InputMetadata() :
+ parsed(false),
+ layer(),
+ option()
{
- mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
- if (type.empty()) {
- LOGE("Invalid type[null]");
- return colorspace;
- }
+ // shape_type
+ mSupportedShapeType.insert({"NCHW", INFERENCE_TENSOR_SHAPE_NCHW});
+ mSupportedShapeType.insert({"NHWC", INFERENCE_TENSOR_SHAPE_NHWC});
+
+ // data_type
+ mSupportedDataType.insert({"FLOAT32", MV_INFERENCE_DATA_FLOAT32});
+ mSupportedDataType.insert({"UINT8", MV_INFERENCE_DATA_UINT8});
- if (type.compare("RGB888") == 0) {
- colorspace = MEDIA_VISION_COLORSPACE_RGB888;
- } else if (type.compare("Y800") == 0) {
- colorspace = MEDIA_VISION_COLORSPACE_Y800;
- } else {
- LOGE("Not supported channel type");
+ // color_space
+ mSupportedColorSpace.insert({"RGB888", MEDIA_VISION_COLORSPACE_RGB888});
+ mSupportedColorSpace.insert({"GRAY8", MEDIA_VISION_COLORSPACE_Y800});
+ }
+
+ template <typename T>
+ T InputMetadata::GetSupportedType(JsonObject* root, std::string typeName,
+ std::map<std::string, T>& supportedTypes)
+ {
+ auto supportedType = supportedTypes.find(json_object_get_string_member(root, typeName.c_str()));
+ if (supportedType == supportedTypes.end()) {
+ throw std::invalid_argument(typeName);
}
- return colorspace;
+ LOGI("%s: %d:%s", typeName.c_str(), supportedType->second, supportedType->first.c_str());
+
+ return supportedType->second;
}
int InputMetadata::GetTensorInfo(JsonObject *root)
}
// tensor_info
+ int ret = MEDIA_VISION_ERROR_NONE;
JsonArray * rootArray = json_object_get_array_member(root, "tensor_info");
unsigned int elements = json_array_get_length(rootArray);
static_cast<const char*>(json_object_get_string_member(pObject,"name"));
LOGI("layer: %s", info.name.c_str());
- info.shapeType =
- static_cast<inference_tensor_shape_type_e>(json_object_get_int_member(pObject, "shape_type"));
- LOGI("shape type: %d:%s", info.shapeType, info.shapeType == 0 ? "NCHW" : "NHWC");
-
- info.dataType =
- static_cast<mv_inference_data_type_e>(json_object_get_int_member(pObject, "data_type"));
- LOGI("data type : %d:%s", info.dataType, info.dataType == 0 ? "FLOAT32" : "UINT8");
-
- const char *colorSpace = static_cast<const char*>(json_object_get_string_member(pObject,"color_space"));
- info.colorSpace = ConvertTypeToMD(std::string(colorSpace));
- LOGI("color space : %d:%s", info.colorSpace, info.colorSpace == MEDIA_VISION_COLORSPACE_RGB888 ? "RGB888" : "");
+ try {
+ info.shapeType = GetSupportedType(pObject, "shape_type", mSupportedShapeType);
+ info.dataType = GetSupportedType(pObject, "data_type", mSupportedDataType);
+ info.colorSpace = GetSupportedType(pObject, "color_space", mSupportedColorSpace);
+ } catch (const std::exception& e) {
+ LOGE("Invalid %s", e.what());
+ return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ }
// dims
JsonArray * array = json_object_get_array_member(pObject, "shape_dims");
LOGI("LEAVE");
- return MEDIA_VISION_ERROR_NONE;
+ return ret;
}
int InputMetadata::GetPreProcess(JsonObject *root)
Name: capi-media-vision
Summary: Media Vision library for Tizen Native API
-Version: 0.8.6
+Version: 0.8.7
Release: 0
Group: Multimedia/Framework
License: Apache-2.0 and BSD-3-Clause