mv_machine_learning: make testing more robust
authorVibhav Aggarwal <v.aggarwal@samsung.com>
Mon, 8 Jan 2024 07:07:18 +0000 (16:07 +0900)
committerKwanghoon Son <k.son@samsung.com>
Wed, 17 Jan 2024 01:31:52 +0000 (10:31 +0900)
[Issue type] code improvement

This patch makes the testing more robust by checking
the return value of some native APIs and also fixes
some minor bugs.

Change-Id: I352599b86467ce885e171b4b071a28eb396c2161
Signed-off-by: Vibhav Aggarwal <v.aggarwal@samsung.com>
mv_machine_learning/object_detection_3d/src/object_detection_3d_adapter.cpp
test/testsuites/common/image_helper/src/ImageHelper.cpp
test/testsuites/machine_learning/face_recognition/test_face_recognition_multi_threads.cpp
test/testsuites/machine_learning/image_classification/test_image_classification.cpp
test/testsuites/machine_learning/image_classification/test_image_classification_async.cpp
test/testsuites/machine_learning/image_segmentation/test_selfie_segmentation.cpp
test/testsuites/machine_learning/landmark_detection/test_landmark_detection_async.cpp
test/testsuites/machine_learning/object_detection/test_object_detection.cpp
test/testsuites/machine_learning/object_detection/test_object_detection_async.cpp
test/testsuites/machine_learning/object_detection_3d/test_object_detection_3d.cpp

index 44f441b..74e6af3 100644 (file)
@@ -89,8 +89,10 @@ void ObjectDetection3dAdapter::setModelInfo(const string &model_file, const stri
                LOGW("A given model name is invalid so default task type will be used.");
        }
 
-       if (model_file.empty() && meta_file.empty())
-               throw InvalidParameter("Model info not invalid.");
+       if (model_file.empty() && meta_file.empty()) {
+               LOGW("Given model info is invalid so default model info will be used instead.");
+               return;
+       }
 }
 
 void ObjectDetection3dAdapter::setEngineInfo(const string &engine_type, const string &device_type)
index b3f8550..2cc5888 100644 (file)
@@ -91,6 +91,10 @@ int ImageHelper::loadImageToSource(const char *filePath, mv_source_h source)
 
        MediaSource *mediaSource = static_cast<MediaSource *>(source);
        cv::Mat image = cv::imread(filePath);
+
+       if (!image.data)
+               return MEDIA_VISION_ERROR_INVALID_OPERATION;
+
        cv::cvtColor(image, image, CV_BGR2RGB);
 
        if (!(mediaSource->fill(image.data, image.total() * image.elemSize(), image.cols, image.rows, OPEN_CV_COLOR)))
index b566704..0d4859e 100644 (file)
@@ -142,6 +142,8 @@ void Unregister(mv_face_recognition_h handle)
 
 TEST(FaceRecognitionMultithreadTest, RegisterAndRecognizeShouldBeOk)
 {
+       RemoveModelResources();
+
        mv_face_recognition_h handle;
 
        int ret = mv_face_recognition_create(&handle);
@@ -165,6 +167,8 @@ TEST(FaceRecognitionMultithreadTest, RegisterAndRecognizeShouldBeOk)
 
 TEST(FaceRecognitionMultithreadTest, RegisterAndRecognizeAndUnregisterShouldBeOk)
 {
+       RemoveModelResources();
+
        mv_face_recognition_h handle;
 
        int ret = mv_face_recognition_create(&handle);
index cfc082a..9728223 100644 (file)
@@ -114,9 +114,12 @@ TEST(ImageClassificationTest, InferenceShouldBeOk)
                ret = mv_image_classification_create(&handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
-               mv_image_classification_set_model(handle, model.model_file.c_str(), model.meta_file.c_str(),
-                                                                                 model.label_file.c_str());
-               mv_image_classification_set_engine(handle, "tflite", "cpu");
+               ret = mv_image_classification_set_model(handle, model.model_file.c_str(), model.meta_file.c_str(),
+                                                                                               model.label_file.c_str());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_image_classification_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_image_classification_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
index 152cd21..d99c934 100644 (file)
@@ -84,9 +84,12 @@ TEST(ImageClassificationAsyncTest, InferenceShouldBeOk)
 
                cout << "model name : " << model.model_file << endl;
 
-               mv_image_classification_set_model(handle, model.model_file.c_str(), model.meta_file.c_str(),
-                                                                                 model.label_file.c_str());
-               mv_image_classification_set_engine(handle, "tflite", "cpu");
+               ret = mv_image_classification_set_model(handle, model.model_file.c_str(), model.meta_file.c_str(),
+                                                                                               model.label_file.c_str());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_image_classification_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_image_classification_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
@@ -143,9 +146,12 @@ TEST(ImageClassificationAsyncTest, InferenceShouldBeOkWithDestroyFirst)
 
                cout << "model name : " << model.model_file << endl;
 
-               mv_image_classification_set_model(handle, model.model_file.c_str(), model.meta_file.c_str(),
-                                                                                 model.label_file.c_str());
-               mv_image_classification_set_engine(handle, "tflite", "cpu");
+               ret = mv_image_classification_set_model(handle, model.model_file.c_str(), model.meta_file.c_str(),
+                                                                                               model.label_file.c_str());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_image_classification_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_image_classification_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
index 4e3602d..57864ee 100644 (file)
@@ -103,9 +103,12 @@ TEST(ImageSegmentationTest, DISABLED_InferenceShouldBeOk)
                ret = mv_selfie_segmentation_create(&handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
-               mv_selfie_segmentation_set_model(handle, model.model_name.c_str(), model.model_file.c_str(),
-                                                                                model.meta_file.c_str(), model.label_file.c_str());
-               mv_selfie_segmentation_set_engine(handle, "tflite", "cpu");
+               ret = mv_selfie_segmentation_set_model(handle, model.model_name.c_str(), model.model_file.c_str(),
+                                                                                          model.meta_file.c_str(), model.label_file.c_str());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_selfie_segmentation_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_selfie_segmentation_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
index fd57c67..4a89139 100644 (file)
@@ -85,9 +85,12 @@ TEST(PostLandmarkAsyncTest, InferenceShouldBeOk)
 
                cout << "model name : " << model.model_file << endl;
 
-               mv_pose_landmark_set_model(handle, model.model_name.c_str(), model.model_file.c_str(), model.meta_file.c_str(),
-                                                                  model.label_file.c_str());
-               mv_pose_landmark_set_engine(handle, "tflite", "cpu");
+               ret = mv_pose_landmark_set_model(handle, model.model_name.c_str(), model.model_file.c_str(),
+                                                                                model.meta_file.c_str(), model.label_file.c_str());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_pose_landmark_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_pose_landmark_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
@@ -137,9 +140,12 @@ TEST(PostLandmarkAsyncTest, InferenceShouldBeOkWithDestroyFirst)
 
                cout << "model name : " << model.model_file << endl;
 
-               mv_pose_landmark_set_model(handle, model.model_name.c_str(), model.model_file.c_str(), model.meta_file.c_str(),
-                                                                  model.label_file.c_str());
-               mv_pose_landmark_set_engine(handle, "tflite", "cpu");
+               ret = mv_pose_landmark_set_model(handle, model.model_name.c_str(), model.model_file.c_str(),
+                                                                                model.meta_file.c_str(), model.label_file.c_str());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_pose_landmark_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_pose_landmark_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
@@ -216,9 +222,12 @@ TEST(FacialLandmarkAsyncTest, InferenceShouldBeOk)
 
                cout << "model name : " << model.model_file << endl;
 
-               mv_facial_landmark_set_model(handle, model.model_name.c_str(), model.model_file.c_str(),
-                                                                        model.meta_file.c_str(), model.label_file.c_str());
-               mv_facial_landmark_set_engine(handle, "tflite", "cpu");
+               ret = mv_facial_landmark_set_model(handle, model.model_name.c_str(), model.model_file.c_str(),
+                                                                                  model.meta_file.c_str(), model.label_file.c_str());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_facial_landmark_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_facial_landmark_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
@@ -268,9 +277,12 @@ TEST(FacialLandmarkAsyncTest, InferenceShouldBeOkWithDestroyFirst)
 
                cout << "model name : " << model.model_file << endl;
 
-               mv_facial_landmark_set_model(handle, model.model_name.c_str(), model.model_file.c_str(),
-                                                                        model.meta_file.c_str(), model.label_file.c_str());
-               mv_facial_landmark_set_engine(handle, "tflite", "cpu");
+               ret = mv_facial_landmark_set_model(handle, model.model_name.c_str(), model.model_file.c_str(),
+                                                                                  model.meta_file.c_str(), model.label_file.c_str());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_facial_landmark_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_facial_landmark_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
index 5f045f6..2a205dd 100644 (file)
@@ -157,9 +157,12 @@ TEST(ObjectDetectionTest, InferenceShouldBeOk)
                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_engine(handle, "tflite", "cpu");
+               ret = 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());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_object_detection_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_object_detection_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
@@ -229,9 +232,12 @@ TEST(FaceDetectionTest, InferenceShouldBeOk)
                ret = mv_face_detection_create(&handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
-               mv_face_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_face_detection_set_engine(handle, "tflite", "cpu");
+               ret = mv_face_detection_set_model(handle, model.model_name.c_str(), model.model_file.c_str(),
+                                                                                 model.meta_file.c_str(), model.label_file.c_str());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_face_detection_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_face_detection_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
index a6cdda9..9dc68a1 100644 (file)
@@ -99,9 +99,12 @@ TEST(ObjectDetectionAsyncTest, InferenceShouldBeOk)
 
                cout << "model name : " << model.model_file << endl;
 
-               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_engine(handle, "tflite", "cpu");
+               ret = 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());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_object_detection_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_object_detection_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
@@ -154,9 +157,12 @@ TEST(ObjectDetectionAsyncTest, InferenceShouldBeOkWithDestroyFirst)
 
                cout << "model name : " << model.model_file << endl;
 
-               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_engine(handle, "tflite", "cpu");
+               ret = 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());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_object_detection_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_object_detection_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
@@ -244,9 +250,12 @@ TEST(FaceDetectionAsyncTest, InferenceShouldBeOk)
 
                cout << "model name : " << model.model_file << endl;
 
-               mv_face_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_face_detection_set_engine(handle, "tflite", "cpu");
+               ret = mv_face_detection_set_model(handle, model.model_name.c_str(), model.model_file.c_str(),
+                                                                                 model.meta_file.c_str(), model.label_file.c_str());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_face_detection_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_face_detection_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
@@ -297,9 +306,12 @@ TEST(FaceDetectionAsyncTest, InferenceShouldBeOkWithDestroyFirst)
 
                cout << "model name : " << model.model_file << endl;
 
-               mv_face_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_face_detection_set_engine(handle, "tflite", "cpu");
+               ret = mv_face_detection_set_model(handle, model.model_name.c_str(), model.model_file.c_str(),
+                                                                                 model.meta_file.c_str(), model.label_file.c_str());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_face_detection_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_face_detection_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
index d803e83..0ce07a5 100644 (file)
@@ -108,9 +108,12 @@ TEST(ObjectDetection3dTest, InferenceShouldBeOk)
                ret = mv_object_detection_3d_create(&handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
-               mv_object_detection_3d_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_3d_set_engine(handle, "tflite", "cpu");
+               ret = mv_object_detection_3d_set_model(handle, model.model_name.c_str(), model.model_file.c_str(),
+                                                                                          model.meta_file.c_str(), model.label_file.c_str());
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_object_detection_3d_set_engine(handle, "tflite", "cpu");
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_object_detection_3d_configure(handle);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);