mv_machine_learning: small optimization in FaceRecognition 76/304676/6
authorVibhav Aggarwal <v.aggarwal@samsung.com>
Tue, 23 Jan 2024 04:13:18 +0000 (13:13 +0900)
committerVibhav Aggarwal <v.aggarwal@samsung.com>
Fri, 26 Jan 2024 02:10:18 +0000 (02:10 +0000)
[Issue type] code optimization

Change-Id: I1f2967ddf6137c4eef62fa71ed48ba895b89d90e
Signed-off-by: Vibhav Aggarwal <v.aggarwal@samsung.com>
mv_machine_learning/face_recognition/include/Facenet.h
mv_machine_learning/face_recognition/src/Facenet.cpp
mv_machine_learning/face_recognition/src/mv_face_recognition.cpp

index a154f51b4159d9d4928e70917419ebfc83d04dd1..c9d0ac30cd14f82b78787fcabab6df3a6684f6e2 100644 (file)
@@ -47,7 +47,6 @@ protected:
        std::unique_ptr<mediavision::inference::Inference> _inference;
        std::unique_ptr<MediaVision::Common::EngineConfig> _config;
        std::unique_ptr<MetaParser> _parser;
-       FacenetOutput _result;
        inference_engine_tensor_buffer *_outputTensorBuffer {};
        Preprocess _preprocess;
        std::string _modelFileName;
index 752a4729605a9c24408b7b626a5c597774ac3576..5b1c48e6ddbb099267e8fc27103374657af1490e 100644 (file)
@@ -185,9 +185,10 @@ FacenetOutput &Facenet::result()
 {
        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
+       // 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.
-       _result.outputs.clear();
+       static FacenetOutput result;
+       result.outputs.clear();
 
        _outputTensorBuffer = tensor_buffer_obj.getTensorBuffer(_facenetOutputTensorName);
        if (!_outputTensorBuffer)
@@ -195,9 +196,9 @@ FacenetOutput &Facenet::result()
 
        float *buffer = reinterpret_cast<float *>(_outputTensorBuffer->buffer);
 
-       _result.outputs.push_back(vector<float>(buffer, buffer + _outputTensorBuffer->size / sizeof(float)));
+       result.outputs.push_back(vector<float>(buffer, buffer + _outputTensorBuffer->size / sizeof(float)));
 
-       return _result;
+       return result;
 }
 
 template void Facenet::preprocess<float>(mv_source_h &mv_src, shared_ptr<MetaInfo> metaInfo,
index b9f2e4ea95feedefd9dfcf9cd0f0647d2e8c7564..33341f15e0e6b8a055198ae045cc4c31fb39218a 100644 (file)
@@ -139,7 +139,7 @@ int mv_face_recognition_register(mv_face_recognition_h handle, mv_source_h sourc
                FaceRecognitionInput face_recognition_input;
 
                face_recognition_input.mode = RequestMode::REGISTER;
-               face_recognition_input.inputs.push_back(facenet_output.outputs[0]);
+               face_recognition_input.inputs.push_back(move(facenet_output.outputs[0]));
                face_recognition_input.labels.push_back(label);
                machine_learning_native_inference(handle, "face_recognition", face_recognition_input);
        } catch (const BaseException &e) {