virtual ~IBackboneModelInfo()
{}
- virtual std::vector<model_layer_info> &GetInputLayerInfo() = 0;
- virtual std::vector<model_layer_info> &GetOutputLayerInfo() = 0;
- virtual std::string GetModelFilePath() = 0;
+ virtual std::vector<model_layer_info> &getInputLayerInfo() = 0;
+ virtual std::vector<model_layer_info> &getOutputLayerInfo() = 0;
+ virtual std::string getModelFilePath() = 0;
};
#endif
\ No newline at end of file
} // face_recognition
-struct face_recognition_register_input_s {
+struct FaceRecognitionRegisterInput {
std::vector<float> data;
std::string label;
};
-struct mv_face_recognition_input_s {
+struct FaceRecognitionInput {
unsigned int mode;
- std::vector<face_recognition_register_input_s> register_src;
+ std::vector<FaceRecognitionRegisterInput> register_src;
std::vector<std::vector<float> > inputs;
std::vector<std::string> labels;
};
* @details Contains face recognition result such as label, label index, raw data,
* and raw data count.
*/
-struct mv_face_recognition_result_s {
+struct FaceRecognitionResult {
unsigned int label_idx; /**< label index of label file. */
std::vector<float> raw_data; /**< raw data to each label. */
std::string label; /**< label string. */
std::unique_ptr<TrainingModel> _training_model;
std::unique_ptr<LabelManager> _label_manager;
FaceRecognitionConfig _config;
- mv_face_recognition_result_s _result;
+ FaceRecognitionResult _result;
// FYI. This function should be called every time a new face is registered.
- void ImportLabel();
- void CheckFeatureVectorFile(std::string fv_file_name, std::string new_fv_file_name);
- void StoreDataSet(std::unique_ptr<DataSetManager> &data_set, unsigned int label_cnt);
- int GetAnswer();
- std::vector<model_layer_info> &GetBackboneInputLayerInfo();
- int GetVecFromMvSource(mv_source_h img_src, std::vector<float> &out_vec);
+ void importLabel();
+ void checkFeatureVectorFile(std::string fv_file_name, std::string new_fv_file_name);
+ void storeDataSet(std::unique_ptr<DataSetManager> &data_set, unsigned int label_cnt);
+ int getAnswer();
+ std::vector<model_layer_info> &getBackboneInputLayerInfo();
+ int getVecFromMvSource(mv_source_h img_src, std::vector<float> &out_vec);
public:
FaceRecognition();
~FaceRecognition();
- int Initialize();
- void SetConfig(FaceRecognitionConfig &config);
- int RegisterNewFace(std::vector<float> &input_vec, std::string label_name);
- int RecognizeFace(std::vector<float> &input_vec);
- int DeleteLabel(std::string label_name);
- int GetLabel(const char **out_label);
- mv_face_recognition_result_s &result();
+ int initialize();
+ void setConfig(FaceRecognitionConfig &config);
+ int registerNewFace(std::vector<float> &input_vec, std::string label_name);
+ int recognizeFace(std::vector<float> &input_vec);
+ int deleteLabel(std::string label_name);
+ int getLabel(const char **out_label);
+ FaceRecognitionResult &result();
};
} // machine_learning
class FaceRecognitionDSM : public DataSetManager
{
private:
- void PrintHeader(FeaVecHeader &fvh);
+ void printHeader(FeaVecHeader &fvh);
public:
FaceRecognitionDSM();
~FaceRecognitionDSM() = default;
- bool IsFeatureVectorAllowed(unsigned int label_idx) override;
- void LoadDataSet(const std::string file_name, unsigned int new_label_cnt) override;
- void AddDataSet(std::vector<float> &feature_vec, const unsigned int label_idx,
+ bool isFeatureVectorAllowed(unsigned int label_idx) override;
+ void loadDataSet(const std::string file_name, unsigned int new_label_cnt) override;
+ void addDataSet(std::vector<float> &feature_vec, const unsigned int label_idx,
const unsigned int label_cnt) override;
};
FaceRecognitionFVM(const std::string feature_vector_file = "feature_vector_file.dat");
~FaceRecognitionFVM() = default;
- void WriteHeader(size_t feature_size, size_t label_cnt, unsigned int data_set_cnt) override;
- void StoreData(std::vector<std::vector<float> > &features_vec, std::vector<unsigned int> &label_index) override;
- void Remove() override;
+ void writeHeader(size_t feature_size, size_t label_cnt, unsigned int data_set_cnt) override;
+ void storeData(std::vector<std::vector<float> > &features_vec, std::vector<unsigned int> &label_index) override;
+ void remove() override;
};
#endif
\ No newline at end of file
*/
#define MV_FACE_RECOGNITION_INPUT_TENSOR_SHAPE "FACE_RECOGNITION_INPUT_TENSOR_SHAPE"
-struct facenet_input_s {
+struct FacenetInput {
std::vector<mv_source_h> inputs;
};
-struct facenet_output_s {
+struct FacenetOutput {
std::vector<std::vector<float> > outputs;
};
std::unique_ptr<mediavision::inference::Inference> _inference;
std::unique_ptr<MediaVision::Common::EngineConfig> _config;
std::unique_ptr<MetaParser> _parser;
- facenet_output_s _result;
+ FacenetOutput _result;
inference_engine_tensor_buffer *_outputTensorBuffer {};
Preprocess _preprocess;
std::string _modelFilePath;
void prepare();
void preprocess(mv_source_h &mv_src);
void inference(mv_source_h source);
- facenet_output_s &result();
+ FacenetOutput &result();
};
} // machine_learning
TrainingEngineBackendInfo _engine_info;
private:
- void SaveModel(const std::string file_path) override;
- void RemoveModel(const std::string file_path) override;
+ void saveModel(const std::string file_path) override;
+ void removeModel(const std::string file_path) override;
public:
SimpleShot(const training_backend_type_e backend_type, const training_target_type_e target_type,
~SimpleShot();
// Configure layers for SimpleShot learning.
- void ConfigureModel(int num_of_class) override;
- TrainingEngineBackendInfo &GetTrainingEngineInfo() override;
+ void configureModel(int num_of_class) override;
+ TrainingEngineBackendInfo &getTrainingEngineInfo() override;
};
#endif
\ No newline at end of file
FaceRecognition::~FaceRecognition()
{
if (_label_manager)
- _label_manager->Clear();
+ _label_manager->clear();
}
-void FaceRecognition::CheckFeatureVectorFile(string fv_file_name, string new_fv_file_name)
+void FaceRecognition::checkFeatureVectorFile(string fv_file_name, string new_fv_file_name)
{
// Change new feature vector file to existing one in case that current process is terminated just after removing existing feature vector file but
// new feature vector file isn't changed to existing one yet.
- if (FaceRecogUtil::IsFileExist(new_fv_file_name) && !FaceRecogUtil::IsFileExist(fv_file_name)) {
+ if (FaceRecogUtil::isFileExist(new_fv_file_name) && !FaceRecogUtil::isFileExist(fv_file_name)) {
int ret = ::rename(new_fv_file_name.c_str(), fv_file_name.c_str());
if (ret)
throw InvalidOperation("Fail to rename new feature vector file to original one.");
// Make sure to remove a temp file in case that current process is terminated just after generating new feature vector file
// which is not correct file but existing one isn't removed. In this case, existing file is used again.
- if (FaceRecogUtil::IsFileExist(new_fv_file_name)) {
+ if (FaceRecogUtil::isFileExist(new_fv_file_name)) {
int ret = ::remove(new_fv_file_name.c_str());
if (ret)
throw InvalidOperation("Fail to remove new feature vector file.");
}
}
-void FaceRecognition::StoreDataSet(unique_ptr<DataSetManager> &data_set, unsigned int label_cnt)
+void FaceRecognition::storeDataSet(unique_ptr<DataSetManager> &data_set, unsigned int label_cnt)
{
try {
unique_ptr<FeatureVectorManager> fvm = make_unique<FaceRecognitionFVM>(_config.feature_vector_file_path);
make_unique<FaceRecognitionFVM>(_config.feature_vector_file_path + ".new");
// Make sure feature vector file.
- CheckFeatureVectorFile(fvm->GetFileName(), fvm_new->GetFileName());
+ checkFeatureVectorFile(fvm->getFileName(), fvm_new->getFileName());
// 1. Write feature vector and it's label index.
- fvm_new->StoreData(data_set->GetData(), data_set->GetLabelIdx());
+ fvm_new->storeData(data_set->getData(), data_set->getLabelIdx());
// 2. Write feature vector header.
- fvm_new->WriteHeader(data_set->GetFeaVecSize(), label_cnt, data_set->GetData().size());
+ fvm_new->writeHeader(data_set->getFeaVecSize(), label_cnt, data_set->getData().size());
int ret = 0;
// 3. Change new data file to existing one.
- if (FaceRecogUtil::IsFileExist(fvm->GetFileName())) {
- ret = ::remove(fvm->GetFileName().c_str());
+ if (FaceRecogUtil::isFileExist(fvm->getFileName())) {
+ ret = ::remove(fvm->getFileName().c_str());
if (ret)
throw InvalidOperation("Fail to remove feature vector file.");
}
- ret = ::rename(fvm_new->GetFileName().c_str(), fvm->GetFileName().c_str());
+ ret = ::rename(fvm_new->getFileName().c_str(), fvm->getFileName().c_str());
if (ret)
throw InvalidOperation("Fail to rename new feature vector file to original one.");
} catch (const BaseException &e) {
}
}
-void FaceRecognition::SetConfig(FaceRecognitionConfig &config)
+void FaceRecognition::setConfig(FaceRecognitionConfig &config)
{
_config = config;
}
-std::vector<model_layer_info> &FaceRecognition::GetBackboneInputLayerInfo()
+std::vector<model_layer_info> &FaceRecognition::getBackboneInputLayerInfo()
{
- return _backbone_model_info->GetInputLayerInfo();
+ return _backbone_model_info->getInputLayerInfo();
}
-int FaceRecognition::GetVecFromMvSource(mv_source_h img_src, std::vector<float> &out_vec)
+int FaceRecognition::getVecFromMvSource(mv_source_h img_src, std::vector<float> &out_vec)
{
mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
unsigned int width = 0, height = 0, bufferSize = 0;
return MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT;
}
- vector<model_layer_info> &input_layer_info = GetBackboneInputLayerInfo();
+ vector<model_layer_info> &input_layer_info = getBackboneInputLayerInfo();
// TODO. consider multiple tensor info.
size_t re_width = input_layer_info[0].tensor_info.shape[0];
size_t re_height = input_layer_info[0].tensor_info.shape[1];
LOGD("Convert mv source(WxH) : %d x %d => %zu x %zu", width, height, re_width, re_height);
- FeatureVectorManager::GetVecFromRGB(buffer, out_vec, width, height, re_width, re_height);
+ FeatureVectorManager::getVecFromRGB(buffer, out_vec, width, height, re_width, re_height);
return MEDIA_VISION_ERROR_NONE;
}
-int FaceRecognition::Initialize()
+int FaceRecognition::initialize()
{
_training_model = make_unique<SimpleShot>(_config.training_engine_backend_type, _config.training_target_device_type,
_config.input_tensor_shape, _config.internal_model_file_path);
_internal = make_unique<Inference>();
- int ret = _internal->Bind(_config.inference_engine_backend_type, _config.inference_target_device_type);
+ int ret = _internal->bind(_config.inference_engine_backend_type, _config.inference_target_device_type);
if (ret != MEDIA_VISION_ERROR_NONE)
return ret;
return MEDIA_VISION_ERROR_NONE;
}
-void FaceRecognition::ImportLabel()
+void FaceRecognition::importLabel()
{
try {
// Prepare can be called several times after initialization is done so previous data should be dropped.
_label_manager = make_unique<LabelManager>(_config.label_file_path, _config.decision_threshold);
// Update label manager from a given label file.
- int cnt = _label_manager->ImportLabel();
+ int cnt = _label_manager->importLabel();
LOGD("%d labels have been imported", cnt);
} catch (const BaseException &e) {
}
}
-int FaceRecognition::RegisterNewFace(std::vector<float> &input_vec, string label_name)
+int FaceRecognition::registerNewFace(std::vector<float> &input_vec, string label_name)
{
if (_status < INITIALIZED) {
LOGE("Initialization not ready yet. (%u)", _status);
// TODO. consider data augmentation.
try {
// Import label data from a label file.
- ImportLabel();
+ importLabel();
// 1. Store only label names to label file, which aren't duplicated.
- bool duplicated = _label_manager->AddLabelToMap(label_name, label_name);
+ bool duplicated = _label_manager->addLabelToMap(label_name, label_name);
if (!duplicated) {
- int ret = _label_manager->AddLabelToFile(label_name);
+ int ret = _label_manager->addLabelToFile(label_name);
if (ret == 0)
return MEDIA_VISION_ERROR_INVALID_OPERATION;
}
// Get label index and count.
- unsigned int label_idx = _label_manager->GetLabelIndex(label_name);
- unsigned int label_cnt = _label_manager->GetMaxLabel();
+ unsigned int label_idx = _label_manager->getLabelIndex(label_name);
+ unsigned int label_cnt = _label_manager->getMaxLabel();
- _training_model->ConfigureModel(label_cnt);
+ _training_model->configureModel(label_cnt);
unique_ptr<DataSetManager> data_set = make_unique<FaceRecognitionDSM>();
- data_set->Clear();
+ data_set->clear();
// Load existing feature vectors if the feature vector file exists.
- if (FaceRecogUtil::IsFileExist(_config.feature_vector_file_path) == true) {
+ if (FaceRecogUtil::isFileExist(_config.feature_vector_file_path) == true) {
LOGI("feature vector file already exists so it loads the file first.");
- data_set->LoadDataSet(_config.feature_vector_file_path, label_cnt);
+ data_set->loadDataSet(_config.feature_vector_file_path, label_cnt);
}
// Add new feature vector only in case that feature vector count of given label_idx is less then 5.
// It means that only 5 set of feature vector per a label is valid.
// TODO. According to feature vector priority, new feature vector should be added.
- if (data_set->IsFeatureVectorAllowed(label_idx))
- data_set->AddDataSet(input_vec, label_idx, label_cnt);
+ if (data_set->isFeatureVectorAllowed(label_idx))
+ data_set->addDataSet(input_vec, label_idx, label_cnt);
- _training_model->ApplyDataSet(data_set);
- _training_model->Compile();
- _training_model->Train();
+ _training_model->applyDataSet(data_set);
+ _training_model->compile();
+ _training_model->train();
// TODO. apply feature vector priority policy here.
// We can get weight trained from training engine.
// _training_model->getWeights(&weights, &size, "centroid_knn1");
// Store dataset to feature vector file.
- StoreDataSet(data_set, label_cnt);
+ storeDataSet(data_set, label_cnt);
// 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);
+ _training_model->clearDataSet(data_set);
_status = REGISTERED;
} catch (const BaseException &e) {
LOGE("%s", e.what());
return MEDIA_VISION_ERROR_NONE;
}
-int FaceRecognition::GetAnswer()
+int FaceRecognition::getAnswer()
{
int answer_idx;
answer_idx = max_element(_result.raw_data.begin(), _result.raw_data.end()) - _result.raw_data.begin();
// Check decision threshold.
- if (_result.raw_data[answer_idx] < _label_manager->GetDecisionThreshold()) {
+ if (_result.raw_data[answer_idx] < _label_manager->getDecisionThreshold()) {
throw NoData("Not meet decision threshold.");
}
- float weighted = _result.raw_data[answer_idx] * _label_manager->GetDecisionWeight();
+ float weighted = _result.raw_data[answer_idx] * _label_manager->getDecisionWeight();
// Check decision weight threshold.
for (auto &r : _result.raw_data) {
return MEDIA_VISION_ERROR_NONE;
}
-int FaceRecognition::RecognizeFace(std::vector<float> &input_vec)
+int FaceRecognition::recognizeFace(std::vector<float> &input_vec)
{
if (_status < INITIALIZED) {
LOGE("Initialization not ready yet.(%u)", _status);
return MEDIA_VISION_ERROR_INVALID_OPERATION;
}
- if (!FaceRecogUtil::IsFileExist(_config.internal_model_file_path)) {
+ if (!FaceRecogUtil::isFileExist(_config.internal_model_file_path)) {
LOGE("Internal model file(%s) doesn't exist.", _config.internal_model_file_path.c_str());
return MEDIA_VISION_ERROR_INVALID_PATH;
}
- TrainingEngineBackendInfo engine_info = _training_model->GetTrainingEngineInfo();
+ TrainingEngineBackendInfo engine_info = _training_model->getTrainingEngineInfo();
vector<string> &input_layers = engine_info.input_layer_names;
vector<inference_engine_tensor_info> &input_tensor_info = engine_info.input_tensor_info;
vector<string> &output_layers = engine_info.output_layer_names;
try {
// Import label data from a label file.
- ImportLabel();
+ importLabel();
// Tensor order is NCHW.
size_t width = input_tensor_info[0].shape[0];
size_t height = input_tensor_info[0].shape[1];
size_t ch = input_tensor_info[0].shape[2];
- _internal->ConfigureInputInfo(width, height, 1, ch, 1.0f, 0.0f, MV_INFERENCE_DATA_FLOAT32, input_layers);
+ _internal->configureInputInfo(width, height, 1, ch, 1.0f, 0.0f, MV_INFERENCE_DATA_FLOAT32, input_layers);
// Output tensor size should be a number of labels so update it.
- output_tensor_info[0].shape[0] = _label_manager->GetMaxLabel();
- _internal->ConfigureOutputInfo(output_layers, output_tensor_info);
+ output_tensor_info[0].shape[0] = _label_manager->getMaxLabel();
+ _internal->configureOutputInfo(output_layers, output_tensor_info);
- _internal->ConfigureModelFiles("", _config.internal_model_file_path, "");
+ _internal->configureModelFiles("", _config.internal_model_file_path, "");
// Load the trained internal model.
- int ret = _internal->Load();
+ int ret = _internal->load();
if (ret != INFERENCE_ENGINE_ERROR_NONE) {
LOGE("Fail to Load.");
return MEDIA_VISION_ERROR_INVALID_OPERATION;
std::vector<std::vector<float> > input_tensors = { input_vec };
// Do inference to the internal model.
- ret = _internal->Run(input_tensors);
+ ret = _internal->run(input_tensors);
if (ret != INFERENCE_ENGINE_ERROR_NONE) {
LOGE("fail to inference internal model.");
return MEDIA_VISION_ERROR_INVALID_OPERATION;
}
// output layer size should be 1.
- TensorBuffer tensorBuffer = _internal->GetOutputTensorBuffer();
+ TensorBuffer tensorBuffer = _internal->getOutputTensorBuffer();
inference_engine_tensor_buffer *internal_output_buffer = tensorBuffer.getTensorBuffer(output_layers[0]);
if (!internal_output_buffer) {
LOGE("fail to get internal output tensor buffer.");
copy(raw_buffer, raw_buffer + internal_output_buffer->size / sizeof(float), back_inserter(_result.raw_data));
_status = INFERENCED;
- return GetAnswer();
+ return getAnswer();
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
return MEDIA_VISION_ERROR_INVALID_OPERATION;
}
-int FaceRecognition::DeleteLabel(string label_name)
+int FaceRecognition::deleteLabel(string label_name)
{
if (_status < INITIALIZED) {
LOGE("Initialization not ready yet.(%u)", _status);
try {
// Import label data from a label file.
- ImportLabel();
+ importLabel();
- if (_label_manager->IsExist(label_name) == false) {
+ if (_label_manager->isExist(label_name) == false) {
LOGE("%s doesn't exist in label file.", label_name.c_str());
return MEDIA_VISION_ERROR_INVALID_OPERATION;
}
- unsigned int target_label_idx = _label_manager->GetLabelIndex(label_name);
+ unsigned int target_label_idx = _label_manager->getLabelIndex(label_name);
- auto label_cnt_ori = _label_manager->GetMaxLabel();
+ auto label_cnt_ori = _label_manager->getMaxLabel();
// Get label count after removing a given label from the label file.
- _label_manager->RemoveLabel(label_name);
+ _label_manager->removeLabel(label_name);
- auto label_cnt = _label_manager->GetMaxLabel();
+ auto label_cnt = _label_manager->getMaxLabel();
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");
// Make sure feature vector file.
- CheckFeatureVectorFile(fvm->GetFileName(), fvm_new->GetFileName());
+ checkFeatureVectorFile(fvm->getFileName(), fvm_new->getFileName());
unique_ptr<DataSetManager> data_set = make_unique<FaceRecognitionDSM>();
// feature vectors corresponding to given label aren't removed yet from feature vector file.
// So label_cnt_ori is needed.
- data_set->LoadDataSet(fvm->GetFileName(), label_cnt_ori);
+ data_set->loadDataSet(fvm->getFileName(), label_cnt_ori);
- vector<vector<float> > feature_vectors_old = data_set->GetData();
- vector<unsigned int> label_idx_vectors_old = data_set->GetLabelIdx();
+ vector<vector<float> > feature_vectors_old = data_set->getData();
+ vector<unsigned int> label_idx_vectors_old = data_set->getLabelIdx();
vector<vector<float> > feature_vectors_new;
vector<unsigned int> label_idx_vectors_new;
// Retrain only in case that feature vectors exist.
if (data_set_cnt > 0) {
- fvm_new->StoreData(feature_vectors_new, label_idx_vectors_new);
- fvm_new->WriteHeader(feature_vectors_new[0].size(), label_cnt, data_set_cnt);
+ fvm_new->storeData(feature_vectors_new, label_idx_vectors_new);
+ fvm_new->writeHeader(feature_vectors_new[0].size(), label_cnt, data_set_cnt);
int ret = 0;
- if (FaceRecogUtil::IsFileExist(fvm->GetFileName())) {
+ if (FaceRecogUtil::isFileExist(fvm->getFileName())) {
// Change new data file to existing one.
- ret = ::remove(fvm->GetFileName().c_str());
+ ret = ::remove(fvm->getFileName().c_str());
if (ret)
throw InvalidOperation("Fail to remove feature vector file.");
}
- ret = ::rename(fvm_new->GetFileName().c_str(), fvm->GetFileName().c_str());
+ ret = ::rename(fvm_new->getFileName().c_str(), fvm->getFileName().c_str());
if (ret)
throw InvalidOperation("Fail to rename new feature vector file to original one.");
- _training_model->ConfigureModel(label_cnt);
+ _training_model->configureModel(label_cnt);
unique_ptr<DataSetManager> new_data_set = make_unique<FaceRecognitionDSM>();
- new_data_set->Clear();
+ new_data_set->clear();
// TODO. Remove existing internal model file.
- new_data_set->LoadDataSet(_config.feature_vector_file_path, label_cnt);
- _training_model->ApplyDataSet(new_data_set);
- _training_model->Compile();
- _training_model->Train();
+ new_data_set->loadDataSet(_config.feature_vector_file_path, label_cnt);
+ _training_model->applyDataSet(new_data_set);
+ _training_model->compile();
+ _training_model->train();
// TODO. apply feature vector priority policy here.
// We can get weight trained from NNTrainer.
// _training_model->getWeights(&weights, &size, "centroid_knn1");
} else {
- _training_model->RemoveModel();
- fvm->Remove();
- _label_manager->Remove();
+ _training_model->removeModel();
+ fvm->remove();
+ _label_manager->removeFile();
LOGD("No training data so removed all relevant files.");
}
return MEDIA_VISION_ERROR_NONE;
}
-int FaceRecognition::GetLabel(const char **out_label)
+int FaceRecognition::getLabel(const char **out_label)
{
if (_status != INFERENCED) {
LOGE("Inference not completed yet. (%d)", _status);
}
try {
- _label_manager->GetLabelString(_result.label, _result.label_idx);
+ _label_manager->getLabelString(_result.label, _result.label_idx);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
return MEDIA_VISION_ERROR_NONE;
}
-mv_face_recognition_result_s &FaceRecognition::result()
+FaceRecognitionResult &FaceRecognition::result()
{
if (!_result.is_valid)
throw NoData("Inference result not ready yet.");
- ImportLabel();
+ importLabel();
if (!_label_manager)
throw NoData("Label file doesn't exist.");
try {
- _label_manager->GetLabelString(_result.label, _result.label_idx);
+ _label_manager->getLabelString(_result.label, _result.label_idx);
} catch (const BaseException &e) {
LOGE("%s", e.what());
throw e;
for (auto value : vecIntValues)
config.input_tensor_shape.push_back(static_cast<size_t>(value));
- _face_recognition->SetConfig(config);
+ _face_recognition->setConfig(config);
}
template<typename T, typename V> void FaceRecognitionAdapter<T, V>::prepare()
{
- int ret = _face_recognition->Initialize();
+ int ret = _face_recognition->initialize();
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to initialize face recognition.");
}
{
if (_source.mode == mode::REGISTER) {
for (auto &s : _source.register_src) {
- int ret = _face_recognition->RegisterNewFace(s.data, s.label);
+ int ret = _face_recognition->registerNewFace(s.data, s.label);
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to register new face.");
}
if (_source.mode == mode::INFERENCE) {
// _source.inputs.size should be 1.
- int ret = _face_recognition->RecognizeFace(_source.inputs[0]);
+ int ret = _face_recognition->recognizeFace(_source.inputs[0]);
if (ret == MEDIA_VISION_ERROR_NO_DATA)
throw NoData("Label not found.");
if (_source.mode == mode::DELETE) {
for (auto &l : _source.labels) {
- int ret = _face_recognition->DeleteLabel(l);
+ int ret = _face_recognition->deleteLabel(l);
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to unregister a given label.");
}
return _face_recognition->result();
}
-template class FaceRecognitionAdapter<mv_face_recognition_input_s, mv_face_recognition_result_s>;
+template class FaceRecognitionAdapter<FaceRecognitionInput, FaceRecognitionResult>;
}
}
\ No newline at end of file
using namespace std;
using namespace mediavision::machine_learning::exception;
-void FaceRecognitionDSM::PrintHeader(FeaVecHeader &fvh)
+void FaceRecognitionDSM::printHeader(FeaVecHeader &fvh)
{
LOGD("signature = %u", fvh.signature);
LOGD("feature vector size = %zu", fvh.feature_size);
FaceRecognitionDSM::FaceRecognitionDSM() : DataSetManager()
{}
-bool FaceRecognitionDSM::IsFeatureVectorAllowed(unsigned int label_idx)
+bool FaceRecognitionDSM::isFeatureVectorAllowed(unsigned int label_idx)
{
return (_fv_cnt_per_label[label_idx] < MAX_FEATURE_VECTOR_CNT);
}
-void FaceRecognitionDSM::AddDataSet(std::vector<float> &feature_vec, const unsigned int label_idx,
+void FaceRecognitionDSM::addDataSet(std::vector<float> &feature_vec, const unsigned int label_idx,
const unsigned int label_cnt)
{
_data.push_back(feature_vec);
_label_count = label_cnt;
}
-void FaceRecognitionDSM::LoadDataSet(const string file_name, unsigned int new_label_cnt)
+void FaceRecognitionDSM::loadDataSet(const string file_name, unsigned int new_label_cnt)
{
std::ifstream inFile(file_name);
inFile.seekg(0, ios::beg);
- PrintHeader(fvh);
+ printHeader(fvh);
if (FeatureVectorManager::feature_vector_signature != fvh.signature)
throw InvalidOperation("Wrong feature vector header.");
FaceRecognitionFVM::FaceRecognitionFVM(const string feature_vector_file) : FeatureVectorManager(feature_vector_file)
{}
-void FaceRecognitionFVM::WriteHeader(size_t feature_size, size_t label_cnt, unsigned int data_set_cnt)
+void FaceRecognitionFVM::writeHeader(size_t feature_size, size_t label_cnt, unsigned int data_set_cnt)
{
ofstream outFile { _feature_vector_file, ios::out | ios::binary | ios::app };
outFile.write((char *) &fvHeader, sizeof(FeaVecHeader));
}
-void FaceRecognitionFVM::StoreData(vector<vector<float> > &features_vec, vector<unsigned int> &label_index)
+void FaceRecognitionFVM::storeData(vector<vector<float> > &features_vec, vector<unsigned int> &label_index)
{
ofstream outFile { _feature_vector_file, ios::out | ios::binary | ios::app };
}
}
-void FaceRecognitionFVM::Remove()
+void FaceRecognitionFVM::remove()
{
// Remove existing file forcely.
int ret = ::remove(_feature_vector_file.c_str());
_parser = make_unique<FacenetParser>();
}
-static bool IsJsonFile(const string &fileName)
+static bool isJsonFile(const string &fileName)
{
return (!fileName.substr(fileName.find_last_of(".") + 1).compare("json"));
}
if (_modelMetaFilePath.empty())
throw InvalidOperation("Model meta file doesn't exist.");
- if (!IsJsonFile(_modelMetaFilePath))
+ if (!isJsonFile(_modelMetaFilePath))
throw InvalidOperation("Model meta file should be json.");
_parser->load(_modelMetaFilePath);
void Facenet::configure()
{
- int ret = _inference->Bind(_backendType, _targetDeviceType);
+ int ret = _inference->bind(_backendType, _targetDeviceType);
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to bind a backend engine.");
}
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to configure output tensor info from meta file.");
- _inference->ConfigureModelFiles("", _modelFilePath, "");
+ _inference->configureModelFiles("", _modelFilePath, "");
// Request to load model files to a backend engine.
- ret = _inference->Load();
+ ret = _inference->load();
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to load model files.");
}
{
LOGI("ENTER");
- int ret = _inference->Run();
+ int ret = _inference->run();
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to run inference");
LOGI("LEAVE");
}
-facenet_output_s &Facenet::result()
+FacenetOutput &Facenet::result()
{
- TensorBuffer &tensor_buffer_obj = _inference->GetOutputTensorBuffer();
+ TensorBuffer &tensor_buffer_obj = _inference->getOutputTensorBuffer();
// Make sure to clear _result.outputs vectors because if not clear then other output_vector will be pushed to _result.outputs
// and it results in sending wrong output vector to face recognition framework.
return _facenet->result();
}
-template class FacenetAdapter<facenet_input_s, facenet_output_s>;
+template class FacenetAdapter<FacenetInput, FacenetOutput>;
}
}
\ No newline at end of file
using namespace mediavision::machine_learning;
using namespace mediavision::machine_learning::face_recognition;
using namespace mediavision::machine_learning::exception;
-using FaceRecognitionTask = ITask<mv_face_recognition_input_s, mv_face_recognition_result_s>;
-using FacenetTask = ITask<facenet_input_s, facenet_output_s>;
+using FaceRecognitionTask = ITask<FaceRecognitionInput, FaceRecognitionResult>;
+using FacenetTask = ITask<FacenetInput, FacenetOutput>;
int mv_face_recognition_create_open(mv_face_recognition_h *handle)
{
}
FaceRecognitionTask *face_recognition_task = new (nothrow)
- FaceRecognitionAdapter<mv_face_recognition_input_s, mv_face_recognition_result_s>();
+ FaceRecognitionAdapter<FaceRecognitionInput, FaceRecognitionResult>();
if (!face_recognition_task) {
delete context;
LOGE("Fail to allocate a task.");
return MEDIA_VISION_ERROR_OUT_OF_MEMORY;
}
- FacenetTask *facenet_task = new (nothrow) FacenetAdapter<facenet_input_s, facenet_output_s>();
+ FacenetTask *facenet_task = new (nothrow) FacenetAdapter<FacenetInput, FacenetOutput>();
if (!facenet_task) {
delete face_recognition_task;
delete context;
std::lock_guard<std::mutex> lock(context->_mutex);
- facenet_input_s facenet_input = { { source } };
+ FacenetInput facenet_input = { { source } };
facenet_task->setInput(facenet_input);
facenet_task->perform();
- facenet_output_s &facenet_output = facenet_task->getOutput();
- mv_face_recognition_input_s face_recognition_input = { .mode = mode::REGISTER };
- face_recognition_register_input_s facenet_to_face_reg_input = { facenet_output.outputs[0], string(label) };
+ FacenetOutput &facenet_output = facenet_task->getOutput();
+ FaceRecognitionInput face_recognition_input = { .mode = mode::REGISTER };
+ FaceRecognitionRegisterInput facenet_to_face_reg_input = { facenet_output.outputs[0], string(label) };
face_recognition_input.register_src.clear();
face_recognition_input.register_src.push_back(facenet_to_face_reg_input);
std::lock_guard<std::mutex> lock(context->_mutex);
- mv_face_recognition_input_s input = { mode::DELETE };
+ FaceRecognitionInput input = { mode::DELETE };
input.labels.clear();
input.labels.push_back(string(label));
std::lock_guard<std::mutex> lock(context->_mutex);
- facenet_input_s facenet_input = { { source } };
+ FacenetInput facenet_input = { { source } };
facenet_task->setInput(facenet_input);
facenet_task->perform();
- facenet_output_s &facenet_output = facenet_task->getOutput();
+ FacenetOutput &facenet_output = facenet_task->getOutput();
- mv_face_recognition_input_s face_recognition_input = { mode::INFERENCE };
+ FaceRecognitionInput face_recognition_input = { mode::INFERENCE };
face_recognition_input.inputs = facenet_output.outputs;
face_recognition_task->setInput(face_recognition_input);
_training->DestroyModel(_model.get());
}
-void SimpleShot::ConfigureModel(int num_of_class)
+void SimpleShot::configureModel(int num_of_class)
{
// TODO. Check the capacity.
throw InvalidOperation("Fail to add knn layer.");
}
-TrainingEngineBackendInfo &SimpleShot::GetTrainingEngineInfo()
+TrainingEngineBackendInfo &SimpleShot::getTrainingEngineInfo()
{
return _engine_info;
}
-void SimpleShot::SaveModel(const string file_path)
+void SimpleShot::saveModel(const string file_path)
{
string bin_file_path = file_path.substr(0, file_path.find('.')) + ".bin";
int ret = 0;
// NNStreamer returns an error if internal model file(ini and bin files) exists before generating it.
// So remove existing files.
- if (FaceRecogUtil::IsFileExist(bin_file_path)) {
+ if (FaceRecogUtil::isFileExist(bin_file_path)) {
ret = ::remove(bin_file_path.c_str());
if (ret)
throw InvalidOperation("Fail to remove internal model file.");
}
- if (FaceRecogUtil::IsFileExist(file_path)) {
+ if (FaceRecogUtil::isFileExist(file_path)) {
ret = ::remove(file_path.c_str());
if (ret)
throw InvalidOperation("Fail to remove internal model file.");
throw InvalidOperation("Fail to save a model.");
}
-void SimpleShot::RemoveModel(const string file_path)
+void SimpleShot::removeModel(const string file_path)
{
string bin_file_path = file_path.substr(0, file_path.find('.')) + ".bin";
int ret = 0;
// Remove existing files forcely.
- if (FaceRecogUtil::IsFileExist(bin_file_path)) {
+ if (FaceRecogUtil::isFileExist(bin_file_path)) {
ret = ::remove(bin_file_path.c_str());
if (ret)
throw InvalidOperation("Fail to remove internal model file.");
}
- if (FaceRecogUtil::IsFileExist(file_path)) {
+ if (FaceRecogUtil::isFileExist(file_path)) {
ret = ::remove(file_path.c_str());
if (ret)
throw InvalidOperation("Fail to remove internal model file.");
void prepare();
void preprocess(mv_source_h &mv_src);
void inference(mv_source_h source);
- virtual image_classification_result_s &result() = 0;
+ virtual ImageClassificationResult &result() = 0;
};
} // machine_learning
class ImageClassificationDefault : public ImageClassification
{
private:
- image_classification_result_s _result;
+ ImageClassificationResult _result;
public:
ImageClassificationDefault();
~ImageClassificationDefault();
- image_classification_result_s &result() override;
+ ImageClassificationResult &result() override;
};
} // machine_learning
{
namespace machine_learning
{
-struct image_classification_input_s {
+struct ImageClassificationInput {
mv_source_h inference_src;
std::string model_file;
std::string meta_file;
* @brief The object detection result structure.
* @details Contains object detection 3d result.
*/
-struct image_classification_result_s {
+struct ImageClassificationResult {
std::string label;
};
-enum class image_classification_task_type_e {
+enum class ImageClassificationTaskType {
IMAGE_CLASSIFICATION_TASK_NONE = 0,
// TODO
};
void ImageClassification::configure()
{
- int ret = _inference->Bind(_backendType, _targetDeviceType);
+ int ret = _inference->bind(_backendType, _targetDeviceType);
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to bind a backend engine.");
}
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to configure output tensor info from meta file.");
- _inference->ConfigureModelFiles("", _modelFilePath, "");
+ _inference->configureModelFiles("", _modelFilePath, "");
// Request to load model files to a backend engine.
- ret = _inference->Load();
+ ret = _inference->load();
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to load model files.");
}
sources.push_back(source);
- int ret = _inference->Run();
+ int ret = _inference->run();
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to run inference");
void ImageClassification::getOutputNames(vector<string> &names)
{
- TensorBuffer &tensor_buffer_obj = _inference->GetOutputTensorBuffer();
+ TensorBuffer &tensor_buffer_obj = _inference->getOutputTensorBuffer();
IETensorBuffer &ie_tensor_buffer = tensor_buffer_obj.getIETensorBuffer();
for (IETensorBuffer::iterator it = ie_tensor_buffer.begin(); it != ie_tensor_buffer.end(); it++)
{
LOGI("ENTER");
- TensorBuffer &tensor_buffer_obj = _inference->GetOutputTensorBuffer();
+ TensorBuffer &tensor_buffer_obj = _inference->getOutputTensorBuffer();
inference_engine_tensor_buffer *tensor_buffer = tensor_buffer_obj.getTensorBuffer(target_name);
if (!tensor_buffer)
return _image_classification->result();
}
-template class ImageClassificationAdapter<image_classification_input_s, image_classification_result_s>;
+template class ImageClassificationAdapter<ImageClassificationInput, ImageClassificationResult>;
}
}
\ No newline at end of file
ImageClassificationDefault::~ImageClassificationDefault()
{}
-image_classification_result_s &ImageClassificationDefault::result()
+ImageClassificationResult &ImageClassificationDefault::result()
{
vector<string> names;
using namespace mediavision::machine_learning;
using namespace MediaVision::Common;
using namespace mediavision::machine_learning::exception;
-using ImageClassificationTask = ITask<image_classification_input_s, image_classification_result_s>;
+using ImageClassificationTask = ITask<ImageClassificationInput, ImageClassificationResult>;
int mv_image_classification_set_model_open(mv_image_classification_h handle, const char *model_file,
const char *meta_file, const char *label_file)
auto context = static_cast<Context *>(handle);
auto task = static_cast<ImageClassificationTask *>(context->__tasks.at("image_classification"));
- image_classification_input_s input;
+ ImageClassificationInput input;
input.model_file = string(model_file);
input.meta_file = string(meta_file);
try {
context = new Context();
- task = new ImageClassificationAdapter<image_classification_input_s, image_classification_result_s>();
+ task = new ImageClassificationAdapter<ImageClassificationInput, ImageClassificationResult>();
context->__tasks.insert(make_pair("image_classification", task));
*out_handle = static_cast<mv_image_classification_h>(context);
auto context = static_cast<Context *>(handle);
auto task = static_cast<ImageClassificationTask *>(context->__tasks.at("image_classification"));
- image_classification_input_s input = { source };
+ ImageClassificationInput input = { source };
task->setInput(input);
task->perform();
auto context = static_cast<Context *>(handle);
auto task = static_cast<ImageClassificationTask *>(context->__tasks.at("image_classification"));
- image_classification_result_s &result = task->getOutput();
+ ImageClassificationResult &result = task->getOutput();
*out_label = result.label.c_str();
} catch (const BaseException &e) {
*
* @since_tizen 5.5
*/
- void ConfigureModelFiles(const std::string modelConfigFilePath, const std::string modelWeightFilePath,
+ void configureModelFiles(const std::string modelConfigFilePath, const std::string modelWeightFilePath,
const std::string modelUserFilePath);
/**
*
* @since_tizen 6.0
*/
- int ConfigureInputInfo(int width, int height, int dim, int ch, double stdValue, double meanValue, int dataType,
+ int configureInputInfo(int width, int height, int dim, int ch, double stdValue, double meanValue, int dataType,
const std::vector<std::string> names);
- int ConfigureOutputInfo(std::vector<std::string> names, std::vector<inference_engine_tensor_info> &tensors_info);
+ int configureOutputInfo(std::vector<std::string> names, std::vector<inference_engine_tensor_info> &tensors_info);
/**
* @brief Configure input information from model meta file.
*
* @since_tizen 6.0
*/
- int ConfigureTargetDevices(const int targetDevices);
+ int configureTargetDevices(const int targetDevices);
/**
* @brief Configure the maximum number of inference results
*
* @since_tizen 5.5
*/
- void ConfigureOutput(const int maxOutputNumbers);
+ void configureOutput(const int maxOutputNumbers);
/**
* @brief Configure the confidence threshold
*
* @since_tizen 5.5
*/
- void ConfigureThreshold(const double threshold);
+ void configureThreshold(const double threshold);
/**
* @brief Parses the metadata file path
*
* @since_tizen 6.5
*/
- int ParseMetadata(const std::string filePath);
+ int parseMetadata(const std::string filePath);
/**
* @brief Bind a backend engine
* @retval #MEDIA_VISION_ERROR_NONE Successful
* @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
*/
- int Bind(int backend_type, int device_type);
+ int bind(int backend_type, int device_type);
/**
* @brief Load model files
* @retval #MEDIA_VISION_ERROR_NONE Successful
* @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
*/
- int Load();
+ int load();
/**
* @brief Runs inference with a region of a given image
* @since_tizen 5.5
* @return @c true on success, otherwise a negative error value
*/
- int Run(std::vector<mv_source_h> &mvSources, std::vector<mv_rectangle_s> &rects);
+ int run(std::vector<mv_source_h> &mvSources, std::vector<mv_rectangle_s> &rects);
- int Run(std::vector<std::vector<float> > &input_tensors);
+ int run(std::vector<std::vector<float> > &input_tensors);
- int Run();
+ int run();
/**
* @brief Gets that given engine is supported or not
* @since_tizen 5.5
* @return @c true on success, otherwise a negative error value
*/
- std::pair<std::string, bool> GetSupportedInferenceBackend(int backend);
+ std::pair<std::string, bool> getSupportedInferenceBackend(int backend);
/**
* @brief Gets the ImageClassificationResults
* @since_tizen 5.5
* @return @c true on success, otherwise a negative error value
*/
- int GetClassficationResults(ImageClassificationResults *results);
+ int getClassficationResults(ImageClassificationResults *results);
/**
* @brief Gets the ObjectDetectioResults
* @since_tizen 5.5
* @return @c true on success, otherwise a negative error value
*/
- int GetObjectDetectionResults(ObjectDetectionResults *results);
+ int getObjectDetectionResults(ObjectDetectionResults *results);
/**
* @brief Gets the FaceDetectioResults
* @since_tizen 5.5
* @return @c true on success, otherwise a negative error value
*/
- int GetFaceDetectionResults(FaceDetectionResults *results);
+ int getFaceDetectionResults(FaceDetectionResults *results);
/**
* @brief Gets the FacialLandmarkDetectionResults
* @since_tizen 5.5
* @return @c true on success, otherwise a negative error value
*/
- int GetFacialLandMarkDetectionResults(FacialLandMarkDetectionResults *results);
+ int getFacialLandMarkDetectionResults(FacialLandMarkDetectionResults *results);
/**
* @brief Gets the PoseLandmarkDetectionResults
* @since_tizen 6.0
* @return @c true on success, otherwise a negative error value
*/
- int GetPoseLandmarkDetectionResults(std::unique_ptr<mv_inference_pose_s> &detectionResults, int width, int height);
+ int getPoseLandmarkDetectionResults(std::unique_ptr<mv_inference_pose_s> &detectionResults, int width, int height);
- mv_engine_config_h GetEngineConfig(void)
+ mv_engine_config_h getEngineConfig(void)
{
return engine_config;
}
- void SetEngineConfig(mv_engine_config_h config)
+ void setEngineConfig(mv_engine_config_h config)
{
engine_config = config;
}
- int GetTargetType()
+ int getTargetType()
{
return mConfig.mTargetTypes;
}
- TensorBuffer &GetOutputTensorBuffer()
+ TensorBuffer &getOutputTensorBuffer()
{
return mOutputTensorBuffers;
}
private:
int setInputInfo();
int setOutputInfo(inference_engine_layer_property &property);
- void CheckSupportedInferenceBackend();
- int CheckBackendType(const mv_inference_backend_type_e backendType);
- bool IsTargetDeviceSupported(const int targetDevices);
- int ConvertEngineErrorToVisionError(int error);
- int ConvertTargetTypes(int given_types);
- int ConvertToCv(int given_type);
- int ConvertOutputDataTypeToFloat();
- int Preprocess(std::vector<mv_source_h> &mv_sources, std::vector<cv::Mat> &cv_sources);
- inference_tensor_data_type_e ConvertToIE(int given_type);
- int PrepareTenosrBuffers(void);
- void CleanupTensorBuffers(void);
- int SetUserFile(std::string filename);
+ void checkSupportedInferenceBackend();
+ int checkBackendType(const mv_inference_backend_type_e backendType);
+ bool isTargetDeviceSupported(const int targetDevices);
+ int convertEngineErrorToVisionError(int error);
+ int convertTargetTypes(int given_types);
+ int convertToCv(int given_type);
+ int convertOutputDataTypeToFloat();
+ int preprocess(std::vector<mv_source_h> &mv_sources, std::vector<cv::Mat> &cv_sources);
+ inference_tensor_data_type_e convertToIE(int given_type);
+ int prepareTenosrBuffers(void);
+ void cleanupTensorBuffers(void);
+ int setUserFile(std::string filename);
};
} /* Inference */
{
LOGI("ENTER");
- CheckSupportedInferenceBackend();
+ checkSupportedInferenceBackend();
for (auto &backend : mSupportedInferenceBackend) {
LOGI("%s: %s", backend.second.first.c_str(), backend.second.second ? "TRUE" : "FALSE");
Inference::~Inference()
{
- CleanupTensorBuffers();
+ cleanupTensorBuffers();
if (!mInputLayerProperty.layers.empty()) {
mInputLayerProperty.layers.clear();
LOGI("Released backend engine.");
}
-void Inference::CheckSupportedInferenceBackend()
+void Inference::checkSupportedInferenceBackend()
{
LOGI("ENTER");
LOGI("LEAVE");
}
-int Inference::ConvertEngineErrorToVisionError(int error)
+int Inference::convertEngineErrorToVisionError(int error)
{
int ret = MEDIA_VISION_ERROR_NONE;
return ret;
}
-int Inference::ConvertTargetTypes(int given_types)
+int Inference::convertTargetTypes(int given_types)
{
int target_types = INFERENCE_TARGET_NONE;
return target_types;
}
-int Inference::ConvertToCv(int given_type)
+int Inference::convertToCv(int given_type)
{
int type = 0;
const int ch = mConfig.mTensorInfo.ch;
return type;
}
-inference_tensor_data_type_e Inference::ConvertToIE(int given_type)
+inference_tensor_data_type_e Inference::convertToIE(int given_type)
{
inference_tensor_data_type_e type = INFERENCE_TENSOR_DATA_TYPE_FLOAT32;
return type;
}
-int Inference::SetUserFile(std::string filename)
+int Inference::setUserFile(std::string filename)
{
std::ifstream fp(filename.c_str());
if (!fp.is_open()) {
return MEDIA_VISION_ERROR_NONE;
}
-void Inference::ConfigureModelFiles(const std::string modelConfigFilePath, const std::string modelWeightFilePath,
+void Inference::configureModelFiles(const std::string modelConfigFilePath, const std::string modelWeightFilePath,
const std::string modelUserFilePath)
{
LOGI("ENTER");
LOGI("LEAVE");
}
-int Inference::ConfigureInputInfo(int width, int height, int dim, int ch, double stdValue, double meanValue,
+int Inference::configureInputInfo(int width, int height, int dim, int ch, double stdValue, double meanValue,
int dataType, const std::vector<std::string> names)
{
LOGI("ENTER");
for (auto &name : mConfig.mInputLayerNames) {
inference_engine_tensor_info tensor_info;
- tensor_info.data_type = ConvertToIE(mConfig.mDataType);
+ tensor_info.data_type = convertToIE(mConfig.mDataType);
// In case of OpenCV, only supports NCHW
tensor_info.shape_type = INFERENCE_TENSOR_SHAPE_NCHW;
return ret;
}
-int Inference::ConfigureOutputInfo(const std::vector<std::string> names,
+int Inference::configureOutputInfo(const std::vector<std::string> names,
std::vector<inference_engine_tensor_info> &tensors_info)
{
LOGI("ENTER");
return ret;
}
-int Inference::CheckBackendType(const mv_inference_backend_type_e backendType)
+int Inference::checkBackendType(const mv_inference_backend_type_e backendType)
{
// Check if a given backend type is valid or not.
if (backendType <= MV_INFERENCE_BACKEND_NONE || backendType >= MV_INFERENCE_BACKEND_MAX) {
return MEDIA_VISION_ERROR_NONE;
}
-int Inference::ConfigureTargetDevices(const int targetDevices)
+int Inference::configureTargetDevices(const int targetDevices)
{
// Check if given target types are valid or not.
if (MV_INFERENCE_TARGET_DEVICE_NONE >= targetDevices || MV_INFERENCE_TARGET_DEVICE_MAX <= targetDevices) {
return MEDIA_VISION_ERROR_NONE;
}
-bool Inference::IsTargetDeviceSupported(const int targetDevices)
+bool Inference::isTargetDeviceSupported(const int targetDevices)
{
if (!(mBackendCapacity.supported_accel_devices & targetDevices)) {
LOGE("Backend doesn't support a given %x device acceleration.", targetDevices);
return true;
}
-void Inference::ConfigureOutput(const int maxOutputNumbers)
+void Inference::configureOutput(const int maxOutputNumbers)
{
mConfig.mMaxOutputNumbers =
std::max(std::min(maxOutputNumbers, MV_INFERENCE_OUTPUT_NUMBERS_MAX), MV_INFERENCE_OUTPUT_NUMBERS_MIN);
}
-void Inference::ConfigureThreshold(const double threshold)
+void Inference::configureThreshold(const double threshold)
{
mConfig.mConfidenceThresHold =
std::max(std::min(threshold, MV_INFERENCE_CONFIDENCE_THRESHOLD_MAX), MV_INFERENCE_CONFIDENCE_THRESHOLD_MIN);
}
-int Inference::ParseMetadata(const std::string filePath)
+int Inference::parseMetadata(const std::string filePath)
{
LOGI("ENTER");
int ret = mMetadata.Init(filePath);
return MEDIA_VISION_ERROR_NONE;
}
-void Inference::CleanupTensorBuffers(void)
+void Inference::cleanupTensorBuffers(void)
{
LOGI("ENTER");
LOGI("LEAVE");
}
-int Inference::PrepareTenosrBuffers(void)
+int Inference::prepareTenosrBuffers(void)
{
// If there are input and output tensor buffers allocated before then release the buffers.
// They will be allocated again according to a new model file to be loaded.
- CleanupTensorBuffers();
+ cleanupTensorBuffers();
// IF model file is loaded again then the model type could be different so
// clean up input and output layer properties so that they can be updated again
int ret = mBackend->GetInputTensorBuffers(inputTensorBuffers);
if (ret != INFERENCE_ENGINE_ERROR_NONE) {
LOGE("Fail to get input tensor buffers from backend engine.");
- return ConvertEngineErrorToVisionError(ret);
+ return convertEngineErrorToVisionError(ret);
}
ret = mBackend->GetInputLayerProperty(mInputLayerProperty);
if (ret != INFERENCE_ENGINE_ERROR_NONE) {
LOGE("Fail to get input layer property from backend engine.");
- return ConvertEngineErrorToVisionError(ret);
+ return convertEngineErrorToVisionError(ret);
}
// If the backend engine isn't able to allocate input tensor buffers internally,
ret = mBackend->GetOutputTensorBuffers(outputTensorBuffers);
if (ret != INFERENCE_ENGINE_ERROR_NONE) {
LOGE("Fail to get output tensor buffers from backend engine.");
- return ConvertEngineErrorToVisionError(ret);
+ return convertEngineErrorToVisionError(ret);
}
ret = mBackend->GetOutputLayerProperty(mOutputLayerProperty);
if (ret != INFERENCE_ENGINE_ERROR_NONE) {
LOGE("Fail to get output layer property from backend engine.");
- return ConvertEngineErrorToVisionError(ret);
+ return convertEngineErrorToVisionError(ret);
}
// If the backend engine isn't able to allocate output tensor buffers internally,
return MEDIA_VISION_ERROR_NONE;
}
-int Inference::ConvertOutputDataTypeToFloat()
+int Inference::convertOutputDataTypeToFloat()
{
IETensorBuffer &ieTensorBuffers = mOutputTensorBuffers.getIETensorBuffer();
return MEDIA_VISION_ERROR_NONE;
}
-int Inference::Bind(int backend_type, int device_type)
+int Inference::bind(int backend_type, int device_type)
{
LOGI("ENTER");
- int ret = CheckBackendType(static_cast<mv_inference_backend_type_e>(backend_type));
+ int ret = checkBackendType(static_cast<mv_inference_backend_type_e>(backend_type));
if (ret != MEDIA_VISION_ERROR_NONE)
return ret;
return ret;
}
- if (!IsTargetDeviceSupported(mConfig.mTargetTypes)) {
+ if (!isTargetDeviceSupported(mConfig.mTargetTypes)) {
mBackend->UnbindBackend();
LOGE("Tried to configure invalid target types.");
return MEDIA_VISION_ERROR_NOT_SUPPORTED;
return MEDIA_VISION_ERROR_NONE;
}
-int Inference::Load(void)
+int Inference::load(void)
{
LOGI("ENTER");
return MEDIA_VISION_ERROR_INVALID_PARAMETER;
}
- int ret = (userFileLength > 0) ? SetUserFile(label_file) : MEDIA_VISION_ERROR_NONE;
+ int ret = (userFileLength > 0) ? setUserFile(label_file) : MEDIA_VISION_ERROR_NONE;
if (ret != MEDIA_VISION_ERROR_NONE) {
LOGE("Fail to load label file.");
return ret;
LOGE("Fail to load model");
mCanRun = false;
std::vector<std::string>().swap(models);
- return ConvertEngineErrorToVisionError(ret);
+ return convertEngineErrorToVisionError(ret);
}
std::vector<std::string>().swap(models);
// Prepare input and output tensor buffers.
- ret = PrepareTenosrBuffers();
+ ret = prepareTenosrBuffers();
if (ret != INFERENCE_ENGINE_ERROR_NONE) {
LOGE("Fail to prepare buffer");
mCanRun = false;
LOGI("LEAVE");
- return ConvertEngineErrorToVisionError(ret);
+ return convertEngineErrorToVisionError(ret);
}
-int Inference::Preprocess(std::vector<mv_source_h> &mv_sources, std::vector<cv::Mat> &cv_sources)
+int Inference::preprocess(std::vector<mv_source_h> &mv_sources, std::vector<cv::Mat> &cv_sources)
{
unsigned int src_idx = 0;
for (auto &buffer : mInputTensorBuffers.getIETensorBuffer()) {
inference_engine_tensor_buffer &tensor_buffer = buffer.second;
- int data_type = ConvertToCv(tensor_buffer.data_type);
+ int data_type = convertToCv(tensor_buffer.data_type);
LayerInfo layerInfo;
Options opt;
mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
return MEDIA_VISION_ERROR_NONE;
}
-int Inference::Run(std::vector<mv_source_h> &mvSources, std::vector<mv_rectangle_s> &rects)
+int Inference::run(std::vector<mv_source_h> &mvSources, std::vector<mv_rectangle_s> &rects)
{
int ret = INFERENCE_ENGINE_ERROR_NONE;
// TODO. consider multiple cv sources.
mSourceSize = cvSources[0].size();
- ret = Preprocess(mvSources, cvSources);
+ ret = preprocess(mvSources, cvSources);
if (ret != MEDIA_VISION_ERROR_NONE) {
LOGE("Fail to preprocess given input sources.");
return ret;
if (ret != INFERENCE_ENGINE_ERROR_NONE)
return ret;
- return ConvertOutputDataTypeToFloat();
+ return convertOutputDataTypeToFloat();
}
-int Inference::Run(std::vector<std::vector<float> > &input_tensors)
+int Inference::run(std::vector<std::vector<float> > &input_tensors)
{
int ret = INFERENCE_ENGINE_ERROR_NONE;
if (ret != INFERENCE_ENGINE_ERROR_NONE)
return ret;
- return ConvertOutputDataTypeToFloat();
+ return convertOutputDataTypeToFloat();
}
-int Inference::Run()
+int Inference::run()
{
int ret = INFERENCE_ENGINE_ERROR_NONE;
if (ret != INFERENCE_ENGINE_ERROR_NONE)
return ret;
- return ConvertOutputDataTypeToFloat();
+ return convertOutputDataTypeToFloat();
}
-std::pair<std::string, bool> Inference::GetSupportedInferenceBackend(int backend)
+std::pair<std::string, bool> Inference::getSupportedInferenceBackend(int backend)
{
return mSupportedInferenceBackend[backend];
}
-int Inference::GetClassficationResults(ImageClassificationResults *results)
+int Inference::getClassficationResults(ImageClassificationResults *results)
{
// Will contain top N results in ascending order.
std::vector<std::pair<float, int> > topScore;
return MEDIA_VISION_ERROR_NONE;
}
-int Inference::GetObjectDetectionResults(ObjectDetectionResults *results)
+int Inference::getObjectDetectionResults(ObjectDetectionResults *results)
{
if (mMetadata.GetOutputMeta().IsParsed()) {
OutputMetadata &outputMeta = mMetadata.GetOutputMeta();
return MEDIA_VISION_ERROR_NONE;
}
-int Inference::GetFaceDetectionResults(FaceDetectionResults *results)
+int Inference::getFaceDetectionResults(FaceDetectionResults *results)
{
if (mMetadata.GetOutputMeta().IsParsed()) {
OutputMetadata &outputMeta = mMetadata.GetOutputMeta();
return MEDIA_VISION_ERROR_NONE;
}
-int Inference::GetFacialLandMarkDetectionResults(FacialLandMarkDetectionResults *results)
+int Inference::getFacialLandMarkDetectionResults(FacialLandMarkDetectionResults *results)
{
LOGI("ENTER");
return MEDIA_VISION_ERROR_NONE;
}
-int Inference::GetPoseLandmarkDetectionResults(std::unique_ptr<mv_inference_pose_s> &detectionResults, int width,
+int Inference::getPoseLandmarkDetectionResults(std::unique_ptr<mv_inference_pose_s> &detectionResults, int width,
int height)
{
LOGI("ENTER");
{
Inference *pInfer = static_cast<Inference *>(infer);
- return pInfer->GetEngineConfig();
+ return pInfer->getEngineConfig();
}
int mv_inference_create_open(mv_inference_h *infer)
goto release_model_meta_file_path;
}
- ret = pInfer->ParseMetadata(std::string(modelMetaFilePath));
+ ret = pInfer->parseMetadata(std::string(modelMetaFilePath));
if (ret != MEDIA_VISION_ERROR_NONE) {
LOGE("Fail to ParseMetadata");
}
goto release_model_user_file_path;
}
- if (IsConfigFilePathRequired(pInfer->GetTargetType(), backendType)) {
+ if (IsConfigFilePathRequired(pInfer->getTargetType(), backendType)) {
if (access(modelConfigFilePath, F_OK)) {
LOGE("modelConfigFilePath in [%s] ", modelConfigFilePath);
ret = MEDIA_VISION_ERROR_INVALID_PATH;
goto release_model_user_file_path;
}
- pInfer->ConfigureModelFiles(std::string(modelConfigFilePath), std::string(modelWeightFilePath),
+ pInfer->configureModelFiles(std::string(modelConfigFilePath), std::string(modelWeightFilePath),
std::string(modelUserFilePath));
release_model_user_file_path:
goto out_of_function;
}
- pInfer->ConfigureInputInfo(tensorWidth, tensorHeight, 1, tensorCh, stdValue, meanValue, dataType,
+ pInfer->configureInputInfo(tensorWidth, tensorHeight, 1, tensorCh, stdValue, meanValue, dataType,
std::vector<std::string>(1, std::string(node_name)));
free(node_name);
int backendType = 0;
int targetTypes = 0;
- pInfer->SetEngineConfig(engine_config);
+ pInfer->setEngineConfig(engine_config);
int ret = mv_engine_config_get_int_attribute(engine_config, MV_INFERENCE_BACKEND_TYPE, &backendType);
if (ret != MEDIA_VISION_ERROR_NONE) {
}
// Set target device type.
- if (pInfer->ConfigureTargetDevices(targetTypes) != MEDIA_VISION_ERROR_NONE) {
+ if (pInfer->configureTargetDevices(targetTypes) != MEDIA_VISION_ERROR_NONE) {
LOGE("Tried to configure invalid target types.");
goto out_of_function;
}
// Create a inference-engine-common class object and load its corresponding library.
// Ps. Inference engine gets a capability from a given backend by Bind call
// so access to mBackendCapacity should be done after Bind.
- ret = pInfer->Bind(backendType, targetTypes);
+ ret = pInfer->bind(backendType, targetTypes);
if (ret != MEDIA_VISION_ERROR_NONE) {
LOGE("Fail to bind a backend engine.");
goto out_of_function;
goto out_of_function;
}
- pInfer->ConfigureOutput(maxOutput);
+ pInfer->configureOutput(maxOutput);
out_of_function:
LOGI("LEAVE");
goto out_of_function;
}
- pInfer->ConfigureThreshold(threshold);
+ pInfer->configureThreshold(threshold);
out_of_function:
LOGI("LEAVE");
goto out_of_function;
}
- pInfer->ConfigureOutput(maxOutput);
+ pInfer->configureOutput(maxOutput);
ret = mv_engine_config_get_double_attribute(engine_config, MV_INFERENCE_CONFIDENCE_THRESHOLD, &threshold);
if (ret != MEDIA_VISION_ERROR_NONE) {
goto out_of_function;
}
- pInfer->ConfigureThreshold(threshold);
+ pInfer->configureThreshold(threshold);
out_of_function:
LOGI("LEAVE");
std::vector<inference_engine_tensor_info> tensors_info;
- pInfer->ConfigureOutputInfo(names, tensors_info);
+ pInfer->configureOutputInfo(names, tensors_info);
if (node_names) {
for (idx = 0; idx < size; ++idx)
}
// Request to load model files to a backend engine.
- ret = pInfer->Load();
+ ret = pInfer->load();
if (ret != MEDIA_VISION_ERROR_NONE)
LOGE("Fail to load model files.");
std::pair<std::string, bool> backend;
for (int i = 0; i < MV_INFERENCE_BACKEND_MAX; ++i) {
- backend = pInfer->GetSupportedInferenceBackend(i);
+ backend = pInfer->getSupportedInferenceBackend(i);
callback((backend.first).c_str(), backend.second, user_data);
}
if (roi != NULL)
rects.push_back(*roi);
- int ret = pInfer->Run(sources, rects);
+ int ret = pInfer->run(sources, rects);
if (ret != MEDIA_VISION_ERROR_NONE) {
LOGE("Fail to run inference");
return ret;
ImageClassificationResults classificationResults;
- ret = pInfer->GetClassficationResults(&classificationResults);
+ ret = pInfer->getClassficationResults(&classificationResults);
if (ret != MEDIA_VISION_ERROR_NONE) {
LOGE("Fail to get inference results");
return ret;
std::vector<mv_rectangle_s> rects;
sources.push_back(source);
- int ret = pInfer->Run(sources, rects);
+ int ret = pInfer->run(sources, rects);
if (ret != MEDIA_VISION_ERROR_NONE) {
LOGE("Fail to run inference");
return ret;
ObjectDetectionResults objectDetectionResults;
- ret = pInfer->GetObjectDetectionResults(&objectDetectionResults);
+ ret = pInfer->getObjectDetectionResults(&objectDetectionResults);
if (ret != MEDIA_VISION_ERROR_NONE) {
LOGE("Fail to get inference results");
return ret;
sources.push_back(source);
- int ret = pInfer->Run(sources, rects);
+ int ret = pInfer->run(sources, rects);
if (ret != MEDIA_VISION_ERROR_NONE) {
LOGE("Fail to run inference");
return ret;
FaceDetectionResults faceDetectionResults;
- ret = pInfer->GetFaceDetectionResults(&faceDetectionResults);
+ ret = pInfer->getFaceDetectionResults(&faceDetectionResults);
if (ret != MEDIA_VISION_ERROR_NONE) {
LOGE("Fail to get inference results");
return ret;
if (roi != NULL)
rects.push_back(*roi);
- int ret = pInfer->Run(sources, rects);
+ int ret = pInfer->run(sources, rects);
if (ret != MEDIA_VISION_ERROR_NONE) {
LOGE("Fail to run inference");
return ret;
FacialLandMarkDetectionResults facialLandMarkDetectionResults;
- ret = pInfer->GetFacialLandMarkDetectionResults(&facialLandMarkDetectionResults);
+ ret = pInfer->getFacialLandMarkDetectionResults(&facialLandMarkDetectionResults);
if (ret != MEDIA_VISION_ERROR_NONE) {
LOGE("Fail to get inference results");
return ret;
if (roi != NULL)
rects.push_back(*roi);
- ret = pInfer->Run(sources, rects);
+ ret = pInfer->run(sources, rects);
if (ret != MEDIA_VISION_ERROR_NONE) {
LOGE("Fail to run inference");
return ret;
std::unique_ptr<mv_inference_pose_s> pose;
- ret = pInfer->GetPoseLandmarkDetectionResults(pose, width, height);
+ ret = pInfer->getPoseLandmarkDetectionResults(pose, width, height);
if (ret != MEDIA_VISION_ERROR_NONE) {
LOGE("Fail to get inference results");
return ret;
void ObjectDetection::configure()
{
- int ret = _inference->Bind(_backendType, _targetDeviceType);
+ int ret = _inference->bind(_backendType, _targetDeviceType);
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to bind a backend engine.");
}
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to configure output tensor info from meta file.");
- _inference->ConfigureModelFiles("", _modelFilePath, "");
+ _inference->configureModelFiles("", _modelFilePath, "");
// Request to load model files to a backend engine.
- ret = _inference->Load();
+ ret = _inference->load();
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to load model files.");
}
sources.push_back(source);
- int ret = _inference->Run();
+ int ret = _inference->run();
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to run inference");
void ObjectDetection::getOutputNames(vector<string> &names)
{
- TensorBuffer &tensor_buffer_obj = _inference->GetOutputTensorBuffer();
+ TensorBuffer &tensor_buffer_obj = _inference->getOutputTensorBuffer();
IETensorBuffer &ie_tensor_buffer = tensor_buffer_obj.getIETensorBuffer();
for (IETensorBuffer::iterator it = ie_tensor_buffer.begin(); it != ie_tensor_buffer.end(); it++)
{
LOGI("ENTER");
- TensorBuffer &tensor_buffer_obj = _inference->GetOutputTensorBuffer();
+ TensorBuffer &tensor_buffer_obj = _inference->getOutputTensorBuffer();
inference_engine_tensor_buffer *tensor_buffer = tensor_buffer_obj.getTensorBuffer(target_name);
if (!tensor_buffer)
DataAugment();
virtual ~DataAugment();
- virtual void Preprocess(std::vector<float> &in_vec, std::vector<float> &out_vec, int width, int height) = 0;
+ virtual void preprocess(std::vector<float> &in_vec, std::vector<float> &out_vec, int width, int height) = 0;
};
#endif
\ No newline at end of file
DataAugmentDefault();
~DataAugmentDefault();
- void Preprocess(std::vector<float> &in_vec, std::vector<float> &out_vec, int width, int height) final;
+ void preprocess(std::vector<float> &in_vec, std::vector<float> &out_vec, int width, int height) final;
};
#endif
\ No newline at end of file
DataAugmentFlip();
~DataAugmentFlip();
- void Preprocess(std::vector<float> &in_vec, std::vector<float> &out_vec, int width, int height) final;
+ void preprocess(std::vector<float> &in_vec, std::vector<float> &out_vec, int width, int height) final;
};
#endif
\ No newline at end of file
DataAugmentRotate(unsigned int degree = 90);
~DataAugmentRotate();
- void Preprocess(std::vector<float> &in_vec, std::vector<float> &out_vec, int width, int height) final;
+ void preprocess(std::vector<float> &in_vec, std::vector<float> &out_vec, int width, int height) final;
};
#endif
\ No newline at end of file
DataSetManager();
virtual ~DataSetManager();
- void Clear();
- bool IsFeatureVectorDuplicated(const std::vector<float> &vec);
- std::vector<std::vector<float> > &GetData(void);
- std::vector<std::vector<float> > &GetLabel(void);
- size_t GetFeaVecSize(void);
- std::vector<unsigned int> &GetLabelIdx(void);
-
- virtual bool IsFeatureVectorAllowed(unsigned int label_idx) = 0;
- virtual void LoadDataSet(const std::string file_name, unsigned int new_label_cnt) = 0;
- virtual void AddDataSet(std::vector<float> &feature_vec, const unsigned int label_idx,
+ void clear();
+ bool isFeatureVectorDuplicated(const std::vector<float> &vec);
+ std::vector<std::vector<float> > &getData(void);
+ std::vector<std::vector<float> > &getLabel(void);
+ size_t getFeaVecSize(void);
+ std::vector<unsigned int> &getLabelIdx(void);
+
+ virtual bool isFeatureVectorAllowed(unsigned int label_idx) = 0;
+ virtual void loadDataSet(const std::string file_name, unsigned int new_label_cnt) = 0;
+ virtual void addDataSet(std::vector<float> &feature_vec, const unsigned int label_idx,
const unsigned int label_cnt) = 0;
};
FeatureVectorManager(const std::string feature_vector_file = "feature_vector_file.dat");
virtual ~FeatureVectorManager() = default;
- const std::string &GetFileName();
+ const std::string &getFileName();
- static void GetVecFromImg(const std::string image_file, std::vector<float> &vec, unsigned int width,
+ static void getVecFromImg(const std::string image_file, std::vector<float> &vec, unsigned int width,
unsigned int height);
- static void GetVecFromRGB(unsigned char *in_data, std::vector<float> &vec, unsigned int width, unsigned int height,
+ static void getVecFromRGB(unsigned char *in_data, std::vector<float> &vec, unsigned int width, unsigned int height,
size_t re_width, size_t re_height);
- static void GetVecFromXRGB(unsigned char *in_data, std::vector<float> &vec, unsigned int in_width,
+ static void getVecFromXRGB(unsigned char *in_data, std::vector<float> &vec, unsigned int in_width,
unsigned int in_height, unsigned int re_width, unsigned int re_height);
- virtual void WriteHeader(size_t feature_size, size_t label_cnt, unsigned int data_set_cnt) = 0;
- virtual void StoreData(std::vector<std::vector<float> > &features_vec, std::vector<unsigned int> &label_index) = 0;
- virtual void Remove() = 0;
+ virtual void writeHeader(size_t feature_size, size_t label_cnt, unsigned int data_set_cnt) = 0;
+ virtual void storeData(std::vector<std::vector<float> > &features_vec, std::vector<unsigned int> &label_index) = 0;
+ virtual void remove() = 0;
static constexpr unsigned int feature_vector_signature = 0xFEA09841;
};
namespace FaceRecogUtil
{
-bool IsFileExist(const std::string file_path);
-bool IsImageFile(const std::string image_file);
+bool isFileExist(const std::string file_path);
+bool isImageFile(const std::string image_file);
}
#endif
\ No newline at end of file
public:
LabelManager(std::string label_file, double decision_threshold);
~LabelManager();
- void Clear();
- float GetDecisionThreshold();
- float GetDecisionWeight();
- unsigned int GetLabelIndex(const std::string given_label);
- bool IsExist(const std::string given_label);
- unsigned int RemoveLabel(const std::string given_label);
- int GetLabelString(std::string &label, const int idx);
- unsigned int AddLabelToFile(std::string given_label);
- int ImportLabel(void);
- bool AddLabelToMap(const std::string given_label, const std::string image_file);
- size_t GetMaxLabel(const std::string label_file);
- size_t GetMaxLabel();
- std::string GetLabelFromAnswer(const std::vector<float> &result);
- void Remove();
+ void clear();
+ float getDecisionThreshold();
+ float getDecisionWeight();
+ unsigned int getLabelIndex(const std::string given_label);
+ bool isExist(const std::string given_label);
+ unsigned int removeLabel(const std::string given_label);
+ int getLabelString(std::string &label, const int idx);
+ unsigned int addLabelToFile(std::string given_label);
+ int importLabel(void);
+ bool addLabelToMap(const std::string given_label, const std::string image_file);
+ size_t getMaxLabel(const std::string label_file);
+ size_t getMaxLabel();
+ std::string getLabelFromAnswer(const std::vector<float> &result);
+ void removeFile();
};
#endif
#include "data_set_manager.h"
#include "feature_vector_manager.h"
-typedef struct {
+struct TrainingEngineBackendInfo {
std::vector<std::string> input_layer_names;
std::vector<std::string> output_layer_names;
std::vector<inference_engine_tensor_info> input_tensor_info;
std::vector<inference_engine_tensor_info> output_tensor_info;
training_engine_optimizer_property optimizer_property;
training_engine_compile_property compile_property;
-} TrainingEngineBackendInfo;
+};
class TrainingModel
{
private:
- virtual void SaveModel(const std::string file_path) = 0;
- virtual void RemoveModel(const std::string file_path) = 0;
+ virtual void saveModel(const std::string file_path) = 0;
+ virtual void removeModel(const std::string file_path) = 0;
protected:
std::unique_ptr<TrainingEngineInterface::Common::TrainingEngineCommon> _training;
const std::vector<size_t> input_tensor_shape, const std::string internal_model_file);
virtual ~TrainingModel();
- void ApplyDataSet(std::unique_ptr<DataSetManager> &data_set);
- void ClearDataSet(std::unique_ptr<DataSetManager> &data_set);
- void Compile();
- void Train();
- void RemoveModel();
+ void applyDataSet(std::unique_ptr<DataSetManager> &data_set);
+ void clearDataSet(std::unique_ptr<DataSetManager> &data_set);
+ void compile();
+ void train();
+ void removeModel();
void getWeights(float **weights, size_t *size, std::string name);
- virtual void ConfigureModel(int num_of_class) = 0;
- virtual TrainingEngineBackendInfo &GetTrainingEngineInfo() = 0;
+ virtual void configureModel(int num_of_class) = 0;
+ virtual TrainingEngineBackendInfo &getTrainingEngineInfo() = 0;
};
#endif
\ No newline at end of file
DataAugmentDefault::~DataAugmentDefault()
{}
-void DataAugmentDefault::Preprocess(vector<float> &in_vec, vector<float> &out_vec, int width, int height)
+void DataAugmentDefault::preprocess(vector<float> &in_vec, vector<float> &out_vec, int width, int height)
{
cv::Mat cvSrc = cv::Mat(cv::Size(width, height), CV_32FC3, in_vec.data()).clone();
DataAugmentFlip::~DataAugmentFlip()
{}
-void DataAugmentFlip::Preprocess(vector<float> &in_vec, vector<float> &out_vec, int width, int height)
+void DataAugmentFlip::preprocess(vector<float> &in_vec, vector<float> &out_vec, int width, int height)
{
cv::Mat cvSrc = cv::Mat(cv::Size(width, height), CV_32FC3, in_vec.data()).clone();
DataAugmentRotate::~DataAugmentRotate()
{}
-void DataAugmentRotate::Preprocess(vector<float> &in_vec, vector<float> &out_vec, int width, int height)
+void DataAugmentRotate::preprocess(vector<float> &in_vec, vector<float> &out_vec, int width, int height)
{
cv::Mat cvSrc = cv::Mat(cv::Size(width, height), CV_32FC3, in_vec.data()).clone();
DataSetManager::~DataSetManager()
{
- Clear();
+ clear();
}
-void DataSetManager::Clear()
+void DataSetManager::clear()
{
for (auto &data : _data)
data.clear();
_fv_cnt_per_label.clear();
}
-bool DataSetManager::IsFeatureVectorDuplicated(const vector<float> &vec)
+bool DataSetManager::isFeatureVectorDuplicated(const vector<float> &vec)
{
if (_data.empty())
return false;
return false;
}
-vector<vector<float> > &DataSetManager::GetData(void)
+vector<vector<float> > &DataSetManager::getData(void)
{
return _data;
}
-vector<vector<float> > &DataSetManager::GetLabel(void)
+vector<vector<float> > &DataSetManager::getLabel(void)
{
return _labels;
}
-size_t DataSetManager::GetFeaVecSize(void)
+size_t DataSetManager::getFeaVecSize(void)
{
return _feature_vector_size;
}
-vector<unsigned int> &DataSetManager::GetLabelIdx(void)
+vector<unsigned int> &DataSetManager::getLabelIdx(void)
{
return _label_index;
}
\ No newline at end of file
FeatureVectorManager::FeatureVectorManager(const string feature_vector_file) : _feature_vector_file(feature_vector_file)
{}
-const string &FeatureVectorManager::GetFileName()
+const string &FeatureVectorManager::getFileName()
{
return _feature_vector_file;
}
-void FeatureVectorManager::GetVecFromImg(const string image_file, vector<float> &vec, unsigned int width,
+void FeatureVectorManager::getVecFromImg(const string image_file, vector<float> &vec, unsigned int width,
unsigned int height)
{
cv::Mat src, dst;
- if (!FaceRecogUtil::IsImageFile(image_file))
+ if (!FaceRecogUtil::isImageFile(image_file))
throw InvalidOperation("Invalid image file.");
src = cv::imread(image_file);
vec.assign((float *) dst.data, (float *) dst.data + dst.total() * dst.channels());
}
-void FeatureVectorManager::GetVecFromRGB(unsigned char *in_data, vector<float> &vec, unsigned int width,
+void FeatureVectorManager::getVecFromRGB(unsigned char *in_data, vector<float> &vec, unsigned int width,
unsigned int height, size_t re_width, size_t re_height)
{
cv::Mat cvSrc = cv::Mat(cv::Size(width, height), CV_MAKETYPE(CV_8U, 3), in_data).clone();
vec.assign((float *) dst.data, (float *) dst.data + dst.total() * dst.channels());
}
-void FeatureVectorManager::GetVecFromXRGB(unsigned char *in_data, vector<float> &vec, unsigned int in_width,
+void FeatureVectorManager::getVecFromXRGB(unsigned char *in_data, vector<float> &vec, unsigned int in_width,
unsigned int in_height, unsigned int re_width, unsigned int re_height)
{
cv::Mat argb(cv::Size(in_width, in_height), CV_8UC4, in_data);
namespace FaceRecogUtil
{
-bool IsFileExist(const std::string file_path)
+bool isFileExist(const std::string file_path)
{
struct stat fileStat;
return true;
}
-bool IsImageFile(const std::string image_file)
+bool isImageFile(const std::string image_file)
{
size_t size = image_file.size();
LabelManager::~LabelManager()
{}
-void LabelManager::Clear()
+void LabelManager::clear()
{
_labels_and_files.clear();
}
-float LabelManager::GetDecisionThreshold()
+float LabelManager::getDecisionThreshold()
{
return _decision_threshold;
}
-float LabelManager::GetDecisionWeight()
+float LabelManager::getDecisionWeight()
{
return _decision_weight;
}
-unsigned int LabelManager::GetLabelIndex(const string given_label)
+unsigned int LabelManager::getLabelIndex(const string given_label)
{
ifstream readFile;
throw InvalidOperation("Label index not found.");
}
-bool LabelManager::IsExist(const string given_label)
+bool LabelManager::isExist(const string given_label)
{
ifstream readFile;
return false;
}
-unsigned int LabelManager::RemoveLabel(const string given_label)
+unsigned int LabelManager::removeLabel(const string given_label)
{
ifstream readFile;
return label_index;
}
-int LabelManager::GetLabelString(string &label, const int idx)
+int LabelManager::getLabelString(string &label, const int idx)
{
ifstream readFile;
return ret;
}
-unsigned int LabelManager::AddLabelToFile(string given_label)
+unsigned int LabelManager::addLabelToFile(string given_label)
{
ofstream writeFile;
writeFile.write(given_label.c_str(), given_label.size());
writeFile.close();
- return GetMaxLabel(_label_file);
+ return getMaxLabel(_label_file);
}
-int LabelManager::ImportLabel(void)
+int LabelManager::importLabel(void)
{
// label count is 0 if lael file doesn't exist.
- if (!FaceRecogUtil::IsFileExist(_label_file))
+ if (!FaceRecogUtil::isFileExist(_label_file))
return 0;
ifstream readFile;
string line;
while (getline(readFile, line)) {
- bool duplicated = AddLabelToMap(line, line);
+ bool duplicated = addLabelToMap(line, line);
if (duplicated)
continue;
return label_cnt;
}
-bool LabelManager::AddLabelToMap(const string given_label, const string image_file)
+bool LabelManager::addLabelToMap(const string given_label, const string image_file)
{
// Find same one if not empty. If same one exists in the map then skip.
if (!_labels_and_files.empty()) {
return false;
}
-size_t LabelManager::GetMaxLabel(const string label_file)
+size_t LabelManager::getMaxLabel(const string label_file)
{
// label count is 0 if lael file doesn't exist.
- if (!FaceRecogUtil::IsFileExist(label_file))
+ if (!FaceRecogUtil::isFileExist(label_file))
return 0;
ifstream readFile;
return label_cnt;
}
-size_t LabelManager::GetMaxLabel()
+size_t LabelManager::getMaxLabel()
{
- return GetMaxLabel(_label_file);
+ return getMaxLabel(_label_file);
}
-string LabelManager::GetLabelFromAnswer(const vector<float> &result)
+string LabelManager::getLabelFromAnswer(const vector<float> &result)
{
if (result.empty())
throw InvalidParameter("result vector is empty.");
string answer_label;
- int ret = GetLabelString(answer_label, answer_idx);
+ int ret = getLabelString(answer_label, answer_idx);
if (ret)
throw InvalidOperation("answer label not found.");
return answer_label;
}
-void LabelManager::Remove()
+void LabelManager::removeFile()
{
// Remove existing files forcely.
int ret = ::remove(_label_file.c_str());
_training->UnbindBackend();
}
-void TrainingModel::ApplyDataSet(unique_ptr<DataSetManager> &data_set)
+void TrainingModel::applyDataSet(unique_ptr<DataSetManager> &data_set)
{
- auto &values = data_set->GetData();
- auto &labels = data_set->GetLabel();
+ auto &values = data_set->getData();
+ auto &labels = data_set->getLabel();
LOGD("Generating feature vectors for training");
throw InvalidOperation("Fail to set dataset to model.", ret);
}
-void TrainingModel::ClearDataSet(unique_ptr<DataSetManager> &data_set)
+void TrainingModel::clearDataSet(unique_ptr<DataSetManager> &data_set)
{
- data_set->Clear();
+ data_set->clear();
_training->DestroyDataset(_data_set.get());
}
-void TrainingModel::Compile()
+void TrainingModel::compile()
{
auto optimizer = _training->CreateOptimizer(TRAINING_OPTIMIZER_TYPE_SGD);
if (!optimizer)
throw InvalidOperation("Fail to create a optimizer.");
- int ret = _training->SetOptimizerProperty(optimizer.get(), GetTrainingEngineInfo().optimizer_property);
+ int ret = _training->SetOptimizerProperty(optimizer.get(), getTrainingEngineInfo().optimizer_property);
if (ret != TRAINING_ENGINE_ERROR_NONE)
throw InvalidOperation("Fail to set optimizer property.", ret);
if (ret != TRAINING_ENGINE_ERROR_NONE)
throw InvalidOperation("Fail to add optimizer to model.", ret);
- ret = _training->CompileModel(_model.get(), GetTrainingEngineInfo().compile_property);
+ ret = _training->CompileModel(_model.get(), getTrainingEngineInfo().compile_property);
if (ret != TRAINING_ENGINE_ERROR_NONE)
throw InvalidOperation("Fail to compile model.", ret);
}
-void TrainingModel::Train()
+void TrainingModel::train()
{
training_engine_model_property model_property;
int ret = _training->TrainModel(_model.get(), model_property);
throw InvalidOperation("Fail to train model.", ret);
// Save model file.
- SaveModel(_internal_model_file);
+ saveModel(_internal_model_file);
}
void TrainingModel::getWeights(float **weights, size_t *size, std::string name)
// TODO.
}
-void TrainingModel::RemoveModel()
+void TrainingModel::removeModel()
{
- RemoveModel(_internal_model_file);
+ removeModel(_internal_model_file);
}
\ No newline at end of file