--- /dev/null
+/**
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef __BOX_INFO_H__
+#define __BOX_INFO_H__
+
+#include <string>
+#include <vector>
+#include <map>
+#include <memory>
+
+#include <mv_inference_type.h>
+#include <inference_engine_type.h>
+
+namespace mediavision
+{
+namespace inference
+{
+namespace box
+{
+ class BoxInfo
+ {
+ private:
+ std::string name;
+ DimInfo dimInfo;
+ inference_box_type_e type; // 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
+ DecodeInfo decodingInfo;
+
+ 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;
+
+ public:
+ BoxInfo() :
+ name(),
+ 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});
+ }
+
+ ~BoxInfo() = default;
+
+ std::string GetName() { return name; }
+ DimInfo GetDimInfo() { return dimInfo; }
+ inference_box_type_e GetType() { return type; }
+ inference_box_decoding_type_e GetDecodingType() { return decodingType; }
+ std::vector<int> GetOrder() { return order; }
+ int GetCoordinate() { return coordinate; }
+ DecodeInfo& GetDecodeInfo() {return decodingInfo; }
+
+ int ParseBox(JsonObject *root)
+ {
+ LOGI("ENTER");
+
+ JsonArray * rootArray = json_object_get_array_member(root, "box");
+ unsigned int elements = json_array_get_length(rootArray);
+
+ for (unsigned int elem_idx = 0; elem_idx < elements; ++elem_idx) {
+ JsonNode *pNode = json_array_get_element(rootArray, elem_idx);
+ JsonObject *pObject = json_node_get_object(pNode);
+
+ name = json_object_get_string_member(pObject,"name");
+ LOGI("layer: %s", name.c_str());
+
+ JsonArray * 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_idx = 0; elem2_idx < elements2; ++elem2_idx)
+ if (static_cast<int>(json_array_get_int_element(array, elem2_idx)) == 1)
+ dimInfo.SetValidIndex(elem2_idx);
+
+ try {
+ type = GetSupportedType(pObject, "box_type", supportedBoxTypes);
+ coordinate = GetSupportedType(pObject, "box_coordinate", supportedBoxCoordinateTypes);
+ decodingType = GetSupportedType(pObject, "decoding_type", supportedBoxDecodingTypes);
+ } catch (const std::exception& e) {
+ LOGE("Invalid %s", e.what());
+ return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ }
+
+ array = json_object_get_array_member(pObject, "box_order");
+ elements2 = json_array_get_length(array);
+ LOGI("box order should have 4 elements and it has [%u]", elements2);
+
+ for (unsigned int elem2_idx = 0; elem2_idx < elements2; ++elem2_idx) {
+ auto val = static_cast<int>(json_array_get_int_element(array, elem2_idx));
+ order.push_back(val);
+ LOGI("%d", val);
+ }
+ }
+
+ LOGI("LEAVE");
+ return MEDIA_VISION_ERROR_NONE;
+ }
+ };
+} /* box */
+} /* Inference */
+} /* MediaVision */
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef __DECODE_INFO_H__
+#define __DECODE_INFO_H__
+
+#include <string>
+#include <vector>
+#include <map>
+#include <memory>
+
+#include <mv_inference_type.h>
+#include <opencv2/core.hpp>
+
+namespace mediavision
+{
+namespace inference
+{
+namespace box
+{
+ struct AnchorParam {
+ int mode; /**< 0: generate anchor, 1:load pre-anchor*/
+ int numLayers;
+ float minScale;
+ float maxScale;
+ int inputSizeHeight;
+ int inputSizeWidth;
+ float anchorOffsetX;
+ float anchorOffsetY;
+ std::vector<int> strides;
+ std::vector<float> aspectRatios;
+ bool isReduceBoxedInLowestLayer;
+ float interpolatedScaleAspectRatio;
+ bool isFixedAnchorSize;
+ bool isExponentialBoxScale;
+ float xScale;
+ float yScale;
+ float wScale;
+ float hScale;
+ };
+
+ struct NMSParam {
+ inference_box_nms_type_e mode; /**< 0: standard */
+ float iouThreshold;
+ std::map<std::string, inference_box_nms_type_e> supportedBoxNmsTypes;
+ };
+
+ struct RotateParam {
+ int startPointIndex;
+ int endPointIndex;
+ cv::Point2f startPoint;
+ cv::Point2f endPoint;
+ float baseAngle;
+ };
+
+ struct RoiOptionParam {
+ int startPointIndex;
+ int endPointIndex;
+ int centerPointIndex;
+ cv::Point2f centerPoint;
+ float shiftX;
+ float shiftY;
+ float scaleX;
+ float scaleY;
+ int mode;
+ };
+
+ class DecodeInfo {
+ private:
+ AnchorParam anchorParam;
+ std::vector<cv::Rect2f> anchorBoxes;
+ NMSParam nmsParam;
+ RotateParam rotParam;
+ RoiOptionParam roiOptParam;
+
+ public:
+ DecodeInfo() {
+ nmsParam.mode = INFERENCE_BOX_NMS_TYPE_NONE;
+ nmsParam.iouThreshold = 0.2f;
+ nmsParam.supportedBoxNmsTypes.insert({"STANDARD", INFERENCE_BOX_NMS_TYPE_STANDARD});
+
+ rotParam.startPointIndex = -1;
+ rotParam.endPointIndex = -1;
+ rotParam.startPoint = cv::Point2f(0.f,0.f);
+ rotParam.endPoint = cv::Point2f(0.f,0.f);
+ rotParam.baseAngle = 0.f;
+
+ roiOptParam.startPointIndex = -1;
+ roiOptParam.endPointIndex = -1;
+ roiOptParam.centerPointIndex = -1;
+ roiOptParam.centerPoint = cv::Point2f(0.f, 0.f);
+ roiOptParam.shiftX = 0.f;
+ roiOptParam.shiftY = 0.f;
+ roiOptParam.scaleX = 1.f;
+ roiOptParam.scaleY = 1.f;
+ roiOptParam.mode = -1;
+ }
+
+ ~DecodeInfo() = default;
+
+ std::vector<cv::Rect2f>& GetAnchorBoxAll();
+ bool IsAnchorBoxEmpty();
+ void AddAnchorBox(cv::Rect2f& ahcnor);
+ void ClearAnchorBox();
+
+ // Anchor param
+ int ParseAnchorParam(JsonObject *root);
+ int GenerateAnchor();
+ bool IsFixedAnchorSize();
+ bool IsExponentialBoxScale();
+ float GetAnchorXscale();
+ float GetAnchorYscale();
+ float GetAnchorWscale();
+ float GetAnchorHscale();
+ float CalculateScale(float min, float max, int index, int maxStride);
+
+ // Nms param
+ int ParseNms(JsonObject *root);
+ int GetNmsMode();
+ float GetNmsIouThreshold();
+
+ // Rotate param
+ int ParseRotate(JsonObject *root);
+ int GetRotStartPointIndex();
+ int GetRotEndPointIndex();
+ float GetBaseAngle();
+
+ // Roi option param
+ int ParseRoiOption(JsonObject *root);
+ int GetRoiMode();
+ int GetRoiCenterPointIndex();
+ int GetRoiStartPointIndex();
+ int GetRoiEndPointIndex();
+ float GetShiftX();
+ float GetShiftY();
+ float GetScaleX();
+ float GetScaleY();
+ };
+} /* box */
+} /* Inference */
+} /* MediaVision */
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef __DIM_INFO_H__
+#define __DIM_INFO_H__
+
+#include <vector>
+
+namespace mediavision
+{
+namespace inference
+{
+ class DimInfo
+ {
+ private:
+ std::vector<int> dims;
+
+ public:
+ std::vector<int> GetValidIndexAll() const
+ {
+ LOGI("ENTER");
+
+ LOGI("LEAVE");
+ return dims;
+ }
+
+ void SetValidIndex(int index)
+ {
+ LOGI("ENTER");
+
+ dims.push_back(index);
+
+ LOGI("LEAVE");
+ }
+ };
+} /* Inference */
+} /* MediaVision */
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef __DISP_VEC_H__
+#define __DISP_VEC_H__
+
+#include <string>
+#include <vector>
+#include <map>
+#include <memory>
+
+#include <mv_inference_type.h>
+#include "DimInfo.h"
+#include "Utils.h"
+
+namespace mediavision
+{
+namespace inference
+{
+ class DispVec
+ {
+ private:
+ std::string name;
+ DimInfo dimInfo;
+ inference_displacement_type_e type;
+ int shapeType;
+ std::map<std::string, inference_displacement_type_e> supportedDispTypes;
+
+ public:
+ DispVec() :
+ name(),
+ dimInfo(),
+ type(INFERENCE_DISPLACEMENT_TYPE_FORWARD),
+ shapeType(INFERENCE_TENSOR_SHAPE_NCHW)
+ {
+ supportedDispTypes.insert({"FORWARD", INFERENCE_DISPLACEMENT_TYPE_FORWARD});
+ supportedDispTypes.insert({"BACKWARD", INFERENCE_DISPLACEMENT_TYPE_BACKWARD});
+ }
+
+ ~DispVec() = default;
+
+ std::string GetName() { return name; }
+ DimInfo GetDimInfo() { return dimInfo; }
+ inference_displacement_type_e GetType() { return type; }
+ int GetShapeType() { return shapeType; }
+
+ int ParseDisplacement(JsonObject *root, const std::map<std::string, inference_tensor_shape_type_e>& supportedShapeType)
+ {
+ LOGI("ENTER");
+
+ name = static_cast<const char*>(json_object_get_string_member(root,"name"));
+ LOGI("layer: %s", name.c_str());
+
+ JsonArray * array = json_object_get_array_member(root, "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);
+ }
+
+ try {
+ shapeType = GetSupportedType(root, "shape_type", supportedShapeType);
+ type = GetSupportedType(root, "type", supportedDispTypes);
+ } catch (const std::exception& e) {
+ LOGE("Invalid %s", e.what());
+ return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ }
+
+ LOGI("LEAVE");
+ return MEDIA_VISION_ERROR_NONE;
+ }
+
+ };
+} /* Inference */
+} /* MediaVision */
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef __EDGE_H__
+#define __EDGE_H__
+
+#include <vector>
+#include <mv_inference_type.h>
+#include <json-glib/json-glib.h>
+
+namespace mediavision
+{
+namespace inference
+{
+ class Edge
+ {
+ private:
+ std::vector<std::pair<int, int>> edges;
+
+ public:
+ Edge() = default;
+
+ ~Edge() = default;
+
+ int ParseEdge(JsonObject *root)
+ {
+ LOGI("ENTER");
+
+ JsonArray * rootArray = json_object_get_array_member(root, "edgemap");
+ unsigned int elements = json_array_get_length(rootArray);
+
+ // TODO: handling error
+ int pEdgeNode, cEdgeNode;
+
+ for (unsigned int elem = 0; elem < elements; ++elem) {
+ JsonNode *pNode = json_array_get_element(rootArray, elem);
+ JsonObject *pObject = json_node_get_object(pNode);
+
+ pEdgeNode = json_object_get_int_member(pObject, "parent");
+ cEdgeNode = json_object_get_int_member(pObject, "child");
+
+ edges.push_back(std::make_pair(pEdgeNode, cEdgeNode));
+ LOGI("%ud: parent - child: %d - %d", elem, pEdgeNode, cEdgeNode);
+ }
+
+ LOGI("LEAVE");
+ return MEDIA_VISION_ERROR_NONE;
+ }
+
+ std::vector<std::pair<int, int>>& GetEdgesAll() { return edges; }
+ };
+} /* Inference */
+} /* MediaVision */
+
+#endif
\ No newline at end of file
std::map<std::string, LayerInfo> layer;
std::map<std::string, Options> option;
- 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);
* limitations under the License.
*/
-#ifndef __MEDIA_VISION_LANDMARK_H__
-#define __MEDIA_VISION_LANDMARK_H__
+#ifndef __LANDMARK_H__
+#define __LANDMARK_H__
#include <string>
#include <vector>
float score;
} LandmarkResults;
+ typedef struct _HeatMapInfo {
+ int wIdx;
+ int hIdx;
+ int cIdx;
+ float nmsRadius;
+ inference_tensor_shape_type_e shapeType;
+ } HeatMapInfo;
+
+ class Landmark
+ {
+ private:
+ std::string name;
+ DimInfo dimInfo;
+ inference_landmark_type_e type; /**< 0: 2D_SINGLE, 1: 2D_MULTI, 2: 3D_SINGLE */
+ int offset;
+ inference_landmark_coorindate_type_e coordinate; /**< 0: RATIO, 1: PIXEL */
+ inference_landmark_decoding_type_e decodingType; /**< 0: decoding unnecessary,
+ 1: decoding heatmap,
+ 2: decoding heatmap with refinement */
+ HeatMapInfo heatMapInfo;
+
+ std::map<std::string, inference_landmark_type_e> supportedLandmarkTypes;
+ std::map<std::string, inference_landmark_coorindate_type_e> supportedLandmarkCoordinateTypes;
+ std::map<std::string, inference_landmark_decoding_type_e> supportedLandmarkDecodingTypes;
+
+ public:
+
+ Landmark() :
+ name(),
+ dimInfo(),
+ type(INFERENCE_LANDMARK_TYPE_2D_SINGLE),
+ offset(),
+ coordinate(INFERENCE_LANDMARK_COORDINATE_TYPE_RATIO),
+ decodingType(INFERENCE_LANDMARK_DECODING_TYPE_BYPASS),
+ heatMapInfo()
+
+ {
+ supportedLandmarkTypes.insert({"2D_SINGLE", INFERENCE_LANDMARK_TYPE_2D_SINGLE});
+ supportedLandmarkTypes.insert({"2D_MULTI", INFERENCE_LANDMARK_TYPE_2D_MULTI});
+ supportedLandmarkTypes.insert({"3D_SINGLE", INFERENCE_LANDMARK_TYPE_3D_SINGLE});
+
+ supportedLandmarkCoordinateTypes.insert({"RATIO", INFERENCE_LANDMARK_COORDINATE_TYPE_RATIO});
+ supportedLandmarkCoordinateTypes.insert({"PIXEL", INFERENCE_LANDMARK_COORDINATE_TYPE_PIXEL});
+
+ supportedLandmarkDecodingTypes.insert({"BYPASS", INFERENCE_LANDMARK_DECODING_TYPE_BYPASS});
+ supportedLandmarkDecodingTypes.insert({"HEATMAP", INFERENCE_LANDMARK_DECODING_TYPE_HEATMAP});
+ supportedLandmarkDecodingTypes.insert({"HEATMAP_REFINE", INFERENCE_LANDMARK_DECODING_TYPE_HEATMAP_REFINE});
+ }
+
+ ~Landmark() = default;
+
+ int ParseLandmark(JsonObject *root)
+ {
+ // box
+ JsonArray * rootArray = json_object_get_array_member(root, "landmark");
+ unsigned int elements = json_array_get_length(rootArray);
+
+ // TODO: handling error
+ for (unsigned int elem = 0; elem < elements; ++elem) {
+
+ JsonNode *pNode = json_array_get_element(rootArray, elem);
+ JsonObject *pObject = json_node_get_object(pNode);
+
+ name =
+ static_cast<const char*>(json_object_get_string_member(pObject,"name"));
+ LOGI("layer: %s", name.c_str());
+
+ JsonArray * 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);
+ }
+
+ try {
+ type = GetSupportedType(pObject, "landmark_type", supportedLandmarkTypes);
+ coordinate = GetSupportedType(pObject, "landmark_coordinate", supportedLandmarkCoordinateTypes);
+ decodingType = GetSupportedType(pObject, "decoding_type", supportedLandmarkDecodingTypes);
+ } catch (const std::exception& e) {
+ LOGE("Invalid %s", e.what());
+ return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ }
+
+ offset = static_cast<int>(json_object_get_int_member(pObject, "landmark_offset"));
+ LOGI("landmark offset: %d", offset);
+ }
+
+ LOGI("LEAVE");
+ return MEDIA_VISION_ERROR_NONE;
+ }
+
+ inference_landmark_type_e GetType()
+ {
+ return type;
+ }
+
+ int GetOffset()
+ {
+ return offset;
+ }
+
+ inference_landmark_coorindate_type_e GetCoordinate()
+ {
+ return coordinate;
+ }
+
+ inference_landmark_decoding_type_e GetDecodingType()
+ {
+ return decodingType;
+ }
+
+ HeatMapInfo& GetHeatMapInfo()
+ {
+ return heatMapInfo;
+ }
+
+ std::string GetName() { return name; }
+
+ DimInfo GetDimInfo() { return dimInfo; }
+ };
} /* Inference */
} /* MediaVision */
-#endif /* __MEDIA_VISION_LANDMARK_H__ */
+#endif /* __LANDMARK_H__ */
--- /dev/null
+/**
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef __OFFSET_VEC_H__
+#define __OFFSET_VEC_H__
+
+#include <string>
+#include <vector>
+#include <memory>
+
+#include <mv_inference_type.h>
+#include "DimInfo.h"
+#include "Utils.h"
+
+namespace mediavision
+{
+namespace inference
+{
+ class OffsetVec
+ {
+ private:
+ std::string name;
+ DimInfo dimInfo;
+ int shapeType;
+ public:
+ OffsetVec() : name(), dimInfo(), shapeType() { }
+ ~OffsetVec() = default;
+ std::string GetName() { return name; }
+ DimInfo GetDimInfo() { return dimInfo; }
+ int GetShapeType() { return shapeType; }
+
+ int ParseOffset(JsonObject *root, const std::map<std::string, inference_tensor_shape_type_e>& supportedShapeType)
+ {
+ JsonArray * rootArray = json_object_get_array_member(root, "offset");
+ unsigned int elements = json_array_get_length(rootArray);
+
+ // TODO: handling error
+ for (unsigned int elem = 0; elem < elements; ++elem) {
+
+ JsonNode *pNode = json_array_get_element(rootArray, elem);
+ JsonObject *pObject = json_node_get_object(pNode);
+
+ name =
+ static_cast<const char*>(json_object_get_string_member(pObject,"name"));
+ LOGI("layer: %s", name.c_str());
+
+ JsonArray * 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);
+ }
+
+ try {
+ shapeType = GetSupportedType(pObject, "shape_type", supportedShapeType);
+ } catch (const std::exception& e) {
+ LOGE("Invalid %s", e.what());
+ return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ }
+
+ }
+
+ LOGI("LEAVE");
+ return MEDIA_VISION_ERROR_NONE;
+ }
+ };
+} /* Inference */
+} /* MediaVision */
+
+#endif
\ No newline at end of file
#include <json-glib/json-glib.h>
#include <opencv2/core.hpp>
#include "OutputMetadataTypes.h"
+#include "DecodeInfo.h"
+#include "Edge.h"
+#include "DispVec.h"
+#include "DimInfo.h"
+#include "OffsetVec.h"
+#include "Landmark.h"
+#include "BoxInfo.h"
+#include "ScoreInfo.h"
/**
* @file OutputMetadata.h
{
namespace inference
{
- class DimInfo
+ struct Label
{
- private:
- std::vector<int> dims;
-
- public:
- std::vector<int> GetValidIndexAll() const;
- void SetValidIndex(int index);
- };
-
- class DeQuantization
- {
- private:
- double scale;
- double zeropoint;
-
- public:
- DeQuantization(double s, double z) : scale(s), zeropoint(z) {};
- ~DeQuantization() = default;
-
- double GetScale() { return scale; }
- double GetZeroPoint() { return zeropoint; }
- };
-
- class ScoreInfo
- {
- private:
- std::string name;
- DimInfo dimInfo;
- double threshold;
- int topNumber;
- inference_score_type_e type;
- std::shared_ptr<DeQuantization> deQuantization;
- std::map<std::string, inference_score_type_e> supportedScoreTypes;
-
- public:
- ScoreInfo();
- ~ScoreInfo() = default;
-
- std::string GetName() { return name; }
- DimInfo GetDimInfo() { return dimInfo; }
- double GetThresHold() { return threshold; }
- inference_score_type_e GetType() { return type; }
- int GetTopNumber() { return topNumber; }
- std::shared_ptr<DeQuantization> GetDeQuant() { return deQuantization; }
- int ParseScore(JsonObject *root);
- };
-
- struct AnchorParam {
- int mode; /**< 0: generate anchor, 1:load pre-anchor*/
- int numLayers;
- float minScale;
- float maxScale;
- int inputSizeHeight;
- int inputSizeWidth;
- float anchorOffsetX;
- float anchorOffsetY;
- std::vector<int> strides;
- std::vector<float> aspectRatios;
- bool isReduceBoxedInLowestLayer;
- float interpolatedScaleAspectRatio;
- bool isFixedAnchorSize;
- bool isExponentialBoxScale;
- float xScale;
- float yScale;
- float wScale;
- float hScale;
- };
-
- struct NMSParam {
- inference_box_nms_type_e mode; /**< 0: standard */
- float iouThreshold;
- std::map<std::string, inference_box_nms_type_e> supportedBoxNmsTypes;
- };
-
- struct RotateParam {
- int startPointIndex;
- int endPointIndex;
- cv::Point2f startPoint;
- cv::Point2f endPoint;
- float baseAngle;
- };
-
- struct RoiOptionParam {
- int startPointIndex;
- int endPointIndex;
- int centerPointIndex;
- cv::Point2f centerPoint;
- float shiftX;
- float shiftY;
- float scaleX;
- float scaleY;
- int mode;
- };
-
- class DecodeInfo {
- private:
- AnchorParam anchorParam;
- std::vector<cv::Rect2f> anchorBoxes;
- NMSParam nmsParam;
- RotateParam rotParam;
- RoiOptionParam roiOptParam;
-
- public:
- DecodeInfo() {
- nmsParam.mode = INFERENCE_BOX_NMS_TYPE_NONE;
- nmsParam.iouThreshold = 0.2f;
- nmsParam.supportedBoxNmsTypes.insert({"STANDARD", INFERENCE_BOX_NMS_TYPE_STANDARD});
-
- rotParam.startPointIndex = -1;
- rotParam.endPointIndex = -1;
- rotParam.startPoint = cv::Point2f(0.f,0.f);
- rotParam.endPoint = cv::Point2f(0.f,0.f);
- rotParam.baseAngle = 0.f;
-
- roiOptParam.startPointIndex = -1;
- roiOptParam.endPointIndex = -1;
- roiOptParam.centerPointIndex = -1;
- roiOptParam.centerPoint = cv::Point2f(0.f, 0.f);
- roiOptParam.shiftX = 0.f;
- roiOptParam.shiftY = 0.f;
- roiOptParam.scaleX = 1.f;
- roiOptParam.scaleY = 1.f;
- roiOptParam.mode = -1;
- }
-
- ~DecodeInfo() = default;
-
- std::vector<cv::Rect2f>& GetAnchorBoxAll();
- bool IsAnchorBoxEmpty();
- void AddAnchorBox(cv::Rect2f& ahcnor);
- void ClearAnchorBox();
-
- // Anchor param
- int ParseAnchorParam(JsonObject *root);
- int GenerateAnchor();
- bool IsFixedAnchorSize();
- bool IsExponentialBoxScale();
- float GetAnchorXscale();
- float GetAnchorYscale();
- float GetAnchorWscale();
- float GetAnchorHscale();
- float CalculateScale(float min, float max, int index, int maxStride);
-
- // Nms param
- int ParseNms(JsonObject *root);
- int GetNmsMode();
- float GetNmsIouThreshold();
-
- // Rotate param
- int ParseRotate(JsonObject *root);
- int GetRotStartPointIndex();
- int GetRotEndPointIndex();
- float GetBaseAngle();
-
- // Roi option param
- int ParseRoiOption(JsonObject *root);
- int GetRoiMode();
- int GetRoiCenterPointIndex();
- int GetRoiStartPointIndex();
- int GetRoiEndPointIndex();
- float GetShiftX();
- float GetShiftY();
- float GetScaleX();
- float GetScaleY();
- };
-
- class BoxInfo
- {
- private:
- std::string name;
- DimInfo dimInfo;
- inference_box_type_e type; // 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
- DecodeInfo decodingInfo;
-
- 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;
-
- public:
- BoxInfo();
- ~BoxInfo() = default;
-
- std::string GetName() { return name; }
- DimInfo GetDimInfo() { return dimInfo; }
- inference_box_type_e GetType() { return type; }
- inference_box_decoding_type_e GetDecodingType() { return decodingType; }
- std::vector<int> GetOrder() { return order; }
- int GetCoordinate() { return coordinate; }
- DecodeInfo& GetDecodeInfo() {return decodingInfo; }
-
- int ParseBox(JsonObject *root);
- };
-
- class Label
- {
- private:
- std::string name;
- DimInfo dimInfo;
-
- public:
- Label() = default;
- ~Label() = default;
- std::string GetName() { return name; }
- DimInfo GetDimInfo() { return dimInfo; }
-
- int ParseLabel(JsonObject *root);
- };
-
- class Number
- {
- private:
std::string name;
DimInfo dimInfo;
-
- public:
- Number() = default;
- ~Number() = default;
- std::string GetName() { return name; }
- DimInfo GetDimInfo() { return dimInfo; }
-
- int ParseNumber(JsonObject *root);
};
- struct HeatMapInfo {
- int wIdx;
- int hIdx;
- int cIdx;
- float nmsRadius;
- inference_tensor_shape_type_e shapeType;
- };
-
- class Landmark
+ struct Number
{
- private:
std::string name;
DimInfo dimInfo;
- inference_landmark_type_e type; /**< 0: 2D_SINGLE, 1: 2D_MULTI, 2: 3D_SINGLE */
- int offset;
- inference_landmark_coorindate_type_e coordinate; /**< 0: RATIO, 1: PIXEL */
- inference_landmark_decoding_type_e decodingType; /**< 0: decoding unnecessary,
- 1: decoding heatmap,
- 2: decoding heatmap with refinement */
- HeatMapInfo heatMapInfo;
-
- std::map<std::string, inference_landmark_type_e> supportedLandmarkTypes;
- std::map<std::string, inference_landmark_coorindate_type_e> supportedLandmarkCoordinateTypes;
- std::map<std::string, inference_landmark_decoding_type_e> supportedLandmarkDecodingTypes;
-
- public:
- Landmark();
- ~Landmark() = default;
- std::string GetName() { return name; }
- DimInfo GetDimInfo() { return dimInfo; }
- inference_landmark_type_e GetType();
- int GetOffset();
- inference_landmark_coorindate_type_e GetCoordinate();
- inference_landmark_decoding_type_e GetDecodingType();
- HeatMapInfo& GetHeatMapInfo();
-
- int ParseLandmark(JsonObject *root);
- };
-
- class OffsetVec
- {
- private:
- std::string name;
- DimInfo dimInfo;
- int shapeType;
- public:
- OffsetVec() = default;
- ~OffsetVec() = default;
- std::string GetName() { return name; }
- DimInfo GetDimInfo() { return dimInfo; }
- int GetShapeType() { return shapeType; }
-
- int ParseOffset(JsonObject *root);
- };
-
- class DispVec
- {
- private:
- std::string name;
- DimInfo dimInfo;
- inference_displacement_type_e type;
- int shapeType;
- std::map<std::string, inference_displacement_type_e> supportedDispTypes;
- public:
- DispVec();
- ~DispVec() = default;
- std::string GetName() { return name; }
- DimInfo GetDimInfo() { return dimInfo; }
- inference_displacement_type_e GetType() { return type; }
- int GetShapeType() { return shapeType; }
-
- int ParseDisplacement(JsonObject *root);
- };
-
- class Edge
- {
- private:
- std::vector<std::pair<int, int>> edges;
- public:
- Edge() = default;
- ~Edge() = default;
- int ParseEdge(JsonObject *root);
- std::vector<std::pair<int, int>>& GetEdgesAll() { return edges; }
};
class OutputMetadata
private:
bool parsed;
ScoreInfo score;
- BoxInfo box;
+ box::BoxInfo box;
Label label;
Number number;
Landmark landmark;
OffsetVec offsetVec;
std::vector<DispVec> dispVecs;
Edge edgeMap;
+ std::map<std::string, inference_tensor_shape_type_e> mSupportedShapeType;
int ParseScore(JsonObject *root);
int ParseBox(JsonObject *root);
int ParseEdgeMap(JsonObject * root);
public:
- static std::map<std::string, inference_tensor_shape_type_e> supportedTensorShapes;
/**
* @brief Creates an OutputMetadata class instance.
*
double GetScoreThreshold() { return score.GetThresHold(); }
int GetScoreTopNumber() { return score.GetTopNumber(); }
std::shared_ptr<DeQuantization> GetScoreDeQuant() { return score.GetDeQuant(); }
+ double GetScoreDeQuantScale() { return score.GetDeQuantScale(); }
+ double GetScoreDeQuantZeroPoint() { return score.GetDeQuantZeroPoint(); }
std::string GetBoxName() { return box.GetName(); }
DimInfo GetBoxDimInfo() { return box.GetDimInfo(); }
std::vector<int> GetBoxOrder() { return box.GetOrder(); }
- DecodeInfo& GetBoxDecodeInfo() { return box.GetDecodeInfo(); }
+ box::DecodeInfo& GetBoxDecodeInfo() { return box.GetDecodeInfo(); }
inference_box_type_e GetBoxType() { return box.GetType(); }
int GetScoreCoordinate() { return box.GetCoordinate(); }
- std::string GetLabelName() { return label.GetName(); }
- std::string GetNumberName() { return number.GetName(); }
- DimInfo GetNumberDimInfo() { return number.GetDimInfo(); }
+ std::string GetLabelName() { return label.name; }
+ std::string GetNumberName() { return number.name; }
+ DimInfo GetNumberDimInfo() { return number.dimInfo; }
std::string GetLandmarkName() { return landmark.GetName(); }
int GetLandmarkOffset() { return landmark.GetOffset(); }
inference_landmark_type_e GetLandmarkType() { return landmark.GetType(); }
inference_box_decoding_type_e GetBoxDecodingType() { return box.GetDecodingType(); }
std::vector<DispVec>& GetDispVecAll() { return dispVecs; }
std::vector<std::pair<int, int>>& GetEdges() { return edgeMap.GetEdgesAll(); }
- template <typename T>
- static T GetSupportedType(JsonObject* root, std::string typeName,
- std::map<std::string, T>& supportedTypes);
};
} /* Inference */
} /* MediaVision */
--- /dev/null
+/**
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef __SCORE_INFO_H__
+#define __SCORE_INFO_H__
+
+#include <string>
+#include <vector>
+#include <map>
+#include <memory>
+
+#include <mv_inference_type.h>
+#include "DimInfo.h"
+
+namespace mediavision
+{
+namespace inference
+{
+ struct DeQuantization
+ {
+ double scale;
+ double zeropoint;
+
+ DeQuantization(double s, double z) : scale(s), zeropoint(z) { }
+ };
+
+ class ScoreInfo
+ {
+ private:
+ std::string name;
+ DimInfo dimInfo;
+ double threshold;
+ int topNumber;
+ inference_score_type_e type;
+ std::shared_ptr<DeQuantization> deQuantization;
+ std::map<std::string, inference_score_type_e> supportedScoreTypes;
+
+ public:
+ ScoreInfo() :
+ name(),
+ 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() { return name; }
+ DimInfo GetDimInfo() { return dimInfo; }
+ double GetThresHold() { return threshold; }
+ inference_score_type_e GetType() { return type; }
+ int GetTopNumber() { return topNumber; }
+ std::shared_ptr<DeQuantization> GetDeQuant() { return deQuantization; }
+ double GetDeQuantScale() { return deQuantization->scale; }
+ double GetDeQuantZeroPoint() { return deQuantization->zeropoint; }
+
+ int ParseScore(JsonObject *root)
+ {
+ LOGI("ENTER");
+
+ JsonArray * rootArray = json_object_get_array_member(root, "score");
+ unsigned int elements = json_array_get_length(rootArray);
+
+ for (unsigned int elem = 0; elem < elements; ++elem) {
+ JsonNode *pNode = json_array_get_element(rootArray, elem);
+ JsonObject *pObject = json_node_get_object(pNode);
+
+ name = json_object_get_string_member(pObject,"name");
+ LOGI("layer: %s", name.c_str());
+
+ JsonArray * 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);
+ }
+
+ topNumber = static_cast<int>(json_object_get_int_member(pObject, "top_number"));
+ LOGI("top number: %d", topNumber);
+
+ 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;
+ }
+ };
+} /* Inference */
+} /* MediaVision */
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef __UTILS_H__
+#define __UTILS_H__
+
+#include <string>
+#include <vector>
+#include <map>
+#include <memory>
+
+#include <json-glib/json-glib.h>
+
+namespace mediavision
+{
+namespace inference
+{
+ template <typename T>
+ T GetSupportedType(JsonObject* root, std::string typeName, const 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);
+ }
+
+ LOGI("%s: %d:%s", typeName.c_str(), supportedType->second, supportedType->first.c_str());
+
+ return supportedType->second;
+ }
+} /* Inference */
+} /* MediaVision */
+
+#endif
\ No newline at end of file
if (outputMetadata.GetScoreDeQuant()) {
value = PostProcess::dequant(value,
- outputMetadata.GetScoreDeQuant()->GetScale(),
- outputMetadata.GetScoreDeQuant()->GetZeroPoint());
+ outputMetadata.GetScoreDeQuantScale(),
+ outputMetadata.GetScoreDeQuantZeroPoint());
}
if (outputMetadata.GetScoreType() == INFERENCE_SCORE_TYPE_SIGMOID)
#include <algorithm>
#include "InputMetadata.h"
#include <mv_common.h>
+#include "Utils.h"
namespace mediavision
{
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);
- }
-
- LOGI("%s: %d:%s", typeName.c_str(), supportedType->second, supportedType->first.c_str());
-
- return supportedType->second;
- }
-
int InputMetadata::GetTensorInfo(JsonObject *root)
{
LOGI("ENTER");
#include <string>
#include <queue>
#include <algorithm>
+
#include "OutputMetadata.h"
+#include "Utils.h"
+
+using namespace mediavision::inference::box;
namespace mediavision
{
namespace inference
{
- std::map<std::string, inference_tensor_shape_type_e> OutputMetadata::supportedTensorShapes =
- {{"NCHW", INFERENCE_TENSOR_SHAPE_NCHW}, {"NHWC", INFERENCE_TENSOR_SHAPE_NHWC}};
-
OutputMetadata::OutputMetadata() :
parsed(false),
score(),
dispVecs(),
edgeMap()
{
-
- }
-
- ScoreInfo::ScoreInfo() :
- name(),
- 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});
- }
-
- template <typename T>
- T OutputMetadata::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);
- }
-
- LOGI("%s: %d:%s", typeName.c_str(), supportedType->second, supportedType->first.c_str());
-
- return supportedType->second;
- }
-
- int ScoreInfo::ParseScore(JsonObject *root)
- {
- LOGI("ENTER");
-
- JsonArray * rootArray = json_object_get_array_member(root, "score");
- unsigned int elements = json_array_get_length(rootArray);
-
- for (unsigned int elem = 0; elem < elements; ++elem) {
- JsonNode *pNode = json_array_get_element(rootArray, elem);
- JsonObject *pObject = json_node_get_object(pNode);
-
- name = json_object_get_string_member(pObject,"name");
- LOGI("layer: %s", name.c_str());
-
- JsonArray * 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);
- }
-
- topNumber = static_cast<int>(json_object_get_int_member(pObject, "top_number"));
- LOGI("top number: %d", topNumber);
-
- threshold = static_cast<double>(json_object_get_double_member(pObject, "threshold"));
- LOGI("threshold: %1.3f", threshold);
-
- try {
- type = OutputMetadata::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;
+ // shape_type
+ mSupportedShapeType.insert({"NCHW", INFERENCE_TENSOR_SHAPE_NCHW});
+ mSupportedShapeType.insert({"NHWC", INFERENCE_TENSOR_SHAPE_NHWC});
}
int OutputMetadata::ParseScore(JsonObject *root)
return score.ParseScore(root);
}
- BoxInfo::BoxInfo() :
- name(),
- 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});
- }
-
- int BoxInfo::ParseBox(JsonObject *root)
- {
- LOGI("ENTER");
-
- JsonArray * rootArray = json_object_get_array_member(root, "box");
- unsigned int elements = json_array_get_length(rootArray);
-
- for (unsigned int elem = 0; elem < elements; ++elem) {
- JsonNode *pNode = json_array_get_element(rootArray, elem);
- JsonObject *pObject = json_node_get_object(pNode);
-
- name = json_object_get_string_member(pObject,"name");
- LOGI("layer: %s", name.c_str());
-
- JsonArray * 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);
- }
-
- try {
- type = OutputMetadata::GetSupportedType(pObject, "box_type", supportedBoxTypes);
- coordinate = OutputMetadata::GetSupportedType(pObject, "box_coordinate", supportedBoxCoordinateTypes);
- decodingType = OutputMetadata::GetSupportedType(pObject, "decoding_type", supportedBoxDecodingTypes);
- } catch (const std::exception& e) {
- LOGE("Invalid %s", e.what());
- return MEDIA_VISION_ERROR_INVALID_OPERATION;
- }
-
- array = json_object_get_array_member(pObject, "box_order");
- elements2 = json_array_get_length(array);
- LOGI("box order should have 4 elements and it has [%u]", elements2);
- for (unsigned int elem2 = 0; elem2 < elements2; ++elem2) {
- auto val = static_cast<int>(json_array_get_int_element(array, elem2));
- order.push_back(val);
- LOGI("%d", val);
- }
- }
-
- LOGI("LEAVE");
- return MEDIA_VISION_ERROR_NONE;
- }
-
void DecodeInfo::AddAnchorBox(cv::Rect2f& anchor)
{
anchorBoxes.push_back(anchor);
return box.ParseBox(root);
}
- int Label::ParseLabel(JsonObject *root)
+ int OutputMetadata::ParseLabel(JsonObject *root)
{
LOGI("ENTER");
+ if (!json_object_has_member(root, "label")) {
+ LOGE("No box outputmetadata");
+ LOGI("LEAVE");
+ return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ }
+
JsonArray * rootArray = json_object_get_array_member(root, "label");
unsigned int elements = json_array_get_length(rootArray);
JsonNode *pNode = json_array_get_element(rootArray, elem);
JsonObject *pObject = json_node_get_object(pNode);
- name = json_object_get_string_member(pObject,"name");
- LOGI("layer: %s", name.c_str());
+ label.name = json_object_get_string_member(pObject,"name");
+ LOGI("layer: %s", label.name.c_str());
JsonArray * 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);
+ label.dimInfo.SetValidIndex(elem2);
}
}
- LOGI("LEAVEL");
+ LOGI("LEAVE");
return MEDIA_VISION_ERROR_NONE;
}
- int OutputMetadata::ParseLabel(JsonObject *root)
+ int OutputMetadata::ParseNumber(JsonObject *root)
{
LOGI("ENTER");
- if (!json_object_has_member(root, "label")) {
- LOGE("No box outputmetadata");
+ if (!json_object_has_member(root, "number")) {
+ LOGE("No number outputmetadata");
LOGI("LEAVE");
return MEDIA_VISION_ERROR_INVALID_OPERATION;
}
- label.ParseLabel(root);
-
- LOGI("LEAVE");
- return MEDIA_VISION_ERROR_NONE;
- }
-
- int Number::ParseNumber(JsonObject *root)
- {
// box
JsonArray * rootArray = json_object_get_array_member(root, "number");
unsigned int elements = json_array_get_length(rootArray);
JsonNode *pNode = json_array_get_element(rootArray, elem);
JsonObject *pObject = json_node_get_object(pNode);
- name = json_object_get_string_member(pObject,"name");
- LOGI("layer: %s", name.c_str());
+ number.name = json_object_get_string_member(pObject,"name");
+
+ LOGI("layer: %s", number.name.c_str());
JsonArray * 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);
- }
- }
- return MEDIA_VISION_ERROR_NONE;
- }
-
- int OutputMetadata::ParseNumber(JsonObject *root)
- {
- LOGI("ENTER");
+ LOGI("range dim: size[%u]", elements2);
- if (!json_object_has_member(root, "number")) {
- LOGE("No number outputmetadata");
- LOGI("LEAVE");
- return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ for (unsigned int elem2 = 0; elem2 < elements2; ++elem2)
+ if (static_cast<int>(json_array_get_int_element(array, elem2)) == 1)
+ number.dimInfo.SetValidIndex(elem2);
}
- number.ParseNumber(root);
LOGI("LEAVE");
return MEDIA_VISION_ERROR_NONE;
JsonObject *object = json_object_get_object_member(root, "nms");
try {
- this->nmsParam.mode = OutputMetadata::GetSupportedType(object, "mode", this->nmsParam.supportedBoxNmsTypes);
+ this->nmsParam.mode = GetSupportedType(object, "mode", this->nmsParam.supportedBoxNmsTypes);
} catch (const std::exception& e) {
LOGE("Invalid %s", e.what());
return MEDIA_VISION_ERROR_INVALID_OPERATION;
return MEDIA_VISION_ERROR_NONE;
}
- Landmark::Landmark() :
- name(),
- dimInfo(),
- type(INFERENCE_LANDMARK_TYPE_2D_SINGLE),
- offset(),
- coordinate(INFERENCE_LANDMARK_COORDINATE_TYPE_RATIO),
- decodingType(INFERENCE_LANDMARK_DECODING_TYPE_BYPASS),
- heatMapInfo()
-
- {
- supportedLandmarkTypes.insert({"2D_SINGLE", INFERENCE_LANDMARK_TYPE_2D_SINGLE});
- supportedLandmarkTypes.insert({"2D_MULTI", INFERENCE_LANDMARK_TYPE_2D_MULTI});
- supportedLandmarkTypes.insert({"3D_SINGLE", INFERENCE_LANDMARK_TYPE_3D_SINGLE});
-
- supportedLandmarkCoordinateTypes.insert({"RATIO", INFERENCE_LANDMARK_COORDINATE_TYPE_RATIO});
- supportedLandmarkCoordinateTypes.insert({"PIXEL", INFERENCE_LANDMARK_COORDINATE_TYPE_PIXEL});
-
- supportedLandmarkDecodingTypes.insert({"BYPASS", INFERENCE_LANDMARK_DECODING_TYPE_BYPASS});
- supportedLandmarkDecodingTypes.insert({"HEATMAP", INFERENCE_LANDMARK_DECODING_TYPE_HEATMAP});
- supportedLandmarkDecodingTypes.insert({"HEATMAP_REFINE", INFERENCE_LANDMARK_DECODING_TYPE_HEATMAP_REFINE});
- }
-
- int Landmark::ParseLandmark(JsonObject *root)
- {
- // box
- JsonArray * rootArray = json_object_get_array_member(root, "landmark");
- unsigned int elements = json_array_get_length(rootArray);
-
- // TODO: handling error
- for (unsigned int elem = 0; elem < elements; ++elem) {
-
- JsonNode *pNode = json_array_get_element(rootArray, elem);
- JsonObject *pObject = json_node_get_object(pNode);
-
- name =
- static_cast<const char*>(json_object_get_string_member(pObject,"name"));
- LOGI("layer: %s", name.c_str());
-
- JsonArray * 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);
- }
-
- try {
- type = OutputMetadata::GetSupportedType(pObject, "landmark_type", supportedLandmarkTypes);
- coordinate = OutputMetadata::GetSupportedType(pObject, "landmark_coordinate", supportedLandmarkCoordinateTypes);
- decodingType = OutputMetadata::GetSupportedType(pObject, "decoding_type", supportedLandmarkDecodingTypes);
- } catch (const std::exception& e) {
- LOGE("Invalid %s", e.what());
- return MEDIA_VISION_ERROR_INVALID_OPERATION;
- }
-
- offset = static_cast<int>(json_object_get_int_member(pObject, "landmark_offset"));
- LOGI("landmark offset: %d", offset);
- }
-
- LOGI("LEAVE");
- return MEDIA_VISION_ERROR_NONE;
- }
-
- inference_landmark_type_e Landmark::GetType()
- {
- return type;
- }
-
- int Landmark::GetOffset()
- {
- return offset;
- }
-
- inference_landmark_coorindate_type_e Landmark::GetCoordinate()
- {
- return coordinate;
- }
-
- inference_landmark_decoding_type_e Landmark::GetDecodingType()
- {
- return decodingType;
- }
-
- HeatMapInfo& Landmark::GetHeatMapInfo()
- {
- return heatMapInfo;
- }
-
int OutputMetadata::ParseLandmark(JsonObject *root)
{
LOGI("ENTER");
JsonObject *object = json_object_get_object_member(cObject, "heatmap") ;
try {
- landmark.GetHeatMapInfo().shapeType = OutputMetadata::GetSupportedType(object, "shape_type", supportedTensorShapes);
+ landmark.GetHeatMapInfo().shapeType = GetSupportedType(object, "shape_type", mSupportedShapeType);
} catch (const std::exception& e) {
LOGE("Invalid %s", e.what());
return MEDIA_VISION_ERROR_INVALID_OPERATION;
return MEDIA_VISION_ERROR_NONE;
}
- int OffsetVec::ParseOffset(JsonObject *root)
- {
- JsonArray * rootArray = json_object_get_array_member(root, "offset");
- unsigned int elements = json_array_get_length(rootArray);
-
- // TODO: handling error
- for (unsigned int elem = 0; elem < elements; ++elem) {
-
- JsonNode *pNode = json_array_get_element(rootArray, elem);
- JsonObject *pObject = json_node_get_object(pNode);
-
- name =
- static_cast<const char*>(json_object_get_string_member(pObject,"name"));
- LOGI("layer: %s", name.c_str());
-
- JsonArray * 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);
- }
-
- try {
- shapeType = OutputMetadata::GetSupportedType(pObject, "shape_type", OutputMetadata::supportedTensorShapes);
- } catch (const std::exception& e) {
- LOGE("Invalid %s", e.what());
- return MEDIA_VISION_ERROR_INVALID_OPERATION;
- }
-
- }
-
- LOGI("LEAVE");
- return MEDIA_VISION_ERROR_NONE;
- }
-
int OutputMetadata::ParseOffset(JsonObject *root)
{
LOGI("ENTER");
return MEDIA_VISION_ERROR_INVALID_OPERATION;
}
- offsetVec.ParseOffset(root);
-
- LOGI("LEAVE");
- return MEDIA_VISION_ERROR_NONE;
- }
-
- DispVec::DispVec() :
- name(),
- dimInfo(),
- type(INFERENCE_DISPLACEMENT_TYPE_FORWARD),
- shapeType(INFERENCE_TENSOR_SHAPE_NCHW)
- {
- supportedDispTypes.insert({"FORWARD", INFERENCE_DISPLACEMENT_TYPE_FORWARD});
- supportedDispTypes.insert({"BACKWARD", INFERENCE_DISPLACEMENT_TYPE_BACKWARD});
- }
-
- int DispVec::ParseDisplacement(JsonObject *root)
- {
- LOGI("ENTER");
- name =
- static_cast<const char*>(json_object_get_string_member(root,"name"));
- LOGI("layer: %s", name.c_str());
-
- JsonArray * array = json_object_get_array_member(root, "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);
- }
-
- try {
- shapeType = OutputMetadata::GetSupportedType(root, "shape_type", OutputMetadata::supportedTensorShapes);
- type = OutputMetadata::GetSupportedType(root, "type", supportedDispTypes);
- } catch (const std::exception& e) {
- LOGE("Invalid %s", e.what());
- return MEDIA_VISION_ERROR_INVALID_OPERATION;
- }
+ offsetVec.ParseOffset(root, mSupportedShapeType);
LOGI("LEAVE");
return MEDIA_VISION_ERROR_NONE;
for (auto& disp : dispVecs) {
JsonNode *pNode = json_array_get_element(rootArray, elem++);
JsonObject *pObject = json_node_get_object(pNode);
- disp.ParseDisplacement(pObject);
- }
-
- LOGI("LEAVE");
- return MEDIA_VISION_ERROR_NONE;
- }
-
- int Edge::ParseEdge(JsonObject *root)
- {
- LOGI("ENTER");
- JsonArray * rootArray = json_object_get_array_member(root, "edgemap");
- unsigned int elements = json_array_get_length(rootArray);
-
- // TODO: handling error
- int pEdgeNode, cEdgeNode;
- for (unsigned int elem = 0; elem < elements; ++elem) {
-
- JsonNode *pNode = json_array_get_element(rootArray, elem);
- JsonObject *pObject = json_node_get_object(pNode);
- pEdgeNode = json_object_get_int_member(pObject, "parent");
- cEdgeNode = json_object_get_int_member(pObject, "child");
-
- edges.push_back(std::make_pair(pEdgeNode, cEdgeNode));
- LOGI("%ud: parent - child: %d - %d", elem, pEdgeNode, cEdgeNode);
+ disp.ParseDisplacement(pObject, mSupportedShapeType);
}
+
LOGI("LEAVE");
return MEDIA_VISION_ERROR_NONE;
}
return MEDIA_VISION_ERROR_NONE;
}
-
- void DimInfo::SetValidIndex(int index)
- {
- LOGI("ENTER");
-
- dims.push_back(index);
-
- LOGI("LEAVE");
- }
-
- std::vector<int> DimInfo::GetValidIndexAll() const
- {
- LOGI("ENTER");
-
- LOGI("LEAVE");
- return dims;
- }
} /* Inference */
} /* MediaVision */
Name: capi-media-vision
Summary: Media Vision library for Tizen Native API
-Version: 0.8.18
+Version: 0.8.19
Release: 1
Group: Multimedia/Framework
License: Apache-2.0 and BSD-3-Clause