summaryrefslogtreecommitdiff
path: root/mv_machine_learning/object_detection
diff options
context:
space:
mode:
authorInki Dae <inki.dae@samsung.com>2023-09-06 09:49:36 +0900
committerKwanghoon Son <k.son@samsung.com>2023-10-25 10:54:03 +0900
commit60083a6b401d6c391b3a524cb4cfaa84b9ec69e8 (patch)
tree41eb7c3819f4c4f759ebc42d94a579becc44de68 /mv_machine_learning/object_detection
parent8d9c0b7d93934dc6cb1287b8d0a8737c1865d3f5 (diff)
downloadmediavision-60083a6b401d6c391b3a524cb4cfaa84b9ec69e8.tar.gz
mediavision-60083a6b401d6c391b3a524cb4cfaa84b9ec69e8.tar.bz2
mediavision-60083a6b401d6c391b3a524cb4cfaa84b9ec69e8.zip
mv_machine_learning: move inferenceThreadLoop into class
[Issue type] : code cleanup Move the thread callback, inferenceThreadLoop(), for performing asynchronous inference into ObjectDetection class. This is a first step for introducing asynchronous inference manager which can be used commonly for other task groups. Change-Id: Ie018712406e7e922f92dfea8a23aead72e8e61c9 Signed-off-by: Inki Dae <inki.dae@samsung.com>
Diffstat (limited to 'mv_machine_learning/object_detection')
-rw-r--r--mv_machine_learning/object_detection/include/object_detection.h2
-rw-r--r--mv_machine_learning/object_detection/src/object_detection.cpp21
2 files changed, 11 insertions, 12 deletions
diff --git a/mv_machine_learning/object_detection/include/object_detection.h b/mv_machine_learning/object_detection/include/object_detection.h
index ff9c90f2..83b328d1 100644
--- a/mv_machine_learning/object_detection/include/object_detection.h
+++ b/mv_machine_learning/object_detection/include/object_detection.h
@@ -68,6 +68,7 @@ private:
std::shared_ptr<MetaInfo> getInputMetaInfo();
template<typename T> void perform(mv_source_h &mv_src, std::shared_ptr<MetaInfo> metaInfo);
template<typename T> void performAsync(ObjectDetectionInput &input, std::shared_ptr<MetaInfo> metaInfo);
+ template<typename T> void inferenceThreadLoop();
protected:
std::unique_ptr<mediavision::inference::Inference> _inference;
@@ -89,7 +90,6 @@ protected:
void parseMetaFile(std::string meta_file_name);
template<typename T> void inference(std::vector<std::vector<T> > &inputVectors);
virtual ObjectDetectionResult &result() = 0;
- template<typename T> friend void inferenceThreadLoop(ObjectDetection *object);
public:
ObjectDetection(ObjectDetectionTaskType task_type);
diff --git a/mv_machine_learning/object_detection/src/object_detection.cpp b/mv_machine_learning/object_detection/src/object_detection.cpp
index 5f393598..649e2408 100644
--- a/mv_machine_learning/object_detection/src/object_detection.cpp
+++ b/mv_machine_learning/object_detection/src/object_detection.cpp
@@ -360,29 +360,29 @@ void ObjectDetection::perform(mv_source_h &mv_src)
throw InvalidOperation("Invalid model data type.");
}
-template<typename T> void inferenceThreadLoop(ObjectDetection *object)
+template<typename T> void ObjectDetection::inferenceThreadLoop()
{
// If user called destroy API then this thread loop will be terminated.
- while (!object->_exit_thread) {
+ while (!_exit_thread) {
// If input queue is empty then skip inference request.
- if (object->isInputQueueEmpty<T>())
+ if (isInputQueueEmpty<T>())
continue;
- ObjectDetectionQueue<T> input = object->popFromInput<T>();
+ ObjectDetectionQueue<T> input = popFromInput<T>();
LOGD("Popped : input frame number = %lu", input.frame_number);
- object->inference<T>(input.inputs);
+ inference<T>(input.inputs);
- ObjectDetectionResult &result = object->result();
- result.frame_number = input.frame_number;
+ ObjectDetectionResult &resultQueue = result();
+ resultQueue.frame_number = input.frame_number;
- object->pushToOutput(result);
+ pushToOutput(resultQueue);
}
// waitforOutputQueue function could wait for the notify event after while loop is exited.
// So make sure to call notify_one() here.
- object->_cv_event.notify_one();
+ _cv_event.notify_one();
}
template<typename T> void ObjectDetection::performAsync(ObjectDetectionInput &input, shared_ptr<MetaInfo> metaInfo)
@@ -403,7 +403,7 @@ template<typename T> void ObjectDetection::performAsync(ObjectDetectionInput &in
LOGD("Pushed : input frame number = %lu", in_queue.frame_number);
if (!_thread_handle)
- _thread_handle = make_unique<thread>(&inferenceThreadLoop<T>, this);
+ _thread_handle = make_unique<thread>(&ObjectDetection::inferenceThreadLoop<T>, this);
}
void ObjectDetection::performAsync(ObjectDetectionInput &input)
@@ -579,7 +579,6 @@ template void ObjectDetection::perform<unsigned char>(mv_source_h &mv_src, share
template void ObjectDetection::pushToInput<unsigned char>(ObjectDetectionQueue<unsigned char> &inputQueue);
template ObjectDetectionQueue<unsigned char> ObjectDetection::popFromInput();
template bool ObjectDetection::isInputQueueEmpty<unsigned char>();
-
template void ObjectDetection::performAsync<unsigned char>(ObjectDetectionInput &input, shared_ptr<MetaInfo> metaInfo);
}