From: Inki Dae Date: Wed, 7 Sep 2022 01:13:13 +0000 (+0900) Subject: mv_machine_learning: bug fix to face recognition API X-Git-Tag: submit/tizen/20220921.082242~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ffaf45c23643cf70beba33423c1d781a966a5b52;p=platform%2Fcore%2Fapi%2Fmediavision.git mv_machine_learning: bug fix to face recognition API [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 --- diff --git a/mv_machine_learning/face_recognition/include/face_recognition.h b/mv_machine_learning/face_recognition/include/face_recognition.h index 6dcfb3b..c2fb953 100644 --- a/mv_machine_learning/face_recognition/include/face_recognition.h +++ b/mv_machine_learning/face_recognition/include/face_recognition.h @@ -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(); }; diff --git a/mv_machine_learning/face_recognition/src/face_recognition.cpp b/mv_machine_learning/face_recognition/src/face_recognition.cpp index 678ecd3..227a23a 100644 --- a/mv_machine_learning/face_recognition/src/face_recognition.cpp +++ b/mv_machine_learning/face_recognition/src/face_recognition.cpp @@ -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."); diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index ba8863e..b63120d 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -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 diff --git a/test/testsuites/machine_learning/face_recognition/CMakeLists.txt b/test/testsuites/machine_learning/face_recognition/CMakeLists.txt index 05f8e0f..a7e87d2 100644 --- a/test/testsuites/machine_learning/face_recognition/CMakeLists.txt +++ b/test/testsuites/machine_learning/face_recognition/CMakeLists.txt @@ -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 index 0000000..1f45b33 --- /dev/null +++ b/test/testsuites/machine_learning/face_recognition/face_recognition_test_util.cpp @@ -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 + +#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 index 0000000..6d4e1ec --- /dev/null +++ b/test/testsuites/machine_learning/face_recognition/face_recognition_test_util.h @@ -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__ diff --git a/test/testsuites/machine_learning/face_recognition/measure_face_recognition.cpp b/test/testsuites/machine_learning/face_recognition/measure_face_recognition.cpp index 9311728..4e36f7b 100644 --- a/test/testsuites/machine_learning/face_recognition/measure_face_recognition.cpp +++ b/test/testsuites/machine_learning/face_recognition/measure_face_recognition.cpp @@ -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) diff --git a/test/testsuites/machine_learning/face_recognition/test_face_recognition.cpp b/test/testsuites/machine_learning/face_recognition/test_face_recognition.cpp index 37a278b..f5f004b 100644 --- a/test/testsuites/machine_learning/face_recognition/test_face_recognition.cpp +++ b/test/testsuites/machine_learning/face_recognition/test_face_recognition.cpp @@ -22,12 +22,10 @@ #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 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;