Add testcase for YoloV5 DLC model 25/321325/4 sandbox/bhu1.gangula/tizen_8.0_rb5
authorBhuvan Reddy Gangula <bhu1.gangula@samsung.com>
Tue, 18 Mar 2025 10:56:24 +0000 (19:56 +0900)
committerBhuvan Reddy Gangula <bhu1.gangula@samsung.com>
Tue, 25 Mar 2025 04:07:03 +0000 (13:07 +0900)
1) DLC models need SNPE backend library to be installed in the target
2) Need nnstreamer snpe tensor filter to run

The SNPE library version and DLC model convertor(qnn sdk) version need to match since SNPE version 1 and 2 are not compatible

Change-Id: I18ac70eff752022e09b36700e5445b4c083db49a
Signed-off-by: Bhuvan Reddy Gangula <bhu1.gangula@samsung.com>
test/testsuites/machine_learning/object_detection/test_object_detection.cpp

index 5f045f6ec301a7626662bbcde9651259407499d1..bc54db45dd51a49c260e83553f556d354f239b5a 100644 (file)
@@ -277,3 +277,74 @@ TEST(FaceDetectionTest, InferenceShouldBeOk)
        ret = mv_destroy_source(mv_source);
        ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 }
+
+TEST(ObjectDetectionTest, DISABLED_InferenceDLCShouldBeOk)
+{
+       mv_object_detection_h handle;
+       vector<model_info> test_models {
+               { "yolo_v5", "yolov5m.dlc", "yolov5m.json", "label_coco_80.txt", "DOG" }
+               // TODO.
+       };
+
+       mv_source_h mv_source = NULL;
+       int ret = mv_create_source(&mv_source);
+       ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+       ret = ImageHelper::loadImageToSource(IMG_DOG, mv_source);
+       ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+       for (const auto &model : test_models) {
+               cout << "model name : " << model.model_file << endl;
+
+               ret = mv_object_detection_create(&handle);
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               mv_object_detection_set_model(handle, model.model_name.c_str(), model.model_file.c_str(),
+                                                                         model.meta_file.c_str(), model.label_file.c_str());
+               mv_object_detection_set_model_path(handle, "/opt/usr/globalapps/mediavision.object.detection/models/dlc/");
+               mv_object_detection_set_engine(handle, "snpe", "npu");
+
+               ret = mv_object_detection_configure(handle);
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_object_detection_prepare(handle);
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_object_detection_inference(handle, mv_source);
+               ASSERT_EQ(ret, 0);
+
+               unsigned int number_of_objects;
+               const int *left, *top, *right, *bottom;
+               unsigned long frame_number;
+               const float *confidences;
+
+               ret = mv_object_detection_get_result(handle, &number_of_objects, &frame_number, &confidences, &left, &top,
+                                                                                        &right, &bottom);
+               ASSERT_EQ(ret, 0);
+
+               for (unsigned int idx = 0; idx < number_of_objects; ++idx) {
+                       cout << "Frame number = " << frame_number << " probability = " << confidences[idx] << " " << left[idx]
+                                << " x " << top[idx] << " ~ " << right[idx] << " x " << bottom[idx] << endl;
+               }
+
+               for (unsigned int idx = 0; idx < number_of_objects; ++idx) {
+                       const char *label;
+
+                       ret = mv_object_detection_get_label(handle, idx, &label);
+                       ASSERT_EQ(ret, 0);
+                       cout << "index = " << idx << " label = " << label << endl;
+
+                       string label_str(label);
+
+                       transform(label_str.begin(), label_str.end(), label_str.begin(), ::toupper);
+
+                       ASSERT_TRUE(label_str == model.anster);
+               }
+
+               ret = mv_object_detection_destroy(handle);
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+       }
+
+       ret = mv_destroy_source(mv_source);
+       ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+}
\ No newline at end of file