summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKwanghoon Son <k.son@samsung.com>2022-09-06 00:16:02 -0400
committerKwanghoon Son <k.son@samsung.com>2022-09-06 19:41:29 -0400
commit0b4a1a80ad898cb0f5bb46a7fdd2781fafd66016 (patch)
tree4b0b8360c986cd7505591b587eaac9dcc4a82144
parent5cb9195ebffda79403a70253c74f8e91bb03a511 (diff)
downloadmediavision-0b4a1a80ad898cb0f5bb46a7fdd2781fafd66016.tar.gz
mediavision-0b4a1a80ad898cb0f5bb46a7fdd2781fafd66016.tar.bz2
mediavision-0b4a1a80ad898cb0f5bb46a7fdd2781fafd66016.zip
Refactoring Box, ScoreInfo
[Issue type] refactoring - split long header implementation - add missing header - remove 'this' accessor - class initialization Change-Id: I8014892edaceccadd9abcd9c1b45fc0dcd971e33 Signed-off-by: Kwanghoon Son <k.son@samsung.com>
-rw-r--r--mv_machine_learning/inference/include/BoxInfo.h43
-rw-r--r--mv_machine_learning/inference/include/ScoreInfo.h77
-rw-r--r--mv_machine_learning/inference/src/OutputMetadata.cpp168
-rw-r--r--mv_machine_learning/inference/src/ScoreInfo.cpp73
4 files changed, 178 insertions, 183 deletions
diff --git a/mv_machine_learning/inference/include/BoxInfo.h b/mv_machine_learning/inference/include/BoxInfo.h
index b3eb8293..131e6076 100644
--- a/mv_machine_learning/inference/include/BoxInfo.h
+++ b/mv_machine_learning/inference/include/BoxInfo.h
@@ -53,40 +53,29 @@ class BoxInfo
private:
std::vector<std::string> names;
DimInfo dimInfo;
- inference_box_type_e type; // 0:L-T-R-B, 1: Cx-Cy-W-H
+ inference_box_type_e type = INFERENCE_BOX_TYPE_ORIGIN_LEFTTOP; // 0:L-T-R-B, 1: Cx-Cy-W-H
std::vector<int> order; // Order based on box type
- inference_box_coordinate_type_e coordinate; // 0: ratio, 1: pixel
- inference_box_decoding_type_e decodingType; // 0: bypass , 1:ssd with anchor
+ inference_box_coordinate_type_e coordinate = INFERENCE_BOX_COORDINATE_TYPE_RATIO; // 0: ratio, 1: pixel
+ inference_box_decoding_type_e decodingType = INFERENCE_BOX_DECODING_TYPE_BYPASS; // 0: bypass , 1:ssd with anchor
DecodeInfo decodingInfo;
Label label;
Number number;
- std::map<std::string, inference_box_type_e> supportedBoxTypes;
- std::map<std::string, inference_box_coordinate_type_e> supportedBoxCoordinateTypes;
- std::map<std::string, inference_box_decoding_type_e> supportedBoxDecodingTypes;
+ std::map<std::string, inference_box_type_e> supportedBoxTypes = {
+ { "ORIGIN_LEFTTOP", INFERENCE_BOX_TYPE_ORIGIN_LEFTTOP },
+ { "ORIGIN_CENTER", INFERENCE_BOX_TYPE_ORIGIN_CENTER }
+ };
+ std::map<std::string, inference_box_coordinate_type_e> supportedBoxCoordinateTypes = {
+ { "RATIO", INFERENCE_BOX_COORDINATE_TYPE_RATIO },
+ { "PIXEL", INFERENCE_BOX_COORDINATE_TYPE_PIXEL }
+ };
+ std::map<std::string, inference_box_decoding_type_e> supportedBoxDecodingTypes = {
+ { "BYPASS", INFERENCE_BOX_DECODING_TYPE_BYPASS },
+ { "SSD_ANCHOR", INFERENCE_BOX_DECODING_TYPE_SSD_ANCHOR },
+ { "YOLO_ANCHOR", INFERENCE_BOX_DECODING_TYPE_YOLO_ANCHOR }
+ };
public:
- BoxInfo()
- : names()
- , dimInfo()
- , type(INFERENCE_BOX_TYPE_ORIGIN_LEFTTOP)
- , order()
- , coordinate(INFERENCE_BOX_COORDINATE_TYPE_RATIO)
- , decodingType(INFERENCE_BOX_DECODING_TYPE_BYPASS)
- , decodingInfo()
-
- {
- supportedBoxTypes.insert({ "ORIGIN_LEFTTOP", INFERENCE_BOX_TYPE_ORIGIN_LEFTTOP });
- supportedBoxTypes.insert({ "ORIGIN_CENTER", INFERENCE_BOX_TYPE_ORIGIN_CENTER });
-
- supportedBoxCoordinateTypes.insert({ "RATIO", INFERENCE_BOX_COORDINATE_TYPE_RATIO });
- supportedBoxCoordinateTypes.insert({ "PIXEL", INFERENCE_BOX_COORDINATE_TYPE_PIXEL });
-
- supportedBoxDecodingTypes.insert({ "BYPASS", INFERENCE_BOX_DECODING_TYPE_BYPASS });
- supportedBoxDecodingTypes.insert({ "SSD_ANCHOR", INFERENCE_BOX_DECODING_TYPE_SSD_ANCHOR });
- supportedBoxDecodingTypes.insert({ "YOLO_ANCHOR", INFERENCE_BOX_DECODING_TYPE_YOLO_ANCHOR });
- }
-
~BoxInfo() = default;
std::string GetName();
diff --git a/mv_machine_learning/inference/include/ScoreInfo.h b/mv_machine_learning/inference/include/ScoreInfo.h
index bf861c06..69a0d453 100644
--- a/mv_machine_learning/inference/include/ScoreInfo.h
+++ b/mv_machine_learning/inference/include/ScoreInfo.h
@@ -24,6 +24,7 @@
#include <mv_inference_type.h>
#include <mv_private.h>
+#include <OutputMetadataTypes.h>
#include "DimInfo.h"
#include "Utils.h"
@@ -45,26 +46,14 @@ class ScoreInfo
private:
std::vector<std::string> names;
DimInfo dimInfo;
- double threshold;
- int topNumber;
- inference_score_type_e type;
+ double threshold = 0.0;
+ int topNumber = 1;
+ inference_score_type_e type = INFERENCE_SCORE_TYPE_NORMAL;
std::shared_ptr<DeQuantization> deQuantization;
- std::map<std::string, inference_score_type_e> supportedScoreTypes;
+ std::map<std::string, inference_score_type_e> supportedScoreTypes = { { "NORMAL", INFERENCE_SCORE_TYPE_NORMAL },
+ { "SIGMOID", INFERENCE_SCORE_TYPE_SIGMOID } };
public:
- ScoreInfo()
- : names()
- , dimInfo()
- , threshold(0.0)
- , topNumber(1)
- , type(INFERENCE_SCORE_TYPE_NORMAL)
- , deQuantization(nullptr)
- {
- // Score type
- supportedScoreTypes.insert({ "NORMAL", INFERENCE_SCORE_TYPE_NORMAL });
- supportedScoreTypes.insert({ "SIGMOID", INFERENCE_SCORE_TYPE_SIGMOID });
- }
-
~ScoreInfo() = default;
std::string GetName()
@@ -100,59 +89,7 @@ public:
return deQuantization->zeropoint;
}
- int ParseScore(JsonObject *root)
- {
- LOGI("ENTER");
- if (!json_object_has_member(root, "score")) {
- LOGE("member score not exists");
- return MEDIA_VISION_ERROR_INVALID_PARAMETER;
- }
- JsonObject *pObject = json_object_get_object_member(root, "score");
-
- JsonArray *array = json_object_get_array_member(pObject, "name");
- MEDIA_VISION_NULL_ARG_CHECK(array);
-
- unsigned int elements1 = json_array_get_length(array);
- MEDIA_VISION_CHECK_CONDITION(elements1 > 0, MEDIA_VISION_ERROR_INVALID_PARAMETER, "No name on meta file");
-
- for (unsigned int elem1 = 0; elem1 < elements1; ++elem1) {
- names.push_back(json_array_get_string_element(array, elem1));
- }
-
- array = json_object_get_array_member(pObject, "index");
- unsigned int elements2 = json_array_get_length(array);
- LOGI("range dim: size[%u]", elements2);
- for (unsigned int elem2 = 0; elem2 < elements2; ++elem2) {
- if (static_cast<int>(json_array_get_int_element(array, elem2)) == 1)
- dimInfo.SetValidIndex(elem2);
- }
- if (json_object_has_member(pObject, "top_number"))
- topNumber = static_cast<int>(json_object_get_int_member(pObject, "top_number"));
- LOGI("top number: %d", topNumber);
-
- if (json_object_has_member(pObject, "threshold"))
- threshold = static_cast<double>(json_object_get_double_member(pObject, "threshold"));
- LOGI("threshold: %1.3f", threshold);
-
- try {
- type = GetSupportedType(pObject, "score_type", supportedScoreTypes);
- } catch (const std::exception &e) {
- LOGE("Invalid %s", e.what());
- return MEDIA_VISION_ERROR_INVALID_OPERATION;
- }
-
- if (json_object_has_member(pObject, "dequantization")) {
- array = json_object_get_array_member(pObject, "dequantization");
- JsonNode *node = json_array_get_element(array, 0);
- JsonObject *object = json_node_get_object(node);
-
- deQuantization = std::make_shared<DeQuantization>(json_object_get_double_member(object, "scale"),
- json_object_get_double_member(object, "zeropoint"));
- }
-
- LOGI("LEAVE");
- return MEDIA_VISION_ERROR_NONE;
- }
+ int ParseScore(JsonObject *root);
};
} /* Inference */
} /* MediaVision */
diff --git a/mv_machine_learning/inference/src/OutputMetadata.cpp b/mv_machine_learning/inference/src/OutputMetadata.cpp
index 4f44bb2c..2fb49e2d 100644
--- a/mv_machine_learning/inference/src/OutputMetadata.cpp
+++ b/mv_machine_learning/inference/src/OutputMetadata.cpp
@@ -82,34 +82,33 @@ int DecodeInfo::ParseAnchorParam(JsonObject *root)
{
JsonObject *object = json_object_get_object_member(root, "anchor");
- this->anchorParam.mode = static_cast<int>(json_object_get_int_member(object, "mode"));
-
- this->anchorParam.numLayers = static_cast<int>(json_object_get_int_member(object, "num_layers"));
- this->anchorParam.minScale = static_cast<float>(json_object_get_double_member(object, "min_scale"));
- this->anchorParam.maxScale = static_cast<float>(json_object_get_double_member(object, "max_scale"));
- this->anchorParam.inputSizeHeight = static_cast<int>(json_object_get_int_member(object, "input_size_height"));
- this->anchorParam.inputSizeWidth = static_cast<int>(json_object_get_int_member(object, "input_size_width"));
- this->anchorParam.anchorOffsetX = static_cast<float>(json_object_get_double_member(object, "anchor_offset_x"));
- this->anchorParam.anchorOffsetY = static_cast<float>(json_object_get_double_member(object, "anchor_offset_y"));
- this->anchorParam.isReduceBoxedInLowestLayer =
+ anchorParam.mode = static_cast<int>(json_object_get_int_member(object, "mode"));
+
+ anchorParam.numLayers = static_cast<int>(json_object_get_int_member(object, "num_layers"));
+ anchorParam.minScale = static_cast<float>(json_object_get_double_member(object, "min_scale"));
+ anchorParam.maxScale = static_cast<float>(json_object_get_double_member(object, "max_scale"));
+ anchorParam.inputSizeHeight = static_cast<int>(json_object_get_int_member(object, "input_size_height"));
+ anchorParam.inputSizeWidth = static_cast<int>(json_object_get_int_member(object, "input_size_width"));
+ anchorParam.anchorOffsetX = static_cast<float>(json_object_get_double_member(object, "anchor_offset_x"));
+ anchorParam.anchorOffsetY = static_cast<float>(json_object_get_double_member(object, "anchor_offset_y"));
+ anchorParam.isReduceBoxedInLowestLayer =
static_cast<bool>(json_object_get_boolean_member(object, "reduce_boxed_in_lowest_layer"));
- this->anchorParam.interpolatedScaleAspectRatio =
+ anchorParam.interpolatedScaleAspectRatio =
static_cast<float>(json_object_get_double_member(object, "interpolated_scale_aspect_ratio"));
- this->anchorParam.isFixedAnchorSize =
- static_cast<bool>(json_object_get_boolean_member(object, "fixed_anchor_size"));
- this->anchorParam.isExponentialBoxScale =
+ anchorParam.isFixedAnchorSize = static_cast<bool>(json_object_get_boolean_member(object, "fixed_anchor_size"));
+ anchorParam.isExponentialBoxScale =
static_cast<bool>(json_object_get_boolean_member(object, "exponential_box_scale"));
- this->anchorParam.xScale = static_cast<float>(json_object_get_double_member(object, "x_scale"));
- this->anchorParam.yScale = static_cast<float>(json_object_get_double_member(object, "y_scale"));
- this->anchorParam.wScale = static_cast<float>(json_object_get_double_member(object, "w_scale"));
- this->anchorParam.hScale = static_cast<float>(json_object_get_double_member(object, "h_scale"));
+ anchorParam.xScale = static_cast<float>(json_object_get_double_member(object, "x_scale"));
+ anchorParam.yScale = static_cast<float>(json_object_get_double_member(object, "y_scale"));
+ anchorParam.wScale = static_cast<float>(json_object_get_double_member(object, "w_scale"));
+ anchorParam.hScale = static_cast<float>(json_object_get_double_member(object, "h_scale"));
JsonArray *array = json_object_get_array_member(object, "strides");
unsigned int elements2 = json_array_get_length(array);
for (unsigned int elem2 = 0; elem2 < elements2; ++elem2) {
auto stride = static_cast<int>(json_array_get_int_element(array, elem2));
- this->anchorParam.strides.push_back(stride);
+ anchorParam.strides.push_back(stride);
LOGI("stride: %d", stride);
}
@@ -117,7 +116,7 @@ int DecodeInfo::ParseAnchorParam(JsonObject *root)
elements2 = json_array_get_length(array);
for (unsigned int elem2 = 0; elem2 < elements2; ++elem2) {
auto aspectRatio = static_cast<float>(json_array_get_double_element(array, elem2));
- this->anchorParam.aspectRatios.push_back(aspectRatio);
+ anchorParam.aspectRatios.push_back(aspectRatio);
LOGI("aspectRatio: %.4f", aspectRatio);
}
@@ -128,19 +127,19 @@ int DecodeInfo::ParseCellParam(JsonObject *root)
{
JsonObject *object = json_object_get_object_member(root, "cell");
- this->cellParam.numScales = static_cast<int>(json_object_get_int_member(object, "num_scales"));
+ cellParam.numScales = static_cast<int>(json_object_get_int_member(object, "num_scales"));
JsonArray *array = json_object_get_array_member(object, "scales");
unsigned int elements2 = json_array_get_length(array);
for (unsigned int elem2 = 0; elem2 < elements2; ++elem2) {
auto scale = static_cast<int>(json_array_get_int_element(array, elem2));
- this->cellParam.scales.push_back(scale);
+ cellParam.scales.push_back(scale);
LOGI("scale: %d", scale);
}
- this->cellParam.offsetScales = static_cast<int>(json_object_get_int_member(object, "offset_scales"));
+ cellParam.offsetScales = static_cast<int>(json_object_get_int_member(object, "offset_scales"));
try {
- this->cellParam.type = GetSupportedType(object, "type", this->cellParam.supportedCellType);
+ cellParam.type = GetSupportedType(object, "type", cellParam.supportedCellType);
} catch (const std::exception &e) {
LOGE("Invalid %s", e.what());
return MEDIA_VISION_ERROR_INVALID_OPERATION;
@@ -151,22 +150,22 @@ int DecodeInfo::ParseCellParam(JsonObject *root)
std::vector<int> &DecodeInfo::GetCellScalesAll()
{
- return this->cellParam.scales;
+ return cellParam.scales;
}
int DecodeInfo::GetCellNumScales()
{
- return this->cellParam.numScales;
+ return cellParam.numScales;
}
int DecodeInfo::GetCellOffsetScales()
{
- return this->cellParam.offsetScales;
+ return cellParam.offsetScales;
}
inference_score_type_e DecodeInfo::GetCellType()
{
- return this->cellParam.type;
+ return cellParam.type;
}
float DecodeInfo::CalculateScale(float min, float max, int index, int maxStride)
@@ -176,45 +175,45 @@ float DecodeInfo::CalculateScale(float min, float max, int index, int maxStride)
bool DecodeInfo::IsFixedAnchorSize()
{
- return this->anchorParam.isFixedAnchorSize;
+ return anchorParam.isFixedAnchorSize;
;
}
bool DecodeInfo::IsExponentialBoxScale()
{
- return this->anchorParam.isExponentialBoxScale;
+ return anchorParam.isExponentialBoxScale;
}
float DecodeInfo::GetAnchorXscale()
{
- return this->anchorParam.xScale;
+ return anchorParam.xScale;
}
float DecodeInfo::GetAnchorYscale()
{
- return this->anchorParam.yScale;
+ return anchorParam.yScale;
}
float DecodeInfo::GetAnchorWscale()
{
- return this->anchorParam.wScale;
+ return anchorParam.wScale;
}
float DecodeInfo::GetAnchorHscale()
{
- return this->anchorParam.hScale;
+ return anchorParam.hScale;
}
int DecodeInfo::GenerateAnchor()
{
- if (this->anchorParam.strides.empty() || this->anchorParam.aspectRatios.empty()) {
+ if (anchorParam.strides.empty() || anchorParam.aspectRatios.empty()) {
LOGE("Invalid anchor parameters");
return MEDIA_VISION_ERROR_INVALID_OPERATION;
}
int layerId = 0;
- this->ClearAnchorBox();
- while (layerId < this->anchorParam.numLayers) {
+ ClearAnchorBox();
+ while (layerId < anchorParam.numLayers) {
std::vector<float> anchorHeight;
std::vector<float> anchorWidth;
std::vector<float> aspectRatios;
@@ -222,12 +221,12 @@ int DecodeInfo::GenerateAnchor()
int lastSameStrideLayer = layerId;
std::vector<float>::iterator iter1, iter2;
- while ((lastSameStrideLayer < this->anchorParam.numLayers) &&
- (this->anchorParam.strides[lastSameStrideLayer] == this->anchorParam.strides[layerId])) {
- const float scale = CalculateScale(this->anchorParam.minScale, this->anchorParam.maxScale,
- lastSameStrideLayer, this->anchorParam.strides.size());
+ while ((lastSameStrideLayer < anchorParam.numLayers) &&
+ (anchorParam.strides[lastSameStrideLayer] == anchorParam.strides[layerId])) {
+ const float scale = CalculateScale(anchorParam.minScale, anchorParam.maxScale, lastSameStrideLayer,
+ anchorParam.strides.size());
- if (lastSameStrideLayer == 0 && this->anchorParam.isReduceBoxedInLowestLayer) {
+ if (lastSameStrideLayer == 0 && anchorParam.isReduceBoxedInLowestLayer) {
aspectRatios.push_back(1.0);
aspectRatios.push_back(2.0);
aspectRatios.push_back(0.5);
@@ -235,19 +234,17 @@ int DecodeInfo::GenerateAnchor()
scales.push_back(scale);
scales.push_back(scale);
} else {
- for (iter1 = this->anchorParam.aspectRatios.begin(); iter1 != this->anchorParam.aspectRatios.end();
- ++iter1) {
+ for (iter1 = anchorParam.aspectRatios.begin(); iter1 != anchorParam.aspectRatios.end(); ++iter1) {
aspectRatios.push_back((*iter1));
scales.push_back(scale);
}
- if (this->anchorParam.interpolatedScaleAspectRatio > 0.0f) {
- const float scaleNext =
- lastSameStrideLayer == static_cast<int>(this->anchorParam.strides.size()) - 1 ?
- 1.0f :
- CalculateScale(this->anchorParam.minScale, this->anchorParam.maxScale,
- lastSameStrideLayer + 1, this->anchorParam.strides.size());
+ if (anchorParam.interpolatedScaleAspectRatio > 0.0f) {
+ const float scaleNext = lastSameStrideLayer == static_cast<int>(anchorParam.strides.size()) - 1 ?
+ 1.0f :
+ CalculateScale(anchorParam.minScale, anchorParam.maxScale,
+ lastSameStrideLayer + 1, anchorParam.strides.size());
scales.push_back(std::sqrt(scale * scaleNext));
- aspectRatios.push_back(this->anchorParam.interpolatedScaleAspectRatio);
+ aspectRatios.push_back(anchorParam.interpolatedScaleAspectRatio);
}
}
lastSameStrideLayer++;
@@ -260,27 +257,26 @@ int DecodeInfo::GenerateAnchor()
anchorWidth.push_back((*iter2) * ratioSqrts);
}
- const int stride = this->anchorParam.strides[layerId];
- int featureMapHeight = std::ceil(1.0f * this->anchorParam.inputSizeHeight / stride);
- int featureMapWidth = std::ceil(1.0f * this->anchorParam.inputSizeWidth / stride);
+ const int stride = anchorParam.strides[layerId];
+ int featureMapHeight = std::ceil(1.0f * anchorParam.inputSizeHeight / stride);
+ int featureMapWidth = std::ceil(1.0f * anchorParam.inputSizeWidth / stride);
for (int y = 0; y < featureMapHeight; ++y) {
for (int x = 0; x < featureMapWidth; ++x) {
for (int anchorId = 0; anchorId < (int) anchorHeight.size(); ++anchorId) {
- cv::Rect2f anchor = { cv::Point2f { (x + this->anchorParam.anchorOffsetX) * 1.0f / featureMapWidth,
- (y + this->anchorParam.anchorOffsetY) * 1.0f /
- featureMapHeight },
- this->anchorParam.isFixedAnchorSize ?
+ cv::Rect2f anchor = { cv::Point2f { (x + anchorParam.anchorOffsetX) * 1.0f / featureMapWidth,
+ (y + anchorParam.anchorOffsetY) * 1.0f / featureMapHeight },
+ anchorParam.isFixedAnchorSize ?
cv::Size2f { 1.0f, 1.0f } :
cv::Size2f { anchorWidth[anchorId], anchorWidth[anchorId] } };
- this->AddAnchorBox(anchor);
+ AddAnchorBox(anchor);
}
}
}
layerId = lastSameStrideLayer;
}
- if (this->IsAnchorBoxEmpty()) {
+ if (IsAnchorBoxEmpty()) {
LOGE("Anchor boxes are empty");
return MEDIA_VISION_ERROR_INVALID_OPERATION;
}
@@ -297,25 +293,25 @@ int DecodeInfo::ParseNms(JsonObject *root)
JsonObject *object = json_object_get_object_member(root, "nms");
try {
- this->nmsParam.mode = GetSupportedType(object, "mode", this->nmsParam.supportedBoxNmsTypes);
+ nmsParam.mode = GetSupportedType(object, "mode", nmsParam.supportedBoxNmsTypes);
} catch (const std::exception &e) {
LOGE("Invalid %s", e.what());
return MEDIA_VISION_ERROR_INVALID_OPERATION;
}
- this->nmsParam.iouThreshold = static_cast<float>(json_object_get_double_member(object, "iou_threshold"));
+ nmsParam.iouThreshold = static_cast<float>(json_object_get_double_member(object, "iou_threshold"));
return MEDIA_VISION_ERROR_NONE;
}
int DecodeInfo::GetNmsMode()
{
- return this->nmsParam.mode;
+ return nmsParam.mode;
}
float DecodeInfo::GetNmsIouThreshold()
{
- return this->nmsParam.iouThreshold;
+ return nmsParam.iouThreshold;
}
int DecodeInfo::ParseRotate(JsonObject *root)
@@ -326,66 +322,66 @@ int DecodeInfo::ParseRotate(JsonObject *root)
}
JsonObject *object = json_object_get_object_member(root, "rotate");
- this->rotParam.baseAngle = static_cast<float>(json_object_get_double_member(object, "base_angle"));
- this->rotParam.startPointIndex = static_cast<int>(json_object_get_int_member(object, "start_point_index"));
- this->rotParam.endPointIndex = static_cast<int>(json_object_get_int_member(object, "end_point_index"));
+ rotParam.baseAngle = static_cast<float>(json_object_get_double_member(object, "base_angle"));
+ rotParam.startPointIndex = static_cast<int>(json_object_get_int_member(object, "start_point_index"));
+ rotParam.endPointIndex = static_cast<int>(json_object_get_int_member(object, "end_point_index"));
return MEDIA_VISION_ERROR_NONE;
}
int DecodeInfo::GetRotStartPointIndex()
{
- return this->rotParam.startPointIndex;
+ return rotParam.startPointIndex;
}
int DecodeInfo::GetRotEndPointIndex()
{
- return this->rotParam.endPointIndex;
+ return rotParam.endPointIndex;
}
float DecodeInfo::GetBaseAngle()
{
- return this->rotParam.baseAngle;
+ return rotParam.baseAngle;
}
int DecodeInfo::GetRoiMode()
{
- return this->roiOptParam.mode;
+ return roiOptParam.mode;
}
int DecodeInfo::GetRoiStartPointIndex()
{
- return this->roiOptParam.startPointIndex;
+ return roiOptParam.startPointIndex;
}
int DecodeInfo::GetRoiEndPointIndex()
{
- return this->roiOptParam.endPointIndex;
+ return roiOptParam.endPointIndex;
}
int DecodeInfo::GetRoiCenterPointIndex()
{
- return this->roiOptParam.centerPointIndex;
+ return roiOptParam.centerPointIndex;
}
float DecodeInfo::GetShiftX()
{
- return this->roiOptParam.shiftX;
+ return roiOptParam.shiftX;
}
float DecodeInfo::GetShiftY()
{
- return this->roiOptParam.shiftY;
+ return roiOptParam.shiftY;
}
float DecodeInfo::GetScaleX()
{
- return this->roiOptParam.scaleX;
+ return roiOptParam.scaleX;
}
float DecodeInfo::GetScaleY()
{
- return this->roiOptParam.scaleY;
+ return roiOptParam.scaleY;
}
int DecodeInfo::ParseRoiOption(JsonObject *root)
@@ -396,14 +392,14 @@ int DecodeInfo::ParseRoiOption(JsonObject *root)
}
JsonObject *object = json_object_get_object_member(root, "roi");
- this->roiOptParam.startPointIndex = static_cast<int>(json_object_get_int_member(object, "start_point_index"));
- this->roiOptParam.endPointIndex = static_cast<int>(json_object_get_int_member(object, "end_point_index"));
- this->roiOptParam.centerPointIndex = static_cast<int>(json_object_get_int_member(object, "center_point_index"));
- this->roiOptParam.shiftX = static_cast<float>(json_object_get_double_member(object, "shift_x"));
- this->roiOptParam.shiftY = static_cast<float>(json_object_get_double_member(object, "shift_y"));
- this->roiOptParam.scaleX = static_cast<float>(json_object_get_double_member(object, "scale_x"));
- this->roiOptParam.scaleY = static_cast<float>(json_object_get_double_member(object, "scale_y"));
- this->roiOptParam.mode = static_cast<int>(json_object_get_int_member(object, "scale_mode"));
+ roiOptParam.startPointIndex = static_cast<int>(json_object_get_int_member(object, "start_point_index"));
+ roiOptParam.endPointIndex = static_cast<int>(json_object_get_int_member(object, "end_point_index"));
+ roiOptParam.centerPointIndex = static_cast<int>(json_object_get_int_member(object, "center_point_index"));
+ roiOptParam.shiftX = static_cast<float>(json_object_get_double_member(object, "shift_x"));
+ roiOptParam.shiftY = static_cast<float>(json_object_get_double_member(object, "shift_y"));
+ roiOptParam.scaleX = static_cast<float>(json_object_get_double_member(object, "scale_x"));
+ roiOptParam.scaleY = static_cast<float>(json_object_get_double_member(object, "scale_y"));
+ roiOptParam.mode = static_cast<int>(json_object_get_int_member(object, "scale_mode"));
return MEDIA_VISION_ERROR_NONE;
}
diff --git a/mv_machine_learning/inference/src/ScoreInfo.cpp b/mv_machine_learning/inference/src/ScoreInfo.cpp
new file mode 100644
index 00000000..0560218f
--- /dev/null
+++ b/mv_machine_learning/inference/src/ScoreInfo.cpp
@@ -0,0 +1,73 @@
+/**
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <ScoreInfo.h>
+
+using namespace mediavision::inference;
+
+int ScoreInfo::ParseScore(JsonObject *root)
+{
+ LOGI("ENTER");
+ if (!json_object_has_member(root, "score")) {
+ LOGE("member score not exists");
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
+ JsonObject *pObject = json_object_get_object_member(root, "score");
+
+ JsonArray *array = json_object_get_array_member(pObject, "name");
+ MEDIA_VISION_NULL_ARG_CHECK(array);
+
+ unsigned int elements1 = json_array_get_length(array);
+ MEDIA_VISION_CHECK_CONDITION(elements1 > 0, MEDIA_VISION_ERROR_INVALID_PARAMETER, "No name on meta file");
+
+ for (unsigned int elem1 = 0; elem1 < elements1; ++elem1) {
+ names.push_back(json_array_get_string_element(array, elem1));
+ }
+
+ array = json_object_get_array_member(pObject, "index");
+ unsigned int elements2 = json_array_get_length(array);
+ LOGI("range dim: size[%u]", elements2);
+ for (unsigned int elem2 = 0; elem2 < elements2; ++elem2) {
+ if (static_cast<int>(json_array_get_int_element(array, elem2)) == 1)
+ dimInfo.SetValidIndex(elem2);
+ }
+ if (json_object_has_member(pObject, "top_number"))
+ topNumber = static_cast<int>(json_object_get_int_member(pObject, "top_number"));
+ LOGI("top number: %d", topNumber);
+
+ if (json_object_has_member(pObject, "threshold"))
+ threshold = static_cast<double>(json_object_get_double_member(pObject, "threshold"));
+ LOGI("threshold: %1.3f", threshold);
+
+ try {
+ type = GetSupportedType(pObject, "score_type", supportedScoreTypes);
+ } catch (const std::exception &e) {
+ LOGE("Invalid %s", e.what());
+ return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ }
+
+ if (json_object_has_member(pObject, "dequantization")) {
+ array = json_object_get_array_member(pObject, "dequantization");
+ JsonNode *node = json_array_get_element(array, 0);
+ JsonObject *object = json_node_get_object(node);
+
+ deQuantization = std::make_shared<DeQuantization>(json_object_get_double_member(object, "scale"),
+ json_object_get_double_member(object, "zeropoint"));
+ }
+
+ LOGI("LEAVE");
+ return MEDIA_VISION_ERROR_NONE;
+} \ No newline at end of file