task_api: update label data for SemanticSegmentationTask 54/320354/1 tizen_devel
authorInki Dae <inki.dae@samsung.com>
Thu, 27 Feb 2025 06:18:16 +0000 (15:18 +0900)
committerInki Dae <inki.dae@samsung.com>
Thu, 27 Feb 2025 06:18:16 +0000 (15:18 +0900)
Update label data for SemanticSegmentationTask.

Change-Id: I255404b58772059da9d8218f593df3ac5a84b869
Signed-off-by: Inki Dae <inki.dae@samsung.com>
common/include/SingleoCommonTypes.h
inference/backends/mediavision/src/MvSemanticSegmentation.cpp
services/task_api/src/SemanticSegmentationTask.cpp

index e6240f6f48c313bbbee739da677a4bb0cbdb45d3..d2c6c251ad5226fab19febf6698d254bf8f0a833 100644 (file)
@@ -296,7 +296,7 @@ struct SsResultType : public BaseResultType {
        unsigned int width {};
        unsigned int height {};
        unsigned int pixel_size {};
-       std::vector<char> _labels;
+       std::vector<const char *> _labels;
        const unsigned char *_segment_map {};
 
        std::shared_ptr<BaseResultType> clone() override
index a293bc9da609001a5f015f59e81f1fefaf388b3e..c37f33ff5f47310627b74bebe3430aecd187bec8 100644 (file)
@@ -108,6 +108,23 @@ BaseResultType &MvSemanticSegmentation::result()
                ret = mv_semantic_segmentation_get_result(_handle, &_output_data.width, &_output_data.height, &_output_data.pixel_size, &_output_data._segment_map);
                if (ret != MEDIA_VISION_ERROR_NONE)
                        throw runtime_error("Fail to get semantic segmentation label.");
+
+               unsigned int num_labels {};
+               ret = mv_semantic_segmentation_get_label_count(_handle, &num_labels);
+               if (ret != MEDIA_VISION_ERROR_NONE)
+                       throw runtime_error("Fail to get semantic segmentation label count.");
+
+               for (unsigned int idx = 0; idx < num_labels; ++idx) {
+                       const char *label {};
+
+                       ret = mv_semantic_segmentation_get_label(_handle, idx, &label);
+                       if (ret != MEDIA_VISION_ERROR_NO_DATA && ret != MEDIA_VISION_ERROR_NONE)
+                               throw runtime_error("Fail to get a label.");
+
+                       // If there is no label, it means that the model does not provide a label. In this case, we do not push the label.
+                       if (ret != MEDIA_VISION_ERROR_NO_DATA)
+                               _output_data._labels.push_back(label);
+               }
        }
 
        return _output_data;
index 7d5a473bbe4e8ab1524d1104d20b9fa4562f0eb2..7d0ce12d7cf35b46d1fe7a6ac9e07e8efb1d8659 100644 (file)
@@ -107,6 +107,9 @@ void SemanticSegmentationTask::updateResult(std::vector<std::shared_ptr<BaseResu
                        _result.semantic_segmentation_result.height = dynamic_cast<SsResultType &>(*output).height;
                        _result.semantic_segmentation_result.pixel_size = dynamic_cast<SsResultType &>(*output).pixel_size;
 
+                       for (auto &label : dynamic_cast<SsResultType &>(*output)._labels)
+                               _result.semantic_segmentation_result.labels.push_back(label);
+
                        auto *segment_map = dynamic_cast<SsResultType &>(*output)._segment_map;
                        size_t seg_map_size = _result.semantic_segmentation_result.width *
                                                                        _result.semantic_segmentation_result.height *