mv_machine_learning: bug fix to recognition request 75/279375/2 accepted/tizen/unified/20220809.213751 submit/tizen/20220808.075156
authorInki Dae <inki.dae@samsung.com>
Mon, 8 Aug 2022 06:43:57 +0000 (15:43 +0900)
committerInki Dae <inki.dae@samsung.com>
Mon, 8 Aug 2022 06:48:19 +0000 (15:48 +0900)
[Versin] : 0.23.11
[Issue type] : bug fix

Fixed a bug that it didn't handle an error case correctly
at recognition request without label file.

Without label file, recognition request incurred seg. fault issue so
this patch handles the error case correctly.

In addition, this patch adds a test case which tests a recognition request
without label file.

Change-Id: I9e577e4fe8e13f3865bfc2db4a60244626d31467
Signed-off-by: Inki Dae <inki.dae@samsung.com>
mv_machine_learning/face_recognition/src/face_recognition.cpp
mv_machine_learning/face_recognition/src/face_recognition_adapter.cpp
packaging/capi-media-vision.spec
test/testsuites/machine_learning/face_recognition/test_face_recognition.cpp

index 4731d9f7790b6f197f69a08d9ddc513cf767aa93..66473cc2c7f7686caa939298e697ae14c7b2096b 100644 (file)
@@ -619,6 +619,9 @@ int FaceRecognition::GetLabel(const char **out_label)
 
  mv_face_recognition_result_s& FaceRecognition::GetResult()
  {
+       if (!_label_manager)
+               throw NoData("Label file doesn't exist.");
+
        try {
                _label_manager->GetLabelString(_result.label, _result.label_idx);
        } catch (const BaseException& e) {
index da8aeec9cefd4d21af1feb40066a88d79cbc0b08..dba1829bb97200cf5aec785724c5113e5ceb94ae 100644 (file)
@@ -118,6 +118,9 @@ void FaceRecognitionAdapter<T, V>::perform()
                if (ret == MEDIA_VISION_ERROR_NO_DATA)
                        throw NoData("Label not found.");
 
+               if  (ret != MEDIA_VISION_ERROR_NONE)
+                       throw InvalidOperation("Fail to request a recognition.");
+
                return;
        }
 
index e43f4c85cbb7388b0e2cffdc8ccdb252c9cae41b..dbb8634d6d212610437ddcbd488a6d1ffec8adeb 100644 (file)
@@ -1,6 +1,6 @@
 Name:        capi-media-vision
 Summary:     Media Vision library for Tizen Native API
-Version:     0.23.10
+Version:     0.23.11
 Release:     0
 Group:       Multimedia/Framework
 License:     Apache-2.0 and BSD-3-Clause
index c24258e009a21c3c8110f7de860ef064055d0473..37e2c4546e0dee3e51e15eb5cacfa5211ee3eb37 100644 (file)
@@ -25,6 +25,9 @@
 
 #define TRAINING_IMAGE_PATH    "/home/owner/media/res/face_recognition/res/test/training/"
 #define TEST_IMAGE_PATH                "/home/owner/media/res/face_recognition/res/test/test/"
+#define LABEL_FILE_PATH                "/home/owner/media/res/face_recognition/training/labels.dat"
+#define MODEL_FILE_PATH                "/home/owner/media/res/face_recognition/training/model_and_weights.ini"
+#define FV_FILE_PATH           "/home/owner/media/res/face_recognition/training/feature_vector_file.dat"
 
 using namespace testing;
 using namespace std;
@@ -67,6 +70,13 @@ static const map<string, string> test_images = {
 
 using namespace MediaVision::Common;
 
+static void RemoveModelResources(void)
+{
+       remove(LABEL_FILE_PATH);
+       remove(MODEL_FILE_PATH);
+       remove(FV_FILE_PATH);
+}
+
 TEST(FaceRecognitionTest, FaceRecognitionSimpleTest)
 {
        mv_face_recognition_h handle;
@@ -145,6 +155,44 @@ TEST(FaceRecognitionTest, FaceRecognitionClassShouldBeOk)
 
        ret = mv_face_recognition_destroy(handle);
        ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+       RemoveModelResources();
+}
+
+TEST(FaceRecognitionTest, NoLabelShouldBeOk)
+{
+       mv_face_recognition_h handle;
+
+       int ret = mv_face_recognition_create(&handle);
+       ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+       ret = mv_face_recognition_prepare(handle);
+       ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+       for (auto& image : test_images) {
+               const string image_path = string(TEST_IMAGE_PATH) + image.first;
+               mv_source_h mv_source = NULL;
+
+               int ret = mv_create_source(&mv_source);
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = ImageHelper::loadImageToSource(image_path.c_str(), mv_source);
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_face_recognition_inference(handle, mv_source);
+               ASSERT_NE(ret, MEDIA_VISION_ERROR_NONE);
+
+               ret = mv_destroy_source(mv_source);
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+               const char *out_label = NULL;
+
+               ret  = mv_face_recognition_get_label(handle, &out_label);
+               ASSERT_NE(ret, MEDIA_VISION_ERROR_NONE);
+       }
+
+       ret = mv_face_recognition_destroy(handle);
+       ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 }
 
 TEST(FaceRecognitionTest, FaceRecognitionClassWithEachLabelRemovalShouldBeOk)
@@ -241,6 +289,8 @@ TEST(FaceRecognitionTest, FaceRecognitionClassWithEachLabelRemovalShouldBeOk)
 
        ret = mv_face_recognition_destroy(handle);
        ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+       RemoveModelResources();
 }
 
 TEST(FaceRecognitionTest, RemoveAllLabelsShouldBeOk)
@@ -277,6 +327,8 @@ TEST(FaceRecognitionTest, RemoveAllLabelsShouldBeOk)
 
        ret = mv_face_recognition_destroy(handle);
        ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+       RemoveModelResources();
 }
 
 int main(int argc, char **argv)