From: Inki Dae Date: Mon, 20 Mar 2023 09:29:25 +0000 (+0900) Subject: mv_machine_learning: introduce engine configuration API for object detection 3d X-Git-Tag: accepted/tizen/unified/20230411.161303~4^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=257b330c6cd0606d049bb8da72d5b50e07c11baf;p=platform%2Fcore%2Fapi%2Fmediavision.git mv_machine_learning: introduce engine configuration API for object detection 3d [Issue type] : new feature Introduced inference engine configuration task API, which allows user to set user desired inference engine and its device type for inference request. Regarding this, this patch adds below itask interfaces, - setEngineInfo . Set user desired inference engine and its device type. - getNumberOfEngine . Get how many inference engines are available for a given task API. - getEngineType . Get inference engine type to a given index. - getNumberOfDevice . Get how many device types are available for a given inference engine. - getDeviceType . Get device type with a given index. Change-Id: Ic9b1835d0f0024c3b005f905f7bc824bdf956206 Signed-off-by: Inki Dae --- diff --git a/include/mv_object_detection_3d_internal.h b/include/mv_object_detection_3d_internal.h index ce4ca5b1..cb46f1ae 100644 --- a/include/mv_object_detection_3d_internal.h +++ b/include/mv_object_detection_3d_internal.h @@ -76,6 +76,28 @@ int mv_object_detection_3d_create(mv_object_detection_3d_h *infer); */ int mv_object_detection_3d_destroy(mv_object_detection_3d_h infer); +/** + * @brief Set user-given model information. + * @details Use this function to change the model information instead of default one after calling @ref mv_object_detection_3d_create(). + * + * @since_tizen 7.5 + * + * @param[in] handle The handle to the object detection 3d object. + * @param[in] model_name Model name. + * @param[in] model_file Model file name. + * @param[in] meta_file Model meta file name. + * @param[in] label_file Label file name. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Create a object detection 3d handle by calling @ref mv_object_detection_3d_create() + */ +int mv_object_detection_3d_set_model(mv_object_detection_3d_h handle, const char *model_name, const char *model_file, + const char *meta_file, const char *label_file); + /** * @brief Configures the backend for the object detection inference. * @@ -198,6 +220,107 @@ int mv_object_detection_3d_get_num_of_points(mv_object_detection_3d_h handle, un * @pre Request an inference by calling @ref mv_object_detection_3d_inference() */ int mv_object_detection_3d_get_points(mv_object_detection_3d_h handle, unsigned int **out_x, unsigned int **out_y); + +/** + * @brief Set user-given inference engine and device types for inference. + * @details Use this function to change the inference engine and device types for inference instead of default ones after calling @ref mv_object_detection_3d_create(). + * + * @since_tizen 7.5 + * + * @param[in] handle The handle to the object detection 3d object. + * @param[in] engine_type A string of inference engine type. + * @param[in] device_type A string of device type. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Create a object detection 3d handle by calling @ref mv_object_detection_3d_create() + */ +int mv_object_detection_3d_set_engine(mv_object_detection_3d_h handle, const char *engine_type, + const char *device_type); + +/** + * @brief Get a number of inference engines available for object detection 3d task API. + * @details Use this function to get how many inference engines are supported for object detection 3d after calling @ref mv_object_detection_3d_create(). + * + * @since_tizen 7.5 + * + * @param[in] handle The handle to the object detection 3d object. + * @param[out] engine_count A number of inference engines available for object detection 3d API. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Create a object detection 3d handle by calling @ref mv_object_detection_3d_create() + */ +int mv_object_detection_3d_get_engine_count(mv_object_detection_3d_h handle, unsigned int *engine_count); + +/** + * @brief Get engine type to a given inference engine index. + * @details Use this function to get inference engine type with a given engine index after calling @ref mv_object_detection_3d_get_engine_count(). + * + * @since_tizen 7.5 + * + * @param[in] handle The handle to the object detection 3d object. + * @param[in] engine_index A inference engine index for getting the inference engine type. + * @param[out] engine_type A string to inference engine. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Get a number of inference engines available for object detection 3d task API by calling @ref mv_object_detection_get_engine_count() + */ +int mv_object_detection_3d_get_engine_type(mv_object_detection_3d_h handle, const unsigned int engine_index, + char **engine_type); + +/** + * @brief Get a number of device types available to a given inference engine. + * @details Use this function to get how many device types are supported for a given inference engine after calling @ref mv_object_detection_3d_create(). + * + * @since_tizen 7.5 + * + * @param[in] handle The handle to the object detection 3d object. + * @param[in] engine_type A inference engine string. + * @param[out] device_count A number of device types available for a given inference engine. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Create a object detection 3d handle by calling @ref mv_object_detection_3d_create() + */ +int mv_object_detection_3d_get_device_count(mv_object_detection_3d_h handle, const char *engine_type, + unsigned int *device_count); + +/** + * @brief Get device type list available. + * @details Use this function to get what device types are supported for current inference engine type after calling @ref mv_object_detection_3d_configure(). + * + * @since_tizen 7.5 + * + * @param[in] handle The handle to the object detection 3d object. + * @param[in] engine_type A inference engine string. + * @param[in] device_index A device index for getting the device type. + * @param[out] device_type A string to device type. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Create a object detection 3d handle by calling @ref mv_object_detection_3d_create() + * @pre Configure object detection 3d task by calling @ref mv_object_detection_3d_configure() + */ +int mv_object_detection_3d_get_device_type(mv_object_detection_3d_h handle, const char *engine_type, + const unsigned int device_index, char **device_type); + /** * @} */ diff --git a/include/mv_object_detection_internal.h b/include/mv_object_detection_internal.h index 607ac73a..ff203534 100644 --- a/include/mv_object_detection_internal.h +++ b/include/mv_object_detection_internal.h @@ -217,7 +217,7 @@ int mv_object_detection_get_label(mv_object_detection_h infer, const unsigned in * * @since_tizen 7.5 * - * @param[in] handle The handle to the image classification object. + * @param[in] handle The handle to the object detection object. * @param[in] engine_type A string of inference engine type. * @param[in] device_type A string of device type. * @@ -226,25 +226,25 @@ int mv_object_detection_get_label(mv_object_detection_h infer, const unsigned in * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation * - * @pre Create a image classification handle by calling @ref mv_object_detection_create() + * @pre Create a object detection handle by calling @ref mv_object_detection_create() */ int mv_object_detection_set_engine(mv_object_detection_h handle, const char *engine_type, const char *device_type); /** - * @brief Get a number of inference engines available for image classification task API. - * @details Use this function to get how many inference engines are supported for image classification after calling @ref mv_object_detection_create(). + * @brief Get a number of inference engines available for object detection task API. + * @details Use this function to get how many inference engines are supported for object detection after calling @ref mv_object_detection_create(). * * @since_tizen 7.5 * - * @param[in] handle The handle to the image classification object. - * @param[out] engine_count A number of inference engines available for image classification API. + * @param[in] handle The handle to the object detection object. + * @param[out] engine_count A number of inference engines available for object detection API. * * @return @c 0 on success, otherwise a negative error value * @retval #MEDIA_VISION_ERROR_NONE Successful * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation * - * @pre Create a image classification handle by calling @ref mv_object_detection_create() + * @pre Create a object detection handle by calling @ref mv_object_detection_create() */ int mv_object_detection_get_engine_count(mv_object_detection_h handle, unsigned int *engine_count); @@ -254,7 +254,7 @@ int mv_object_detection_get_engine_count(mv_object_detection_h handle, unsigned * * @since_tizen 7.5 * - * @param[in] handle The handle to the image classification object. + * @param[in] handle The handle to the object detection object. * @param[in] engine_index A inference engine index for getting the inference engine type. * @param[out] engine_type A string to inference engine. * @@ -263,7 +263,7 @@ int mv_object_detection_get_engine_count(mv_object_detection_h handle, unsigned * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation * - * @pre Get a number of inference engines available for image classification task API by calling @ref mv_object_detection_get_engine_count() + * @pre Get a number of inference engines available for object detection task API by calling @ref mv_object_detection_get_engine_count() */ int mv_object_detection_get_engine_type(mv_object_detection_h handle, const unsigned int engine_index, char **engine_type); @@ -274,7 +274,7 @@ int mv_object_detection_get_engine_type(mv_object_detection_h handle, const unsi * * @since_tizen 7.5 * - * @param[in] handle The handle to the image classification object. + * @param[in] handle The handle to the object detection object. * @param[in] engine_type A inference engine string. * @param[out] device_count A number of device types available for a given inference engine. * @@ -283,7 +283,7 @@ int mv_object_detection_get_engine_type(mv_object_detection_h handle, const unsi * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation * - * @pre Create a image classification handle by calling @ref mv_object_detection_create() + * @pre Create a object detection handle by calling @ref mv_object_detection_create() */ int mv_object_detection_get_device_count(mv_object_detection_h handle, const char *engine_type, unsigned int *device_count); @@ -294,7 +294,7 @@ int mv_object_detection_get_device_count(mv_object_detection_h handle, const cha * * @since_tizen 7.5 * - * @param[in] handle The handle to the image classification object. + * @param[in] handle The handle to the object detection object. * @param[in] engine_type A inference engine string. * @param[in] device_index A device index for getting the device type. * @param[out] device_type A string to device type. @@ -304,12 +304,14 @@ int mv_object_detection_get_device_count(mv_object_detection_h handle, const cha * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation * - * @pre Create a image classification handle by calling @ref mv_object_detection_create() - * @pre Configure image classification task by calling @ref mv_object_detection_configure() + * @pre Create a object detection handle by calling @ref mv_object_detection_create() + * @pre Configure object detection task by calling @ref mv_object_detection_configure() */ int mv_object_detection_get_device_type(mv_object_detection_h handle, const char *engine_type, const unsigned int device_index, char **device_type); - +/** + * @} + */ #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/mv_machine_learning/object_detection/src/mv_object_detection_open.cpp b/mv_machine_learning/object_detection/src/mv_object_detection_open.cpp index 8dff4d3a..5301b1c8 100644 --- a/mv_machine_learning/object_detection/src/mv_object_detection_open.cpp +++ b/mv_machine_learning/object_detection/src/mv_object_detection_open.cpp @@ -113,6 +113,8 @@ int mv_object_detection_set_model_open(mv_object_detection_h handle, const char int mv_object_detection_set_engine_open(mv_object_detection_h handle, const char *backend_type, const char *device_type) { + lock_guard lock(g_object_detection_mutex); + if (!handle) { LOGE("Handle is NULL."); return MEDIA_VISION_ERROR_INVALID_PARAMETER; @@ -135,6 +137,8 @@ int mv_object_detection_set_engine_open(mv_object_detection_h handle, const char int mv_object_detection_get_engine_count_open(mv_object_detection_h handle, unsigned int *engine_count) { + lock_guard lock(g_object_detection_mutex); + if (!handle) { LOGE("Handle is NULL."); return MEDIA_VISION_ERROR_INVALID_PARAMETER; @@ -159,6 +163,8 @@ int mv_object_detection_get_engine_count_open(mv_object_detection_h handle, unsi int mv_object_detection_get_engine_type_open(mv_object_detection_h handle, const unsigned int engine_index, char **engine_type) { + lock_guard lock(g_object_detection_mutex); + if (!handle) { LOGE("Handle is NULL."); return MEDIA_VISION_ERROR_INVALID_PARAMETER; @@ -183,6 +189,8 @@ int mv_object_detection_get_engine_type_open(mv_object_detection_h handle, const int mv_object_detection_get_device_count_open(mv_object_detection_h handle, const char *engine_type, unsigned int *device_count) { + lock_guard lock(g_object_detection_mutex); + if (!handle) { LOGE("Handle is NULL."); return MEDIA_VISION_ERROR_INVALID_PARAMETER; @@ -207,6 +215,8 @@ int mv_object_detection_get_device_count_open(mv_object_detection_h handle, cons int mv_object_detection_get_device_type_open(mv_object_detection_h handle, const char *engine_type, const unsigned int device_index, char **device_type) { + lock_guard lock(g_object_detection_mutex); + if (!handle) { LOGE("Handle is NULL."); return MEDIA_VISION_ERROR_INVALID_PARAMETER; 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 4e36bafd..44a7c688 100644 --- a/mv_machine_learning/object_detection/src/object_detection_adapter.cpp +++ b/mv_machine_learning/object_detection/src/object_detection_adapter.cpp @@ -89,7 +89,9 @@ void ObjectDetectionAdapter::setModelInfo(const char *model_file, const ch template void ObjectDetectionAdapter::setEngineInfo(const char *engine_type, const char *device_type) -{} +{ + _object_detection->setEngineInfo(string(engine_type), string(device_type)); +} template void ObjectDetectionAdapter::configure() { diff --git a/mv_machine_learning/object_detection_3d/include/mv_object_detection_3d_open.h b/mv_machine_learning/object_detection_3d/include/mv_object_detection_3d_open.h index df444191..5207cf04 100644 --- a/mv_machine_learning/object_detection_3d/include/mv_object_detection_3d_open.h +++ b/mv_machine_learning/object_detection_3d/include/mv_object_detection_3d_open.h @@ -181,6 +181,127 @@ int mv_object_detection_3d_get_num_of_points_open(mv_object_detection_3d_h handl */ int mv_object_detection_3d_get_points_open(mv_object_detection_3d_h handle, unsigned int **out_x, unsigned int **out_y); +/** + * @brief Set user-given model information. + * @details Use this function to change the model information instead of default one after calling @ref mv_object_detection_3d_create(). + * + * @since_tizen 7.5 + * + * @param[in] handle The handle to the object detection 3d object. + * @param[in] model_name Model name. + * @param[in] model_file Model file name. + * @param[in] meta_type Model meta file name. + * @param[in] label_file Label file name. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Create a object detection 3d handle by calling @ref mv_object_detection_3d_create() + */ +int mv_object_detection_3d_set_model_open(mv_object_detection_3d_h handle, const char *model_name, + const char *model_file, const char *meta_file, const char *label_file); +/** + * @brief Set user-given backend and device types for inference. + * @details Use this function to change the backend and device types for inference instead of default ones after calling @ref mv_object_detection_3d_create_open(). + * + * @since_tizen 7.5 + * + * @param[in] handle The handle to the object detection 3d object. + * @param[in] backend_type A string of backend type. + * @param[in] device_type A string of device type. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Create a object detection 3d handle by calling @ref mv_object_detection_3d_create_open() + */ +int mv_object_detection_3d_set_engine_open(mv_object_detection_3d_h handle, const char *backend_type, + const char *device_type); + +/** + * @brief Get a number of inference engines available for object detection 3d task API. + * @details Use this function to get how many inference engines are supported for object detection 3d after calling @ref mv_object_detection_3d_create_open(). + * + * @since_tizen 7.5 + * + * @param[in] handle The handle to the object detection 3d object. + * @param[out] engine_count A number of inference engines available for object detection 3d API. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Create a object detection 3d handle by calling @ref mv_object_detection_3d_create_open() + */ +int mv_object_detection_3d_get_engine_count_open(mv_object_detection_3d_h handle, unsigned int *engine_count); + +/** + * @brief Get engine type to a given inference engine index. + * @details Use this function to get inference engine type with a given engine index after calling @ref mv_object_detection_3d_get_engine_count(). + * + * @since_tizen 7.5 + * + * @param[in] handle The handle to the object detection 3d object. + * @param[in] engine_index A inference engine index for getting the inference engine type. + * @param[out] engine_type A string to inference engine. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Get a number of inference engines available for object detection 3d task API by calling @ref mv_object_detection_3d_get_engine_count() + */ +int mv_object_detection_3d_get_engine_type_open(mv_object_detection_3d_h handle, const unsigned int engine_index, + char **engine_type); + +/** + * @brief Get a number of device types available to a given inference engine. + * @details Use this function to get how many device types are supported for a given inference engine after calling @ref mv_object_detection_3d_create_open(). + * + * @since_tizen 7.5 + * + * @param[in] handle The handle to the object detection 3d object. + * @param[in] engine_type A inference engine string. + * @param[out] device_count A number of device types available for a given inference engine. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Create a object detection 3d handle by calling @ref mv_object_detection_3d_create_open() + */ +int mv_object_detection_3d_get_device_count_open(mv_object_detection_3d_h handle, const char *engine_type, + unsigned int *device_count); + +/** + * @brief Get device type list available. + * @details Use this function to get what device types are supported for current inference engine type after calling @ref mv_object_detection_3d_configure(). + * + * @since_tizen 7.5 + * + * @param[in] handle The handle to the object detection 3d object. + * @param[in] engine_type A inference engine string. + * @param[in] device_index A device index for getting the device type. + * @param[out] device_type A string to device type. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #MEDIA_VISION_ERROR_NONE Successful + * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_VISION_ERROR_INVALID_OPERATION Invalid operation + * + * @pre Create a object detection 3d handle by calling @ref mv_object_detection_3d_create_open() + * @pre Configure object detection 3d task by calling @ref mv_object_detection_3d_configure_open() + */ +int mv_object_detection_3d_get_device_type_open(mv_object_detection_3d_h handle, const char *engine_type, + const unsigned int device_index, char **device_type); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/mv_machine_learning/object_detection_3d/include/object_detection_3d.h b/mv_machine_learning/object_detection_3d/include/object_detection_3d.h index 25a496dd..17d7b1fc 100644 --- a/mv_machine_learning/object_detection_3d/include/object_detection_3d.h +++ b/mv_machine_learning/object_detection_3d/include/object_detection_3d.h @@ -34,13 +34,24 @@ namespace machine_learning { class ObjectDetection3d { +private: + void getEngineList(); + void getDeviceList(const char *engine_type); + + ObjectDetection3dTaskType _task_type; + protected: std::unique_ptr _inference; std::unique_ptr _config; std::unique_ptr _parser; + std::vector _labels; + std::vector _valid_backends; + std::vector _valid_devices; Preprocess _preprocess; std::string _modelFilePath; std::string _modelMetaFilePath; + std::string _modelDefaultPath; + std::string _modelLabelFilePath; int _backendType; int _targetDeviceType; @@ -48,14 +59,22 @@ protected: void getOutputTensor(std::string &target_name, std::vector &tensor); public: - ObjectDetection3d(); + ObjectDetection3d(ObjectDetection3dTaskType task_type); virtual ~ObjectDetection3d() = default; + + ObjectDetection3dTaskType getTaskType(); + void setUserModel(std::string model_file, std::string meta_file, std::string label_file); + void setEngineInfo(std::string engine_type, std::string device_type); + void getNumberOfEngines(unsigned int *number_of_engines); + void getEngineType(unsigned int engine_index, char **engine_type); + void getNumberOfDevices(const char *engine_type, unsigned int *number_of_devices); + void getDeviceType(const char *engine_type, const unsigned int device_index, char **device_type); void parseMetaFile(); void configure(); void prepare(); void preprocess(mv_source_h &mv_src); void inference(mv_source_h source); - virtual object_detection_3d_result_s &result() = 0; + virtual ObjectDetection3dResult &result() = 0; }; } // machine_learning 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 b80de8b8..131e7daa 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 @@ -32,6 +32,10 @@ template class ObjectDetection3dAdapter : public mediavi private: std::unique_ptr _object_detection_3d; T _source; + std::string _model_name; + std::string _model_file; + std::string _meta_file; + std::string _label_file; public: ObjectDetection3dAdapter(); diff --git a/mv_machine_learning/object_detection_3d/include/object_detection_3d_type.h b/mv_machine_learning/object_detection_3d/include/object_detection_3d_type.h index a1db493f..cbe86646 100644 --- a/mv_machine_learning/object_detection_3d/include/object_detection_3d_type.h +++ b/mv_machine_learning/object_detection_3d/include/object_detection_3d_type.h @@ -24,11 +24,11 @@ namespace mediavision { namespace machine_learning { -struct object_detection_3d_input_s { +struct ObjectDetection3dInput { mv_source_h inference_src; }; -struct edge_index_s { +struct EdgeIndex { unsigned int start {}; unsigned int end {}; }; @@ -37,16 +37,16 @@ struct edge_index_s { * @brief The object detection 3d result structure. * @details Contains object detection 3d result. */ -struct object_detection_3d_result_s { +struct ObjectDetection3dResult { unsigned int probability {}; unsigned int number_of_points {}; std::vector x_vec; std::vector y_vec; unsigned int number_of_edges {}; - std::vector edge_index_vec; + std::vector edge_index_vec; }; -enum class object_detection_3d_task_type_e { +enum class ObjectDetection3dTaskType { OBJECT_DETECTION_3D_TASK_NONE = 0, OBJECTRON // TODO diff --git a/mv_machine_learning/object_detection_3d/include/objectron.h b/mv_machine_learning/object_detection_3d/include/objectron.h index 2a5d6243..9512009d 100644 --- a/mv_machine_learning/object_detection_3d/include/objectron.h +++ b/mv_machine_learning/object_detection_3d/include/objectron.h @@ -31,12 +31,13 @@ namespace machine_learning class Objectron : public ObjectDetection3d { private: - object_detection_3d_result_s _result; + ObjectDetection3dResult _result; public: - Objectron(); + Objectron(ObjectDetection3dTaskType task_type); ~Objectron(); - object_detection_3d_result_s &result() override; + + ObjectDetection3dResult &result() override; }; } // machine_learning diff --git a/mv_machine_learning/object_detection_3d/src/mv_object_detection_3d.c b/mv_machine_learning/object_detection_3d/src/mv_object_detection_3d.c index 6b397a68..2084b140 100644 --- a/mv_machine_learning/object_detection_3d/src/mv_object_detection_3d.c +++ b/mv_machine_learning/object_detection_3d/src/mv_object_detection_3d.c @@ -49,6 +49,112 @@ int mv_object_detection_3d_destroy(mv_object_detection_3d_h infer) return ret; } +int mv_object_detection_3d_set_model(mv_object_detection_3d_h handle, const char *model_name, const char *model_file, + const char *meta_file, const char *label_file) +{ + MEDIA_VISION_SUPPORT_CHECK(_mv_inference_face_check_system_info_feature_supported()); + + MEDIA_VISION_INSTANCE_CHECK(handle); + MEDIA_VISION_INSTANCE_CHECK(model_name); + MEDIA_VISION_NULL_ARG_CHECK(model_file); + MEDIA_VISION_NULL_ARG_CHECK(meta_file); + MEDIA_VISION_NULL_ARG_CHECK(label_file); + + MEDIA_VISION_FUNCTION_ENTER(); + + int ret = mv_object_detection_3d_set_model_open(handle, model_name, model_file, meta_file, label_file); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_object_detection_3d_set_engine(mv_object_detection_3d_h handle, const char *backend_type, + const char *device_type) +{ + MEDIA_VISION_SUPPORT_CHECK(_mv_inference_face_check_system_info_feature_supported()); + + MEDIA_VISION_INSTANCE_CHECK(handle); + MEDIA_VISION_NULL_ARG_CHECK(backend_type); + MEDIA_VISION_NULL_ARG_CHECK(device_type); + + MEDIA_VISION_FUNCTION_ENTER(); + + int ret = mv_object_detection_3d_set_engine_open(handle, backend_type, device_type); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_object_detection_3d_get_engine_count(mv_object_detection_3d_h handle, unsigned int *engine_count) +{ + MEDIA_VISION_SUPPORT_CHECK(_mv_inference_face_check_system_info_feature_supported()); + + MEDIA_VISION_INSTANCE_CHECK(handle); + MEDIA_VISION_NULL_ARG_CHECK(engine_count); + + MEDIA_VISION_FUNCTION_ENTER(); + + int ret = mv_object_detection_3d_get_engine_count_open(handle, engine_count); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_object_detection_3d_get_engine_type(mv_object_detection_3d_h handle, const unsigned int engine_index, + char **engine_type) +{ + MEDIA_VISION_SUPPORT_CHECK(_mv_inference_face_check_system_info_feature_supported()); + + MEDIA_VISION_INSTANCE_CHECK(handle); + MEDIA_VISION_NULL_ARG_CHECK(engine_type); + + MEDIA_VISION_FUNCTION_ENTER(); + + int ret = mv_object_detection_3d_get_engine_type_open(handle, engine_index, engine_type); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_object_detection_3d_get_device_count(mv_object_detection_3d_h handle, const char *engine_type, + unsigned int *device_count) +{ + MEDIA_VISION_SUPPORT_CHECK(_mv_inference_face_check_system_info_feature_supported()); + + MEDIA_VISION_INSTANCE_CHECK(handle); + MEDIA_VISION_NULL_ARG_CHECK(device_count); + + MEDIA_VISION_FUNCTION_ENTER(); + + int ret = mv_object_detection_3d_get_device_count_open(handle, engine_type, device_count); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + +int mv_object_detection_3d_get_device_type(mv_object_detection_3d_h handle, const char *engine_type, + const unsigned int device_index, char **device_type) +{ + MEDIA_VISION_SUPPORT_CHECK(_mv_inference_face_check_system_info_feature_supported()); + + MEDIA_VISION_INSTANCE_CHECK(handle); + MEDIA_VISION_NULL_ARG_CHECK(engine_type); + MEDIA_VISION_NULL_ARG_CHECK(device_type); + + MEDIA_VISION_FUNCTION_ENTER(); + + int ret = mv_object_detection_3d_get_device_type_open(handle, engine_type, device_index, device_type); + + MEDIA_VISION_FUNCTION_LEAVE(); + + return ret; +} + int mv_object_detection_3d_configure(mv_object_detection_3d_h infer) { MEDIA_VISION_SUPPORT_CHECK(_mv_inference_check_system_info_feature_supported()); diff --git a/mv_machine_learning/object_detection_3d/src/mv_object_detection_3d_open.cpp b/mv_machine_learning/object_detection_3d/src/mv_object_detection_3d_open.cpp index 075cba08..89619e05 100644 --- a/mv_machine_learning/object_detection_3d/src/mv_object_detection_3d_open.cpp +++ b/mv_machine_learning/object_detection_3d/src/mv_object_detection_3d_open.cpp @@ -26,6 +26,7 @@ #include #include #include +#include using namespace std; using namespace mediavision::inference; @@ -33,7 +34,9 @@ using namespace mediavision::common; using namespace mediavision::machine_learning; using namespace MediaVision::Common; using namespace mediavision::machine_learning::exception; -using ObjectDetection3dTask = ITask; +using ObjectDetection3dTask = ITask; + +static mutex g_object_detection_3d_mutex; int mv_object_detection_3d_create_open(mv_object_detection_3d_h *out_handle) { @@ -47,9 +50,7 @@ int mv_object_detection_3d_create_open(mv_object_detection_3d_h *out_handle) try { context = new Context(); - task = new ObjectDetection3dAdapter(); - task->create(static_cast(object_detection_3d_task_type_e::OBJECTRON)); - + task = new ObjectDetection3dAdapter(); context->__tasks.insert(make_pair("object_detection_3d", task)); *out_handle = static_cast(context); } catch (const BaseException &e) { @@ -65,6 +66,8 @@ int mv_object_detection_3d_create_open(mv_object_detection_3d_h *out_handle) int mv_object_detection_3d_destroy_open(mv_object_detection_3d_h handle) { + lock_guard lock(g_object_detection_3d_mutex); + if (!handle) { LOGE("Handle is NULL."); return MEDIA_VISION_ERROR_INVALID_PARAMETER; @@ -82,10 +85,177 @@ int mv_object_detection_3d_destroy_open(mv_object_detection_3d_h handle) return MEDIA_VISION_ERROR_NONE; } +int mv_object_detection_3d_set_model_open(mv_object_detection_3d_h handle, const char *model_name, + const char *model_file, const char *meta_file, const char *label_file) +{ + LOGD("ENTER"); + + lock_guard lock(g_object_detection_3d_mutex); + + if (!handle) { + LOGE("Handle is NULL."); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + try { + auto context = static_cast(handle); + auto task = static_cast(context->__tasks.at("object_detection_3d")); + + task->setModelInfo(model_file, meta_file, label_file, model_name); + } catch (const BaseException &e) { + LOGE("%s", e.what()); + return e.getError(); + } + + LOGD("LEAVE"); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_object_detection_3d_set_engine_open(mv_object_detection_3d_h handle, const char *backend_type, + const char *device_type) +{ + LOGD("ENTER"); + + lock_guard lock(g_object_detection_3d_mutex); + + if (!handle) { + LOGE("Handle is NULL."); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + try { + auto context = static_cast(handle); + auto task = static_cast(context->__tasks.at("object_detection_3d")); + + task->setEngineInfo(backend_type, device_type); + } catch (const BaseException &e) { + LOGE("%s", e.what()); + return e.getError(); + } + + LOGD("LEAVE"); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_object_detection_3d_get_engine_count_open(mv_object_detection_3d_h handle, unsigned int *engine_count) +{ + LOGD("ENTER"); + + lock_guard lock(g_object_detection_3d_mutex); + + if (!handle) { + LOGE("Handle is NULL."); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + try { + auto context = static_cast(handle); + auto task = static_cast(context->__tasks.at("object_detection_3d")); + + task->getNumberOfEngines(engine_count); + // TODO. + } catch (const BaseException &e) { + LOGE("%s", e.what()); + return e.getError(); + } + + LOGD("LEAVE"); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_object_detection_3d_get_engine_type_open(mv_object_detection_3d_h handle, const unsigned int engine_index, + char **engine_type) +{ + LOGD("ENTER"); + + lock_guard lock(g_object_detection_3d_mutex); + + if (!handle) { + LOGE("Handle is NULL."); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + try { + auto context = static_cast(handle); + auto task = static_cast(context->__tasks.at("object_detection_3d")); + + task->getEngineType(engine_index, engine_type); + // TODO. + } catch (const BaseException &e) { + LOGE("%s", e.what()); + return e.getError(); + } + + LOGD("LEAVE"); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_object_detection_3d_get_device_count_open(mv_object_detection_3d_h handle, const char *engine_type, + unsigned int *device_count) +{ + LOGD("ENTER"); + + lock_guard lock(g_object_detection_3d_mutex); + + if (!handle) { + LOGE("Handle is NULL."); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + try { + auto context = static_cast(handle); + auto task = static_cast(context->__tasks.at("object_detection_3d")); + + task->getNumberOfDevices(engine_type, device_count); + // TODO. + } catch (const BaseException &e) { + LOGE("%s", e.what()); + return e.getError(); + } + + LOGD("LEAVE"); + + return MEDIA_VISION_ERROR_NONE; +} + +int mv_object_detection_3d_get_device_type_open(mv_object_detection_3d_h handle, const char *engine_type, + const unsigned int device_index, char **device_type) +{ + LOGD("ENTER"); + + lock_guard lock(g_object_detection_3d_mutex); + + if (!handle) { + LOGE("Handle is NULL."); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + + try { + auto context = static_cast(handle); + auto task = static_cast(context->__tasks.at("object_detection_3d")); + + task->getDeviceType(engine_type, device_index, device_type); + // TODO. + } catch (const BaseException &e) { + LOGE("%s", e.what()); + return e.getError(); + } + + LOGD("LEAVE"); + + return MEDIA_VISION_ERROR_NONE; +} + int mv_object_detection_3d_configure_open(mv_object_detection_3d_h handle) { LOGD("ENTER"); + lock_guard lock(g_object_detection_3d_mutex); + if (!handle) { LOGE("Handle is NULL."); return MEDIA_VISION_ERROR_INVALID_PARAMETER; @@ -110,6 +280,8 @@ int mv_object_detection_3d_prepare_open(mv_object_detection_3d_h handle) { LOGD("ENTER"); + lock_guard lock(g_object_detection_3d_mutex); + if (!handle) { LOGE("Handle is NULL."); return MEDIA_VISION_ERROR_INVALID_PARAMETER; @@ -134,6 +306,8 @@ int mv_object_detection_3d_inference_open(mv_object_detection_3d_h handle, mv_so { LOGD("ENTER"); + lock_guard lock(g_object_detection_3d_mutex); + if (!handle) { LOGE("Handle is NULL."); return MEDIA_VISION_ERROR_INVALID_PARAMETER; @@ -143,7 +317,7 @@ int mv_object_detection_3d_inference_open(mv_object_detection_3d_h handle, mv_so auto context = static_cast(handle); auto task = static_cast(context->__tasks.at("object_detection_3d")); - object_detection_3d_input_s input = { source }; + ObjectDetection3dInput input = { source }; task->setInput(input); task->perform(); @@ -161,6 +335,8 @@ int mv_object_detection_3d_get_probability_open(mv_object_detection_3d_h handle, { LOGD("ENTER"); + lock_guard lock(g_object_detection_3d_mutex); + if (!handle) { LOGE("Handle is NULL."); return MEDIA_VISION_ERROR_INVALID_PARAMETER; @@ -170,7 +346,7 @@ int mv_object_detection_3d_get_probability_open(mv_object_detection_3d_h handle, auto context = static_cast(handle); auto task = static_cast(context->__tasks.at("object_detection_3d")); - object_detection_3d_result_s &result = task->getOutput(); + ObjectDetection3dResult &result = task->getOutput(); *out_probability = result.probability; } catch (const BaseException &e) { @@ -187,6 +363,8 @@ int mv_object_detection_3d_get_num_of_points_open(mv_object_detection_3d_h handl { LOGD("ENTER"); + lock_guard lock(g_object_detection_3d_mutex); + if (!handle) { LOGE("Handle is NULL."); return MEDIA_VISION_ERROR_INVALID_PARAMETER; @@ -196,7 +374,7 @@ int mv_object_detection_3d_get_num_of_points_open(mv_object_detection_3d_h handl auto context = static_cast(handle); auto task = static_cast(context->__tasks.at("object_detection_3d")); - object_detection_3d_result_s &result = task->getOutput(); + ObjectDetection3dResult &result = task->getOutput(); *out_num_of_points = result.number_of_points; } catch (const BaseException &e) { @@ -213,6 +391,8 @@ int mv_object_detection_3d_get_points_open(mv_object_detection_3d_h handle, unsi { LOGD("ENTER"); + lock_guard lock(g_object_detection_3d_mutex); + if (!handle) { LOGE("Handle is NULL."); return MEDIA_VISION_ERROR_INVALID_PARAMETER; @@ -222,7 +402,7 @@ int mv_object_detection_3d_get_points_open(mv_object_detection_3d_h handle, unsi Context *context = static_cast(handle); auto task = static_cast(context->__tasks.at("object_detection_3d")); - object_detection_3d_result_s &result = task->getOutput(); + ObjectDetection3dResult &result = task->getOutput(); *out_x = result.x_vec.data(); *out_y = result.y_vec.data(); diff --git a/mv_machine_learning/object_detection_3d/src/object_detection_3d.cpp b/mv_machine_learning/object_detection_3d/src/object_detection_3d.cpp index c3911223..fdad14c3 100644 --- a/mv_machine_learning/object_detection_3d/src/object_detection_3d.cpp +++ b/mv_machine_learning/object_detection_3d/src/object_detection_3d.cpp @@ -20,24 +20,136 @@ #include #include "machine_learning_exception.h" +#include "mv_machine_learning_common.h" #include "mv_object_detection_3d_config.h" #include "object_detection_3d.h" using namespace std; using namespace mediavision::inference; using namespace MediaVision::Common; +using namespace mediavision::common; using namespace mediavision::machine_learning::exception; namespace mediavision { namespace machine_learning { -ObjectDetection3d::ObjectDetection3d() : _backendType(), _targetDeviceType() +ObjectDetection3d::ObjectDetection3d(ObjectDetection3dTaskType task_type) + : _task_type(task_type), _backendType(), _targetDeviceType() { _inference = make_unique(); _parser = make_unique(); } +ObjectDetection3dTaskType ObjectDetection3d::getTaskType() +{ + return _task_type; +} + +void ObjectDetection3d::getEngineList() +{ + for (auto idx = MV_INFERENCE_BACKEND_NONE + 1; idx < MV_INFERENCE_BACKEND_MAX; ++idx) { + auto backend = _inference->getSupportedInferenceBackend(idx); + // TODO. we need to describe what inference engines are supported by each Task API, + // and based on it, below inference engine types should be checked + // if a given type is supported by this Task API later. As of now, tflite only. + if (backend.second == true && backend.first.compare("tflite") == 0) + _valid_backends.push_back(backend.first); + } +} + +void ObjectDetection3d::getDeviceList(const char *engine_type) +{ + // TODO. add device types available for a given engine type later. + // In default, cpu and gpu only. + _valid_devices.push_back("cpu"); + _valid_devices.push_back("gpu"); +} + +void ObjectDetection3d::setEngineInfo(std::string engine_type, std::string device_type) +{ + if (engine_type.empty() || device_type.empty()) + throw InvalidParameter("Invalid engine info."); + + transform(engine_type.begin(), engine_type.end(), engine_type.begin(), ::toupper); + transform(device_type.begin(), device_type.end(), device_type.begin(), ::toupper); + + _backendType = GetBackendType(engine_type); + _targetDeviceType = GetDeviceType(device_type); + + LOGI("Engine type : %s => %d, Device type : %s => %d", engine_type.c_str(), GetBackendType(engine_type), + device_type.c_str(), GetDeviceType(device_type)); + + if (_backendType == MEDIA_VISION_ERROR_INVALID_PARAMETER || + _targetDeviceType == MEDIA_VISION_ERROR_INVALID_PARAMETER) + throw InvalidParameter("backend or target device type not found."); +} + +void ObjectDetection3d::getNumberOfEngines(unsigned int *number_of_engines) +{ + if (!_valid_backends.empty()) { + *number_of_engines = _valid_backends.size(); + return; + } + + getEngineList(); + *number_of_engines = _valid_backends.size(); +} + +void ObjectDetection3d::getEngineType(unsigned int engine_index, char **engine_type) +{ + if (!_valid_backends.empty()) { + if (_valid_backends.size() <= engine_index) + throw InvalidParameter("Invalid engine index."); + + *engine_type = const_cast(_valid_backends[engine_index].data()); + return; + } + + getEngineList(); + + if (_valid_backends.size() <= engine_index) + throw InvalidParameter("Invalid engine index."); + + *engine_type = const_cast(_valid_backends[engine_index].data()); +} + +void ObjectDetection3d::getNumberOfDevices(const char *engine_type, unsigned int *number_of_devices) +{ + if (!_valid_devices.empty()) { + *number_of_devices = _valid_devices.size(); + return; + } + + getDeviceList(engine_type); + *number_of_devices = _valid_devices.size(); +} + +void ObjectDetection3d::getDeviceType(const char *engine_type, const unsigned int device_index, char **device_type) +{ + if (!_valid_devices.empty()) { + if (_valid_devices.size() <= device_index) + throw InvalidParameter("Invalid device index."); + + *device_type = const_cast(_valid_devices[device_index].data()); + return; + } + + getDeviceList(engine_type); + + if (_valid_devices.size() <= device_index) + throw InvalidParameter("Invalid device index."); + + *device_type = const_cast(_valid_devices[device_index].data()); +} + +void ObjectDetection3d::setUserModel(string model_file, string meta_file, string label_file) +{ + _modelFilePath = model_file; + _modelMetaFilePath = meta_file; + _modelLabelFilePath = label_file; +} + static bool IsJsonFile(const string &fileName) { return (!fileName.substr(fileName.find_last_of(".") + 1).compare("json")); @@ -61,21 +173,25 @@ void ObjectDetection3d::parseMetaFile() if (ret != MEDIA_VISION_ERROR_NONE) throw InvalidOperation("Fail to get model default path"); - ret = _config->getStringAttribute(MV_OBJECT_DETECTION_3D_MODEL_FILE_PATH, &_modelFilePath); - if (ret != MEDIA_VISION_ERROR_NONE) - throw InvalidOperation("Fail to get model file path"); + if (_modelFilePath.empty()) { + ret = _config->getStringAttribute(MV_OBJECT_DETECTION_3D_MODEL_FILE_PATH, &_modelFilePath); + if (ret != MEDIA_VISION_ERROR_NONE) + throw InvalidOperation("Fail to get model file path"); + } _modelFilePath = modelDefaultPath + _modelFilePath; - ret = _config->getStringAttribute(MV_OBJECT_DETECTION_3D_MODEL_META_FILE_PATH, &_modelMetaFilePath); - if (ret != MEDIA_VISION_ERROR_NONE) - throw InvalidOperation("Fail to get model meta file path"); + if (_modelMetaFilePath.empty()) { + ret = _config->getStringAttribute(MV_OBJECT_DETECTION_3D_MODEL_META_FILE_PATH, &_modelMetaFilePath); + if (ret != MEDIA_VISION_ERROR_NONE) + throw InvalidOperation("Fail to get model meta file path"); - if (_modelMetaFilePath.empty()) - throw InvalidOperation("Model meta file doesn't exist."); + if (_modelMetaFilePath.empty()) + throw InvalidOperation("Model meta file doesn't exist."); - if (!IsJsonFile(_modelMetaFilePath)) - throw InvalidOperation("Model meta file should be json"); + if (!IsJsonFile(_modelMetaFilePath)) + throw InvalidOperation("Model meta file should be json"); + } _modelMetaFilePath = modelDefaultPath + _modelMetaFilePath; 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 f0a14b78..ad9f51b3 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 @@ -27,30 +27,50 @@ namespace mediavision namespace machine_learning { template ObjectDetection3dAdapter::ObjectDetection3dAdapter() : _source() -{} +{ + _object_detection_3d = make_unique(ObjectDetection3dTaskType::OBJECTRON); +} template ObjectDetection3dAdapter::~ObjectDetection3dAdapter() {} template void ObjectDetection3dAdapter::create(int type) -{ - switch (static_cast(type)) { - case object_detection_3d_task_type_e::OBJECTRON: - _object_detection_3d = make_unique(); - break; - default: - throw InvalidParameter("Invalid object detection task type."); - } -} +{} template void ObjectDetection3dAdapter::setModelInfo(const char *model_file, const char *meta_file, const char *label_file, const char *model_name) -{} +{ + string model_name_str(model_name); + + if (!model_name_str.empty()) { + transform(model_name_str.begin(), model_name_str.end(), model_name_str.begin(), ::toupper); + + int model_type = 0; + + if (model_name_str == string("OBJECTRON")) + model_type = static_cast(ObjectDetection3dTaskType::OBJECTRON); + else + throw InvalidParameter("Invalid object detection 3d model name."); + + create(static_cast(model_type)); + } + + _model_file = string(model_file); + _meta_file = string(meta_file); + _label_file = string(label_file); + + if (_model_file.empty() && _meta_file.empty() && _label_file.empty()) + throw InvalidParameter("Model info not invalid."); + + _object_detection_3d->setUserModel(_model_file, _meta_file, _label_file); +} template void ObjectDetection3dAdapter::setEngineInfo(const char *engine_type, const char *device_type) -{} +{ + _object_detection_3d->setEngineInfo(string(engine_type), string(device_type)); +} template void ObjectDetection3dAdapter::configure() { @@ -60,20 +80,28 @@ template void ObjectDetection3dAdapter::configure( template void ObjectDetection3dAdapter::getNumberOfEngines(unsigned int *number_of_engines) -{} +{ + _object_detection_3d->getNumberOfEngines(number_of_engines); +} template void ObjectDetection3dAdapter::getEngineType(unsigned int engine_index, char **engine_type) -{} +{ + _object_detection_3d->getEngineType(engine_index, engine_type); +} template void ObjectDetection3dAdapter::getNumberOfDevices(const char *engine_type, unsigned int *number_of_devices) -{} +{ + _object_detection_3d->getNumberOfDevices(engine_type, number_of_devices); +} template void ObjectDetection3dAdapter::getDeviceType(const char *engine_type, unsigned int device_index, char **device_type) -{} +{ + _object_detection_3d->getDeviceType(engine_type, device_index, device_type); +} template void ObjectDetection3dAdapter::prepare() { @@ -96,6 +124,6 @@ template V &ObjectDetection3dAdapter::getOutput() return _object_detection_3d->result(); } -template class ObjectDetection3dAdapter; +template class ObjectDetection3dAdapter; } } \ No newline at end of file diff --git a/mv_machine_learning/object_detection_3d/src/objectron.cpp b/mv_machine_learning/object_detection_3d/src/objectron.cpp index c6f38b20..c32f2f5b 100644 --- a/mv_machine_learning/object_detection_3d/src/objectron.cpp +++ b/mv_machine_learning/object_detection_3d/src/objectron.cpp @@ -30,13 +30,13 @@ namespace mediavision { namespace machine_learning { -Objectron::Objectron() : _result() +Objectron::Objectron(ObjectDetection3dTaskType task_type) : ObjectDetection3d(task_type), _result() {} Objectron::~Objectron() {} -object_detection_3d_result_s &Objectron::result() +ObjectDetection3dResult &Objectron::result() { vector names; diff --git a/test/testsuites/machine_learning/object_detection_3d/test_object_detection_3d.cpp b/test/testsuites/machine_learning/object_detection_3d/test_object_detection_3d.cpp index dc5e994f..7e37f9d0 100644 --- a/test/testsuites/machine_learning/object_detection_3d/test_object_detection_3d.cpp +++ b/test/testsuites/machine_learning/object_detection_3d/test_object_detection_3d.cpp @@ -30,55 +30,121 @@ using namespace std; using namespace MediaVision::Common; -TEST(ObjectDetection3DTest, InferenceShouldBeOk) +struct model_info { + string model_name; + string model_file; + string meta_file; + string label_file; +}; + +TEST(ObjectDetection3dTest, GettingAvailableInferenceEnginesInfoShouldBeOk) { mv_object_detection_3d_h handle; int ret = mv_object_detection_3d_create(&handle); ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); - ret = mv_object_detection_3d_configure(handle); + unsigned int engine_count = 0; + + ret = mv_object_detection_3d_get_engine_count(handle, &engine_count); ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); - ret = mv_object_detection_3d_prepare(handle); + cout << "Engine count = " << engine_count << endl; + ASSERT_GE(engine_count, 1); + + for (unsigned int engine_idx = 0; engine_idx < engine_count; ++engine_idx) { + char *engine_type = nullptr; + + ret = mv_object_detection_3d_get_engine_type(handle, engine_idx, &engine_type); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + cout << "Engine type : " << engine_type << endl; + + unsigned int device_count = 0; + + ret = mv_object_detection_3d_get_device_count(handle, engine_type, &device_count); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + cout << "Device count = " << device_count << endl; + + ASSERT_GE(engine_count, 1); + + for (unsigned int device_idx = 0; device_idx < device_count; ++device_idx) { + char *device_type = nullptr; + + ret = mv_object_detection_3d_get_device_type(handle, engine_type, device_idx, &device_type); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + cout << "Device type : " << device_type << endl; + } + } + + ret = mv_object_detection_3d_destroy(handle); ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); +} + +TEST(ObjectDetection3dTest, InferenceShouldBeOk) +{ + vector test_models { + { "", "", "", "" }, // If empty then default model will be used. + { "objectron", "object_detection_3d_cup.tflite", "object_detection_3d_cup.json", "" } + // TODO. + }; const string image_path = IMAGE_PATH; mv_source_h mv_source = NULL; - ret = mv_create_source(&mv_source); + int ret = mv_create_source(&mv_source); ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); ret = ImageHelper::loadImageToSource(image_path.c_str(), mv_source); ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); - ret = mv_object_detection_3d_inference(handle, mv_source); - ASSERT_EQ(ret, 0); + for (auto model : test_models) { + mv_object_detection_3d_h handle; - unsigned int probability; + cout << "model name : " << model.model_file << endl; - ret = mv_object_detection_3d_get_probability(handle, &probability); - ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + ret = mv_object_detection_3d_create(&handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); - std::cout << "Probability = " << probability << std::endl; + mv_object_detection_3d_set_model(handle, model.model_name.c_str(), model.model_file.c_str(), + model.meta_file.c_str(), model.label_file.c_str()); + mv_object_detection_3d_set_engine(handle, "tflite", "cpu"); - unsigned int num_of_points; + ret = mv_object_detection_3d_configure(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); - ret = mv_object_detection_3d_get_num_of_points(handle, &num_of_points); - ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + ret = mv_object_detection_3d_prepare(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); - unsigned int *x_array, *y_array; + ret = mv_object_detection_3d_inference(handle, mv_source); + ASSERT_EQ(ret, 0); - ret = mv_object_detection_3d_get_points(handle, &x_array, &y_array); - ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + unsigned int probability; + + ret = mv_object_detection_3d_get_probability(handle, &probability); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + std::cout << "Probability = " << probability << std::endl; + + unsigned int num_of_points; - for (unsigned int idx = 0; idx < num_of_points; ++idx) { - std::cout << "index = " << idx + 1 << " : " << x_array[idx] << " x " << y_array[idx] << std::endl; + ret = mv_object_detection_3d_get_num_of_points(handle, &num_of_points); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + unsigned int *x_array, *y_array; + + ret = mv_object_detection_3d_get_points(handle, &x_array, &y_array); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); + + for (unsigned int idx = 0; idx < num_of_points; ++idx) + std::cout << "index = " << idx + 1 << " : " << x_array[idx] << " x " << y_array[idx] << std::endl; + + ret = mv_object_detection_3d_destroy(handle); + ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); } ret = mv_destroy_source(mv_source); ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); - - ret = mv_object_detection_3d_destroy(handle); - ASSERT_EQ(ret, MEDIA_VISION_ERROR_NONE); }