mv_machine_learning: bug fix to face recognition API 25/280925/4
authorInki Dae <inki.dae@samsung.com>
Wed, 7 Sep 2022 01:13:13 +0000 (10:13 +0900)
committerInki Dae <inki.dae@samsung.com>
Tue, 13 Sep 2022 06:11:01 +0000 (15:11 +0900)
[Version] : 0.23.24-0
[Issue type] : bug fix and cleanup

Fixed a bug that it doesn't return an error from get_result() without
inference request. This patch makes get_result() to return an error
without inference request, adds a test case for it, and drops redundant code.

Change-Id: I552c81ae05247e1489c94d5069be11f7c0acd884
Signed-off-by: Inki Dae <inki.dae@samsung.com>
mv_machine_learning/face_recognition/include/face_recognition.h
mv_machine_learning/face_recognition/src/face_recognition.cpp
packaging/capi-media-vision.spec
test/testsuites/machine_learning/face_recognition/CMakeLists.txt
test/testsuites/machine_learning/face_recognition/face_recognition_test_util.cpp [new file with mode: 0644]
test/testsuites/machine_learning/face_recognition/face_recognition_test_util.h [new file with mode: 0644]
test/testsuites/machine_learning/face_recognition/measure_face_recognition.cpp
test/testsuites/machine_learning/face_recognition/test_face_recognition.cpp

index 6dcfb3b..c2fb953 100644 (file)
@@ -133,7 +133,6 @@ public:
        int RegisterNewFace(mv_source_h img_src, std::string label_name);
        int RecognizeFace(mv_source_h img_src);
        int DeleteLabel(std::string label_name);
-       int GetLabel(const char **out_label);
        mv_face_recognition_result_s &GetResult();
 };
 
index 678ecd3..227a23a 100644 (file)
@@ -648,27 +648,11 @@ int FaceRecognition::DeleteLabel(string label_name)
        return MEDIA_VISION_ERROR_NONE;
 }
 
-int FaceRecognition::GetLabel(const char **out_label)
-{
-       if (_status != INFERENCED) {
-               LOGE("Inference not completed yet.");
-               return MEDIA_VISION_ERROR_INVALID_OPERATION;
-       }
-
-       try {
-               _label_manager->GetLabelString(_result.label, _result.label_idx);
-       } catch (const BaseException &e) {
-               LOGE("%s", e.what());
-               return e.getError();
-       }
-
-       *out_label = _result.label.c_str();
-
-       return MEDIA_VISION_ERROR_NONE;
-}
-
 mv_face_recognition_result_s &FaceRecognition::GetResult()
 {
+       if (_status != INFERENCED)
+               throw InvalidOperation("Inference not completed yet.");
+
        if (!_label_manager)
                throw NoData("Label file doesn't exist.");
 
index ba8863e..b63120d 100644 (file)
@@ -1,6 +1,6 @@
 Name:        capi-media-vision
 Summary:     Media Vision library for Tizen Native API
-Version:     0.23.23
+Version:     0.23.24
 Release:     0
 Group:       Multimedia/Framework
 License:     Apache-2.0 and BSD-3-Clause
index 05f8e0f..a7e87d2 100644 (file)
@@ -4,8 +4,8 @@ cmake_minimum_required(VERSION 2.6...3.13)
 set(TEST_FACE_RECOGNITION test_face_recognition)
 set(MEASURE_ACCURACY measure_face_recognition)
 
-add_executable(${TEST_FACE_RECOGNITION} test_face_recognition.cpp)
-add_executable(${MEASURE_ACCURACY} measure_face_recognition.cpp)
+add_executable(${TEST_FACE_RECOGNITION} face_recognition_test_util.cpp test_face_recognition.cpp)
+add_executable(${MEASURE_ACCURACY} face_recognition_test_util.cpp measure_face_recognition.cpp)
 
 target_link_libraries(${TEST_FACE_RECOGNITION} gtest gtest_main
                                                                          mv_face_recognition
diff --git a/test/testsuites/machine_learning/face_recognition/face_recognition_test_util.cpp b/test/testsuites/machine_learning/face_recognition/face_recognition_test_util.cpp
new file mode 100644 (file)
index 0000000..1f45b33
--- /dev/null
@@ -0,0 +1,28 @@
+/**
+ * Copyright (c) 2022 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.
+ */
+
+#include <stdio.h>
+
+#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"
+
+void RemoveModelResources(void)
+{
+       remove(LABEL_FILE_PATH);
+       remove(MODEL_FILE_PATH);
+       remove(FV_FILE_PATH);
+}
\ No newline at end of file
diff --git a/test/testsuites/machine_learning/face_recognition/face_recognition_test_util.h b/test/testsuites/machine_learning/face_recognition/face_recognition_test_util.h
new file mode 100644 (file)
index 0000000..6d4e1ec
--- /dev/null
@@ -0,0 +1,22 @@
+/**
+ * Copyright (c) 2022 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 __FACE_RECOGNITION_TEST_UTIL_H__
+#define __FACE_RECOGNITION_TEST_UTIL_H__
+
+void RemoveModelResources(void);
+
+#endif //__FACE_RECOGNITION_TEST_UTIL_H__
index 9311728..4e36f7b 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "ImageHelper.h"
 #include "mv_face_recognition.h"
+#include "face_recognition_test_util.h"
 
 #define TRAIN_LIST_FILE "/home/owner/media/res/face_recognition/res/measurement/train_list.txt"
 #define TEST_LIST_FILE "/home/owner/media/res/face_recognition/res/measurement/test_list.txt"
@@ -165,6 +166,8 @@ TEST(FaceRecognitionAccuracy, Measure)
 
        ret = mv_face_recognition_destroy(handle);
        ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+       RemoveModelResources();
 }
 
 int main(int argc, char **argv)
index 37a278b..f5f004b 100644 (file)
 
 #include "ImageHelper.h"
 #include "mv_face_recognition.h"
+#include "face_recognition_test_util.h"
 
 #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;
@@ -48,13 +46,6 @@ 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, CreateAndDestroyShouldBeOk)
 {
        mv_face_recognition_h handle;
@@ -89,7 +80,7 @@ TEST(FaceRecognitionTest, InferenceAfterTrainingShouldBeOk)
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_face_recognition_register(handle, mv_source, image.second.c_str());
-               ASSERT_EQ(ret, 0);
+               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
                ret = mv_destroy_source(mv_source);
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
@@ -135,6 +126,44 @@ TEST(FaceRecognitionTest, InferenceAfterTrainingShouldBeOk)
        RemoveModelResources();
 }
 
+TEST(FaceRecognitionTest, GetLabelWithoutInferenceShouldBeError)
+{
+       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 : training_images) {
+               const string image_path = string(TRAINING_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_register(handle, mv_source, image.second.c_str());
+               ASSERT_EQ(ret, 0);
+
+               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_EQ(ret, MEDIA_VISION_ERROR_INVALID_OPERATION);
+
+       ret = mv_face_recognition_destroy(handle);
+       ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
+
+       RemoveModelResources();
+}
+
 TEST(FaceRecognitionTest, InferenceWithoutLabelShouldBeOk)
 {
        mv_face_recognition_h handle;