void machine_learning_native_inference_async(void *handle, const std::string &task_name, InputBaseType &input);
OutputBaseType &machine_learning_native_get_result(void *handle, const std::string &task_name);
void machine_learning_native_set_model(void *handle, const std::string &task_name, const char *model_file,
- const char *meta_file, const char *label_file);
+ const char *meta_file, const char *label_file, const char *model_name = "");
void machine_learning_native_set_engine(void *handle, const std::string &task_name, const char *backend_type,
const char *device_type);
void machine_learning_native_get_engine_count(void *handle, const std::string &task_name, unsigned int *engine_count);
}
void machine_learning_native_set_model(void *handle, const string &task_name, const char *model_file,
- const char *meta_file, const char *label_file)
+ const char *meta_file, const char *label_file, const char *model_name)
{
auto task = get_task(handle, task_name);
- task->setModelInfo(model_file, meta_file, label_file);
+ task->setModelInfo(model_file, meta_file, label_file, model_name);
}
void machine_learning_native_set_engine(void *handle, const string &task_name, const char *backend_type,
MEDIA_VISION_FUNCTION_ENTER();
try {
- machine_learning_native_set_model(handle, TASK_NAME, model_file, meta_file, label_file);
+ machine_learning_native_set_model(handle, TASK_NAME, model_file, meta_file, label_file, model_name);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- machine_learning_native_set_model(handle, TASK_NAME, model_file, meta_file, label_file);
+ machine_learning_native_set_model(handle, TASK_NAME, model_file, meta_file, label_file, model_name);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
#include "mv_face_detection_internal.h"
#include "face_detection_adapter.h"
#include "machine_learning_exception.h"
+#include "MachineLearningNative.h"
#include "object_detection_type.h"
#include "context.h"
#include <mutex>
#include <iostream>
+#define TASK_NAME "face_detection"
+
using namespace std;
using namespace mediavision::inference;
using namespace mediavision::common;
using namespace mediavision::machine_learning;
using namespace MediaVision::Common;
using namespace mediavision::machine_learning::exception;
-using FaceDetectionTask = ITask<InputBaseType, OutputBaseType>;
+using FaceDetectionTask = FaceDetectionAdapter<InputBaseType, OutputBaseType>;
int mv_face_detection_create(mv_face_detection_h *handle)
{
MEDIA_VISION_FUNCTION_ENTER();
- Context *context = nullptr;
- FaceDetectionTask *task = nullptr;
-
try {
- context = new Context();
- task = new FaceDetectionAdapter<InputBaseType, OutputBaseType>();
- context->__tasks.insert(make_pair("face_detection", task));
- *handle = static_cast<mv_face_detection_h>(context);
+ machine_learning_native_create<InputBaseType, OutputBaseType>(TASK_NAME, new FaceDetectionTask(), handle);
} catch (const BaseException &e) {
- delete task;
- delete context;
return e.getError();
}
MEDIA_VISION_FUNCTION_ENTER();
- auto context = static_cast<Context *>(handle);
-
- for (auto &m : context->__tasks)
- delete static_cast<FaceDetectionTask *>(m.second);
-
- delete context;
+ machine_learning_native_destory(handle, TASK_NAME);
MEDIA_VISION_FUNCTION_LEAVE();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<FaceDetectionTask *>(context->__tasks.at("face_detection"));
-
- task->setModelInfo(model_file, meta_file, label_file, model_name);
+ machine_learning_native_set_model(handle, TASK_NAME, model_file, meta_file, label_file, model_name);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<FaceDetectionTask *>(context->__tasks.at("face_detection"));
-
- task->setEngineInfo(backend_type, device_type);
+ machine_learning_native_set_engine(handle, TASK_NAME, backend_type, device_type);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<FaceDetectionTask *>(context->__tasks.at("face_detection"));
-
- task->getNumberOfEngines(engine_count);
- // TODO.
+ machine_learning_native_get_engine_count(handle, TASK_NAME, engine_count);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<FaceDetectionTask *>(context->__tasks.at("face_detection"));
-
- task->getEngineType(engine_index, engine_type);
- // TODO.
+ machine_learning_native_get_engine_type(handle, TASK_NAME, engine_index, engine_type);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<FaceDetectionTask *>(context->__tasks.at("face_detection"));
-
- task->getNumberOfDevices(engine_type, device_count);
- // TODO.
+ machine_learning_native_get_device_count(handle, TASK_NAME, engine_type, device_count);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<FaceDetectionTask *>(context->__tasks.at("face_detection"));
-
- task->getDeviceType(engine_type, device_index, device_type);
- // TODO.
+ machine_learning_native_get_device_type(handle, TASK_NAME, engine_type, device_index, device_type);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<FaceDetectionTask *>(context->__tasks.at("face_detection"));
-
- task->configure();
+ machine_learning_native_configure(handle, TASK_NAME);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<FaceDetectionTask *>(context->__tasks.at("face_detection"));
-
- task->prepare();
+ machine_learning_native_prepare(handle, TASK_NAME);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<FaceDetectionTask *>(context->__tasks.at("face_detection"));
-
ObjectDetectionInput input(source);
- task->setInput(input);
- task->perform();
+ machine_learning_native_inference(handle, TASK_NAME, input);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
- if (!handle) {
- LOGE("Handle is NULL.");
- return MEDIA_VISION_ERROR_INVALID_PARAMETER;
- }
-
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<FaceDetectionTask *>(context->__tasks.at("face_detection"));
-
ObjectDetectionInput input(source);
- task->performAsync(input);
+ machine_learning_native_inference_async(handle, TASK_NAME, input);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<FaceDetectionTask *>(context->__tasks.at("face_detection"));
-
- auto &result = static_cast<ObjectDetectionResult &>(task->getOutput());
+ auto &result = static_cast<ObjectDetectionResult &>(machine_learning_native_get_result(handle, TASK_NAME));
*number_of_objects = result.number_of_objects;
*frame_number = result.frame_number;
*confidences = result.confidences.data();
#include "mv_object_detection_internal.h"
#include "object_detection_adapter.h"
#include "machine_learning_exception.h"
+#include "MachineLearningNative.h"
#include "object_detection_type.h"
#include "context.h"
#include <mutex>
#include <iostream>
+#define TASK_NAME "object_detection"
+
using namespace std;
using namespace mediavision::inference;
using namespace mediavision::common;
using namespace mediavision::machine_learning;
using namespace MediaVision::Common;
using namespace mediavision::machine_learning::exception;
-using ObjectDetectionTask = ITask<InputBaseType, OutputBaseType>;
+using ObjectDetectionTask = ObjectDetectionAdapter<InputBaseType, OutputBaseType>;
int mv_object_detection_create(mv_object_detection_h *handle)
{
MEDIA_VISION_FUNCTION_ENTER();
- Context *context = nullptr;
- ObjectDetectionTask *task = nullptr;
-
try {
- context = new Context();
- task = new ObjectDetectionAdapter<InputBaseType, OutputBaseType>();
- context->__tasks.insert(make_pair("object_detection", task));
- *handle = static_cast<mv_object_detection_h>(context);
+ machine_learning_native_create<InputBaseType, OutputBaseType>(TASK_NAME, new ObjectDetectionTask(), handle);
} catch (const BaseException &e) {
- delete task;
- delete context;
return e.getError();
}
MEDIA_VISION_FUNCTION_ENTER();
- auto context = static_cast<Context *>(handle);
-
- for (auto &m : context->__tasks)
- delete static_cast<ObjectDetectionTask *>(m.second);
-
- delete context;
+ machine_learning_native_destory(handle, TASK_NAME);
MEDIA_VISION_FUNCTION_LEAVE();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
- task->setModelInfo(model_file, meta_file, label_file, model_name);
+ machine_learning_native_set_model(handle, TASK_NAME, model_file, meta_file, label_file, model_name);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
- task->setEngineInfo(backend_type, device_type);
+ machine_learning_native_set_engine(handle, TASK_NAME, backend_type, device_type);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
- task->getNumberOfEngines(engine_count);
- // TODO.
+ machine_learning_native_get_engine_count(handle, TASK_NAME, engine_count);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
- task->getEngineType(engine_index, engine_type);
- // TODO.
+ machine_learning_native_get_engine_type(handle, TASK_NAME, engine_index, engine_type);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
- task->getNumberOfDevices(engine_type, device_count);
- // TODO.
+ machine_learning_native_get_device_count(handle, TASK_NAME, engine_type, device_count);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
- task->getDeviceType(engine_type, device_index, device_type);
- // TODO.
+ machine_learning_native_get_device_type(handle, TASK_NAME, engine_type, device_index, device_type);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
- task->configure();
+ machine_learning_native_configure(handle, TASK_NAME);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
- task->prepare();
+ machine_learning_native_prepare(handle, TASK_NAME);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
ObjectDetectionInput input(source);
- task->setInput(input);
- task->perform();
+ machine_learning_native_inference(handle, TASK_NAME, input);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
ObjectDetectionInput input(source);
- task->performAsync(input);
+ machine_learning_native_inference_async(handle, TASK_NAME, input);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
- auto &result = static_cast<ObjectDetectionResult &>(task->getOutput());
+ auto &result = static_cast<ObjectDetectionResult &>(machine_learning_native_get_result(handle, TASK_NAME));
*number_of_objects = result.number_of_objects;
*frame_number = result.frame_number;
*confidences = result.confidences.data();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<ObjectDetectionTask *>(context->__tasks.at("object_detection"));
-
- auto &result = static_cast<ObjectDetectionResult &>(task->getOutputCache());
+ auto &result = static_cast<ObjectDetectionResult &>(machine_learning_native_get_result(handle, TASK_NAME));
if (result.number_of_objects <= index)
throw InvalidParameter("Invalid index range.");
const char *label;
ret = mv_object_detection_get_label(handle, idx, &label);
+ if (ret == MEDIA_VISION_ERROR_INVALID_OPERATION)
+ break;
+
ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE);
cout << "index = " << idx << " label = " << label << endl;