diff options
Diffstat (limited to 'mv_machine_learning')
25 files changed, 73 insertions, 23 deletions
diff --git a/mv_machine_learning/common/include/itask.h b/mv_machine_learning/common/include/itask.h index bfad5a91..99723b62 100644 --- a/mv_machine_learning/common/include/itask.h +++ b/mv_machine_learning/common/include/itask.h @@ -39,6 +39,7 @@ public: virtual void perform() = 0; virtual void performAsync(T &t) = 0; virtual V &getOutput() = 0; + virtual V &getOutputCache() = 0; }; } // namespace } // namespace diff --git a/mv_machine_learning/face_recognition/include/face_recognition_adapter.h b/mv_machine_learning/face_recognition/include/face_recognition_adapter.h index b6acf632..69c2854e 100644 --- a/mv_machine_learning/face_recognition/include/face_recognition_adapter.h +++ b/mv_machine_learning/face_recognition/include/face_recognition_adapter.h @@ -56,6 +56,7 @@ public: void perform() override; void performAsync(T &t) override; V &getOutput() override; + V &getOutputCache() override; }; } // machine_learning diff --git a/mv_machine_learning/face_recognition/include/facenet_adapter.h b/mv_machine_learning/face_recognition/include/facenet_adapter.h index 17e1b261..94cb4cd5 100644 --- a/mv_machine_learning/face_recognition/include/facenet_adapter.h +++ b/mv_machine_learning/face_recognition/include/facenet_adapter.h @@ -50,6 +50,7 @@ public: void perform() override; void performAsync(T &t) override; V &getOutput() override; + V &getOutputCache() override; }; } // machine_learning diff --git a/mv_machine_learning/face_recognition/src/face_recognition_adapter.cpp b/mv_machine_learning/face_recognition/src/face_recognition_adapter.cpp index a6126ef5..5464c66e 100644 --- a/mv_machine_learning/face_recognition/src/face_recognition_adapter.cpp +++ b/mv_machine_learning/face_recognition/src/face_recognition_adapter.cpp @@ -153,6 +153,11 @@ template<typename T, typename V> V &FaceRecognitionAdapter<T, V>::getOutput() return _face_recognition->result(); } +template<typename T, typename V> V &FaceRecognitionAdapter<T, V>::getOutputCache() +{ + throw InvalidOperation("Not support yet."); +} + template class FaceRecognitionAdapter<FaceRecognitionInput, FaceRecognitionResult>; } }
\ No newline at end of file diff --git a/mv_machine_learning/face_recognition/src/facenet_adapter.cpp b/mv_machine_learning/face_recognition/src/facenet_adapter.cpp index 7f16ba5f..82de240b 100644 --- a/mv_machine_learning/face_recognition/src/facenet_adapter.cpp +++ b/mv_machine_learning/face_recognition/src/facenet_adapter.cpp @@ -94,6 +94,11 @@ template<typename T, typename V> V &FacenetAdapter<T, V>::getOutput() return _facenet->result(); } +template<typename T, typename V> V &FacenetAdapter<T, V>::getOutputCache() +{ + throw InvalidOperation("Not support yet."); +} + template class FacenetAdapter<FacenetInput, FacenetOutput>; } }
\ No newline at end of file diff --git a/mv_machine_learning/image_classification/include/image_classification_adapter.h b/mv_machine_learning/image_classification/include/image_classification_adapter.h index 45e493d8..0066c8e8 100644 --- a/mv_machine_learning/image_classification/include/image_classification_adapter.h +++ b/mv_machine_learning/image_classification/include/image_classification_adapter.h @@ -50,6 +50,7 @@ public: void perform() override; void performAsync(T &t) override; V &getOutput() override; + V &getOutputCache() override; }; } // machine_learning diff --git a/mv_machine_learning/image_classification/src/image_classification_adapter.cpp b/mv_machine_learning/image_classification/src/image_classification_adapter.cpp index 4c59dd3c..852eb54d 100644 --- a/mv_machine_learning/image_classification/src/image_classification_adapter.cpp +++ b/mv_machine_learning/image_classification/src/image_classification_adapter.cpp @@ -112,6 +112,11 @@ template<typename T, typename V> V &ImageClassificationAdapter<T, V>::getOutput( return _image_classification->result(); } +template<typename T, typename V> V &ImageClassificationAdapter<T, V>::getOutputCache() +{ + throw InvalidOperation("Not support yet."); +} + template class ImageClassificationAdapter<ImageClassificationInput, ImageClassificationResult>; } }
\ No newline at end of file diff --git a/mv_machine_learning/landmark_detection/include/facial_landmark_adapter.h b/mv_machine_learning/landmark_detection/include/facial_landmark_adapter.h index 1ea521db..82f8e1c0 100644 --- a/mv_machine_learning/landmark_detection/include/facial_landmark_adapter.h +++ b/mv_machine_learning/landmark_detection/include/facial_landmark_adapter.h @@ -56,6 +56,7 @@ public: void perform() override; void performAsync(T &t) override; V &getOutput() override; + V &getOutputCache() override; }; } // machine_learning diff --git a/mv_machine_learning/landmark_detection/include/pose_landmark_adapter.h b/mv_machine_learning/landmark_detection/include/pose_landmark_adapter.h index f2b7f53c..b9659f11 100644 --- a/mv_machine_learning/landmark_detection/include/pose_landmark_adapter.h +++ b/mv_machine_learning/landmark_detection/include/pose_landmark_adapter.h @@ -56,6 +56,7 @@ public: void perform() override; void performAsync(T &t) override; V &getOutput() override; + V &getOutputCache() override; }; } // machine_learning diff --git a/mv_machine_learning/landmark_detection/src/facial_landmark_adapter.cpp b/mv_machine_learning/landmark_detection/src/facial_landmark_adapter.cpp index 9fb19e0e..90a235e3 100644 --- a/mv_machine_learning/landmark_detection/src/facial_landmark_adapter.cpp +++ b/mv_machine_learning/landmark_detection/src/facial_landmark_adapter.cpp @@ -148,6 +148,11 @@ template<typename T, typename V> V &FacialLandmarkAdapter<T, V>::getOutput() return _landmark_detection->result(); } +template<typename T, typename V> V &FacialLandmarkAdapter<T, V>::getOutputCache() +{ + throw InvalidOperation("Not support yet."); +} + template class FacialLandmarkAdapter<LandmarkDetectionInput, LandmarkDetectionResult>; } }
\ No newline at end of file diff --git a/mv_machine_learning/landmark_detection/src/pose_landmark_adapter.cpp b/mv_machine_learning/landmark_detection/src/pose_landmark_adapter.cpp index 5fb6c313..f7b38d7e 100644 --- a/mv_machine_learning/landmark_detection/src/pose_landmark_adapter.cpp +++ b/mv_machine_learning/landmark_detection/src/pose_landmark_adapter.cpp @@ -148,6 +148,11 @@ template<typename T, typename V> V &PoseLandmarkAdapter<T, V>::getOutput() return _landmark_detection->result(); } +template<typename T, typename V> V &PoseLandmarkAdapter<T, V>::getOutputCache() +{ + throw InvalidOperation("Not support yet."); +} + template class PoseLandmarkAdapter<LandmarkDetectionInput, LandmarkDetectionResult>; } }
\ No newline at end of file diff --git a/mv_machine_learning/object_detection/include/face_detection_adapter.h b/mv_machine_learning/object_detection/include/face_detection_adapter.h index 50e32d16..b6f427dc 100644 --- a/mv_machine_learning/object_detection/include/face_detection_adapter.h +++ b/mv_machine_learning/object_detection/include/face_detection_adapter.h @@ -56,6 +56,7 @@ public: void perform() override; void performAsync(T &t) override; V &getOutput() override; + V &getOutputCache() override; }; } // machine_learning diff --git a/mv_machine_learning/object_detection/include/iobject_detection.h b/mv_machine_learning/object_detection/include/iobject_detection.h index ccc735c3..c1c3c6b5 100644 --- a/mv_machine_learning/object_detection/include/iobject_detection.h +++ b/mv_machine_learning/object_detection/include/iobject_detection.h @@ -42,6 +42,7 @@ public: virtual void perform(mv_source_h &mv_src) = 0; virtual void performAsync(ObjectDetectionInput &input) = 0; virtual ObjectDetectionResult &getOutput() = 0; + virtual ObjectDetectionResult &getOutputCache() = 0; }; } // machine_learning diff --git a/mv_machine_learning/object_detection/include/object_detection.h b/mv_machine_learning/object_detection/include/object_detection.h index 64ca00f6..70866322 100644 --- a/mv_machine_learning/object_detection/include/object_detection.h +++ b/mv_machine_learning/object_detection/include/object_detection.h @@ -53,7 +53,6 @@ private: void loadLabel(); void getEngineList(); void getDeviceList(const char *engine_type); - void updateResult(ObjectDetectionResult &result); template<typename T> void preprocess(mv_source_h &mv_src, std::shared_ptr<MetaInfo> metaInfo, std::vector<T> &inputVector); template<typename T> void pushToInput(ObjectDetectionQueue<T> &input); @@ -105,6 +104,7 @@ public: void perform(mv_source_h &mv_src) override; void performAsync(ObjectDetectionInput &input) override; ObjectDetectionResult &getOutput() override; + ObjectDetectionResult &getOutputCache() override; }; } // machine_learning diff --git a/mv_machine_learning/object_detection/include/object_detection_adapter.h b/mv_machine_learning/object_detection/include/object_detection_adapter.h index 1650726d..41be841b 100644 --- a/mv_machine_learning/object_detection/include/object_detection_adapter.h +++ b/mv_machine_learning/object_detection/include/object_detection_adapter.h @@ -59,6 +59,7 @@ public: void perform() override; void performAsync(T &t) override; V &getOutput() override; + V &getOutputCache() override; }; } // machine_learning diff --git a/mv_machine_learning/object_detection/include/object_detection_external.h b/mv_machine_learning/object_detection/include/object_detection_external.h index 3768be76..9034af77 100644 --- a/mv_machine_learning/object_detection/include/object_detection_external.h +++ b/mv_machine_learning/object_detection/include/object_detection_external.h @@ -54,6 +54,7 @@ public: void perform(mv_source_h &mv_src) override; void performAsync(ObjectDetectionInput &input) override; ObjectDetectionResult &getOutput() override; + ObjectDetectionResult &getOutputCache() override; }; } // machine_learning diff --git a/mv_machine_learning/object_detection/include/object_detection_type.h b/mv_machine_learning/object_detection/include/object_detection_type.h index bbd1fd5f..8c04c4b5 100644 --- a/mv_machine_learning/object_detection/include/object_detection_type.h +++ b/mv_machine_learning/object_detection/include/object_detection_type.h @@ -47,7 +47,6 @@ template<typename T> struct ObjectDetectionQueue { * @details Contains object detection result. */ struct ObjectDetectionResult { - bool is_valid {}; unsigned int number_of_objects {}; std::vector<unsigned int> indices; std::vector<std::string> names; diff --git a/mv_machine_learning/object_detection/src/face_detection_adapter.cpp b/mv_machine_learning/object_detection/src/face_detection_adapter.cpp index 239a6d6e..1e1473da 100644 --- a/mv_machine_learning/object_detection/src/face_detection_adapter.cpp +++ b/mv_machine_learning/object_detection/src/face_detection_adapter.cpp @@ -141,6 +141,11 @@ template<typename T, typename V> V &FaceDetectionAdapter<T, V>::getOutput() return _object_detection->getOutput(); } +template<typename T, typename V> V &FaceDetectionAdapter<T, V>::getOutputCache() +{ + return _object_detection->getOutputCache(); +} + template class FaceDetectionAdapter<ObjectDetectionInput, ObjectDetectionResult>; } }
\ No newline at end of file diff --git a/mv_machine_learning/object_detection/src/mv_face_detection.cpp b/mv_machine_learning/object_detection/src/mv_face_detection.cpp index 98509786..5521b1c3 100644 --- a/mv_machine_learning/object_detection/src/mv_face_detection.cpp +++ b/mv_machine_learning/object_detection/src/mv_face_detection.cpp @@ -417,7 +417,7 @@ int mv_face_detection_get_label(mv_face_detection_h handle, const unsigned int i auto context = static_cast<Context *>(handle); auto task = static_cast<FaceDetectionTask *>(context->__tasks.at("face_detection")); - ObjectDetectionResult &result = task->getOutput(); + ObjectDetectionResult &result = task->getOutputCache(); if (result.number_of_objects <= index) throw InvalidParameter("Invalid index range."); diff --git a/mv_machine_learning/object_detection/src/mv_object_detection.cpp b/mv_machine_learning/object_detection/src/mv_object_detection.cpp index a22245da..c84f20da 100644 --- a/mv_machine_learning/object_detection/src/mv_object_detection.cpp +++ b/mv_machine_learning/object_detection/src/mv_object_detection.cpp @@ -415,7 +415,7 @@ int mv_object_detection_get_label(mv_object_detection_h handle, const unsigned i auto context = static_cast<Context *>(handle); auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection")); - ObjectDetectionResult &result = task->getOutput(); + ObjectDetectionResult &result = task->getOutputCache(); if (result.number_of_objects <= index) throw InvalidParameter("Invalid index range."); diff --git a/mv_machine_learning/object_detection/src/object_detection.cpp b/mv_machine_learning/object_detection/src/object_detection.cpp index 2ebf3735..14681fd8 100644 --- a/mv_machine_learning/object_detection/src/object_detection.cpp +++ b/mv_machine_learning/object_detection/src/object_detection.cpp @@ -368,7 +368,6 @@ template<typename T> void inferenceThreadLoop(ObjectDetection *object) object->inference<T>(input.inputs); ObjectDetectionResult &result = object->result(); - result.is_valid = false; object->pushToOutput(result); @@ -412,30 +411,23 @@ void ObjectDetection::performAsync(ObjectDetectionInput &input) } } -void ObjectDetection::updateResult(ObjectDetectionResult &result) -{ - _current_result = result; - _current_result.is_valid = true; -} - ObjectDetectionResult &ObjectDetection::getOutput() { if (_thread_handle) { - // There may be two or more Native APIs which utilize getOutput() function. - // Therefore, the current result should be kept until a new inference request is made for result consistency. - if (_current_result.is_valid) - return _current_result; - if (isOutputQueueEmpty()) - throw InvalidOperation("Output queue is empty."); - - ObjectDetectionResult result = popFromOutput(); - updateResult(result); + throw InvalidOperation("No inference result."); - return _current_result; + _current_result = popFromOutput(); + } else { + _current_result = result(); } - return result(); + return _current_result; +} + +ObjectDetectionResult &ObjectDetection::getOutputCache() +{ + return _current_result; } void ObjectDetection::getOutputNames(vector<string> &names) @@ -491,6 +483,7 @@ ObjectDetectionResult ObjectDetection::popFromOutput() { lock_guard<mutex> lock(_outgoing_queue_mutex); ObjectDetectionResult output = _outgoing_queue.front(); + _outgoing_queue.pop(); return output; diff --git a/mv_machine_learning/object_detection/src/object_detection_adapter.cpp b/mv_machine_learning/object_detection/src/object_detection_adapter.cpp index 4cc86b7a..eb80a63b 100644 --- a/mv_machine_learning/object_detection/src/object_detection_adapter.cpp +++ b/mv_machine_learning/object_detection/src/object_detection_adapter.cpp @@ -169,6 +169,11 @@ template<typename T, typename V> V &ObjectDetectionAdapter<T, V>::getOutput() return _object_detection->getOutput(); } +template<typename T, typename V> V &ObjectDetectionAdapter<T, V>::getOutputCache() +{ + return _object_detection->getOutputCache(); +} + template<typename T, typename V> void ObjectDetectionAdapter<T, V>::performAsync(T &t) { _object_detection->performAsync(t); diff --git a/mv_machine_learning/object_detection/src/object_detection_external.cpp b/mv_machine_learning/object_detection/src/object_detection_external.cpp index f2304129..08ef6470 100644 --- a/mv_machine_learning/object_detection/src/object_detection_external.cpp +++ b/mv_machine_learning/object_detection/src/object_detection_external.cpp @@ -135,7 +135,14 @@ void ObjectDetectionExternal::performAsync(ObjectDetectionInput &input) ObjectDetectionResult &ObjectDetectionExternal::getOutput() { - return _object_detection_plugin->getOutput(); + _current_result = _object_detection_plugin->getOutput(); + + return _current_result; +} + +ObjectDetectionResult &ObjectDetectionExternal::getOutputCache() +{ + return _current_result; } } diff --git a/mv_machine_learning/object_detection_3d/include/object_detection_3d_adapter.h b/mv_machine_learning/object_detection_3d/include/object_detection_3d_adapter.h index 542dc857..192dca82 100644 --- a/mv_machine_learning/object_detection_3d/include/object_detection_3d_adapter.h +++ b/mv_machine_learning/object_detection_3d/include/object_detection_3d_adapter.h @@ -56,6 +56,7 @@ public: void perform() override; void performAsync(T &t) override; V &getOutput() override; + V &getOutputCache() override; }; } // machine_learning diff --git a/mv_machine_learning/object_detection_3d/src/object_detection_3d_adapter.cpp b/mv_machine_learning/object_detection_3d/src/object_detection_3d_adapter.cpp index b72274f0..4c0ca5c1 100644 --- a/mv_machine_learning/object_detection_3d/src/object_detection_3d_adapter.cpp +++ b/mv_machine_learning/object_detection_3d/src/object_detection_3d_adapter.cpp @@ -134,6 +134,11 @@ template<typename T, typename V> V &ObjectDetection3dAdapter<T, V>::getOutput() return _object_detection_3d->result(); } +template<typename T, typename V> V &ObjectDetection3dAdapter<T, V>::getOutputCache() +{ + throw InvalidOperation("Not support yet."); +} + template class ObjectDetection3dAdapter<ObjectDetection3dInput, ObjectDetection3dResult>; } }
\ No newline at end of file |