2 * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __FACE_RECOGNITION_H__
18 #define __FACE_RECOGNITION_H__
20 #include <unordered_map>
21 #include <mv_common.h>
22 #include <mv_inference_type.h>
24 #include "training_engine_error.h"
25 #include "training_engine_common_impl.h"
26 #include "inference_engine_common_impl.h"
27 #include "Inference.h"
28 #include "label_manager.h"
29 #include "backbone_model_info.h"
30 #include "feature_vector_manager.h"
31 #include "data_set_manager.h"
32 #include "simple_shot.h"
36 namespace machine_learning
38 namespace face_recognition
42 enum { NONE = 0, INITIALIZED, REGISTERED, INFERENCED, DELETED };
47 enum { REGISTER = 0, INFERENCE, DELETE };
52 struct face_recognition_register_input_s {
53 std::vector<float> data;
57 struct mv_face_recognition_input_s {
59 std::vector<face_recognition_register_input_s> register_src;
60 std::vector<std::vector<float> > inputs;
61 std::vector<std::string> labels;
65 * @brief The face recognition result structure.
66 * @details Contains face recognition result such as label, label index, raw data,
69 struct mv_face_recognition_result_s {
70 unsigned int label_idx; /**< label index of label file. */
71 std::vector<float> raw_data; /**< raw data to each label. */
72 std::string label; /**< label string. */
73 bool is_valid; /**< inference result is valid or not. */
76 struct FaceRecognitionConfig {
77 training_target_type_e training_target_device_type;
78 training_backend_type_e training_engine_backend_type;
79 mv_inference_target_device_e inference_target_device_type;
80 mv_inference_backend_type_e inference_engine_backend_type;
81 std::string internal_model_file_path;
82 std::string label_file_path;
83 std::string feature_vector_file_path;
84 double decision_threshold;
85 std::vector<size_t> input_tensor_shape;
92 std::unique_ptr<mediavision::inference::Inference> _internal;
93 std::unique_ptr<mediavision::inference::Inference> _backbone;
94 std::unique_ptr<IBackboneModelInfo> _backbone_model_info;
95 std::unique_ptr<TrainingModel> _training_model;
96 std::unique_ptr<LabelManager> _label_manager;
97 FaceRecognitionConfig _config;
98 mv_face_recognition_result_s _result;
100 // FYI. This function should be called every time a new face is registered.
102 void CheckFeatureVectorFile(std::string fv_file_name, std::string new_fv_file_name);
103 void StoreDataSet(std::unique_ptr<DataSetManager> &data_set, unsigned int label_cnt);
105 std::vector<model_layer_info> &GetBackboneInputLayerInfo();
106 int GetVecFromMvSource(mv_source_h img_src, std::vector<float> &out_vec);
113 void SetConfig(FaceRecognitionConfig &config);
114 int RegisterNewFace(std::vector<float> &input_vec, std::string label_name);
115 int RecognizeFace(std::vector<float> &input_vec);
116 int DeleteLabel(std::string label_name);
117 int GetLabel(const char **out_label);
118 mv_face_recognition_result_s &result();
121 } // machine_learning