mv_machine_learning: fix label removal issue of face recognition 19/298919/1
authorInki Dae <inki.dae@samsung.com>
Fri, 15 Sep 2023 07:17:51 +0000 (16:17 +0900)
committerInki Dae <inki.dae@samsung.com>
Fri, 15 Sep 2023 07:17:51 +0000 (16:17 +0900)
[Issue type] : bug fix
[Version] : 0.28.16

Fix a label removal issue of face recognition framework.

Due to this issue, seg. fault happened when unregistering a given label
because the label table wan't updated after unregistering the label.

Therefore, this patch fixes the problem by making sure to update the label
table after unregistering. In addition, this patch makes the result CAPI
to be allowed after mv_face_recognition_inference function call so relevalt
test case is also updated properly.

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

index 999dab8513698dde72c9c217a0befbc34b904cf3..a10ac8a95b5c7bd9e65450db29d477fdccbc87df 100644 (file)
@@ -186,6 +186,7 @@ int FaceRecognition::registerNewFace(std::vector<float> &input_vec, string label
                // label_cnt can be changed every time the training is performed and all data set will be used for the training
                // again in this case. So make sure to clear previous data set before next training.
                _training_model->clearDataSet(data_set);
+               _result.is_valid = false;
                _status = WorkingStatus::REGISTERED;
        } catch (const BaseException &e) {
                LOGE("%s", e.what());
@@ -332,13 +333,18 @@ int FaceRecognition::deleteLabel(string label_name)
                importLabel();
 
                unsigned int target_label_idx = _label_manager->getLabelIndex(label_name);
-
                auto label_cnt_ori = _label_manager->getMaxLabel();
 
+               LOGD("Current label count is %zu", label_cnt_ori);
+               LOGD("The index of label name(%s) is %d", label_name.c_str(), target_label_idx);
+
                // Get label count after removing a given label from the label file.
                _label_manager->removeLabel(label_name);
 
                auto label_cnt = _label_manager->getMaxLabel();
+
+               LOGD("Current label count is %zu after removing the label(%s)", label_cnt, label_name.c_str());
+
                unique_ptr<FeatureVectorManager> fvm = make_unique<FaceRecognitionFVM>(_config.feature_vector_file_path);
                unique_ptr<FeatureVectorManager> fvm_new =
                                make_unique<FaceRecognitionFVM>(_config.feature_vector_file_path + ".new");
@@ -350,6 +356,7 @@ int FaceRecognition::deleteLabel(string label_name)
 
                // feature vectors corresponding to given label aren't removed yet from feature vector file.
                // So label_cnt_ori is needed.
+               LOGD("Load the original feature vector data from the feature vector file.");
                data_set->loadDataSet(fvm->getFileName(), label_cnt_ori);
 
                vector<vector<float> > feature_vectors_old = data_set->getData();
@@ -412,6 +419,7 @@ int FaceRecognition::deleteLabel(string label_name)
 
                        // TODO. Remove existing internal model file.
 
+                       LOGD("Load the new feature vector data from the feature vector file.");
                        new_data_set->loadDataSet(_config.feature_vector_file_path, label_cnt);
                        _training_model->applyDataSet(new_data_set);
                        _training_model->compile();
@@ -428,6 +436,7 @@ int FaceRecognition::deleteLabel(string label_name)
                        LOGD("No training data so removed all relevant files.");
                }
 
+               _result.is_valid = false;
                _status = WorkingStatus::DELETED;
        } catch (const BaseException &e) {
                LOGE("%s", e.what());
index edb16dfcb6f10ff9799df3d2d217b4cceeaea1c0..588ad3ccf49cef24e950588b84eb6c96fde2c6a4 100644 (file)
@@ -100,6 +100,9 @@ unsigned int LabelManager::removeLabel(const string given_label)
                ret = ::rename(new_label_file.c_str(), _label_file.c_str());
                if (ret)
                        throw InvalidOperation("Fail to rename new labal file to original one.");
+
+               // Update _labels because label file is changed.
+               importLabel();
        }
 
        return label_index;
index 6f7cb029ebbec009a1c2fb4b6a32a38aab84ef05..ab4aec1c10667f4608cad639a879495510759c3c 100644 (file)
@@ -1,6 +1,6 @@
 Name:        capi-media-vision
 Summary:     Media Vision library for Tizen Native API
-Version:     0.28.15
+Version:     0.28.16
 Release:     1
 Group:       Multimedia/Framework
 License:     Apache-2.0
index d4102c2549effd991518b42c1fc87dfa84df4a73..fd99564f31f1dbf2a9014da7e0ecee4aeb77a81a 100644 (file)
@@ -273,12 +273,6 @@ TEST(FaceRecognitionTest, LabelUpdateAfterInferenceShouldBeOk)
                size_t num_of_confidences = 0;
                const float *confidences = nullptr;
 
-               ret = mv_face_recognition_get_confidence(handle, &confidences, &num_of_confidences);
-               ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
-
-               // num_of_confidence must be 2 because of no inference request.
-               ASSERT_EQ(num_of_confidences, 2);
-
                // If input is last one then request an inference.
                if (idx == image_names.size() - 1) {
                        ret = mv_face_recognition_inference(handle, mv_source);
@@ -297,16 +291,10 @@ TEST(FaceRecognitionTest, LabelUpdateAfterInferenceShouldBeOk)
                ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
        }
 
-       // Remove "2929" label from the label file.
-       ret = mv_face_recognition_unregister(handle, "2929");
+       // Remove a label, "7779".
+       ret = mv_face_recognition_unregister(handle, "7779");
        ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
 
-       ret = mv_face_recognition_get_confidence(handle, &confidences, &num_of_confidences);
-       ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
-
-       // num_of_confidences must be 3 yet because of no inference request.
-       ASSERT_EQ(num_of_confidences, 3);
-
        const string image_path = string(TRAINING_IMAGE_PATH) + image_names[0];
        mv_source_h mv_source = NULL;