mv_machine_learning: introduce engine configuration API for object detection 3d
authorInki Dae <inki.dae@samsung.com>
Mon, 20 Mar 2023 09:29:25 +0000 (18:29 +0900)
committerKwanghoon Son <k.son@samsung.com>
Wed, 22 Mar 2023 04:10:03 +0000 (13:10 +0900)
[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 <inki.dae@samsung.com>
15 files changed:
include/mv_object_detection_3d_internal.h
include/mv_object_detection_internal.h
mv_machine_learning/object_detection/src/mv_object_detection_open.cpp
mv_machine_learning/object_detection/src/object_detection_adapter.cpp
mv_machine_learning/object_detection_3d/include/mv_object_detection_3d_open.h
mv_machine_learning/object_detection_3d/include/object_detection_3d.h
mv_machine_learning/object_detection_3d/include/object_detection_3d_adapter.h
mv_machine_learning/object_detection_3d/include/object_detection_3d_type.h
mv_machine_learning/object_detection_3d/include/objectron.h
mv_machine_learning/object_detection_3d/src/mv_object_detection_3d.c
mv_machine_learning/object_detection_3d/src/mv_object_detection_3d_open.cpp
mv_machine_learning/object_detection_3d/src/object_detection_3d.cpp
mv_machine_learning/object_detection_3d/src/object_detection_3d_adapter.cpp
mv_machine_learning/object_detection_3d/src/objectron.cpp
test/testsuites/machine_learning/object_detection_3d/test_object_detection_3d.cpp

index ce4ca5b158f9c58e8708c5569216af70862cdc44..cb46f1ae65d71e27d7b60e47d25e6bd4bd5e874f 100644 (file)
@@ -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);
+
 /**
  * @}
  */
index 607ac73a9db3aa6cee2d81f55a946a925c44c462..ff203534a9691e62a3a8e72c4990e51a3b682e4d 100644 (file)
@@ -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 */
index 8dff4d3a89c2e814c715bb5dd2a3cae55bb0d7cb..5301b1c810c4082d587fbd07d911e314bc963909 100644 (file)
@@ -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<mutex> 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<mutex> 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<mutex> 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<mutex> 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<mutex> lock(g_object_detection_mutex);
+
        if (!handle) {
                LOGE("Handle is NULL.");
                return MEDIA_VISION_ERROR_INVALID_PARAMETER;
index 4e36bafd7bde85a063bf7e30936e4daad4364a81..44a7c68820180872ddee69cf46365cbff281c785 100644 (file)
@@ -89,7 +89,9 @@ void ObjectDetectionAdapter<T, V>::setModelInfo(const char *model_file, const ch
 
 template<typename T, typename V>
 void ObjectDetectionAdapter<T, V>::setEngineInfo(const char *engine_type, const char *device_type)
-{}
+{
+       _object_detection->setEngineInfo(string(engine_type), string(device_type));
+}
 
 template<typename T, typename V> void ObjectDetectionAdapter<T, V>::configure()
 {
index df4441919a5f4fa4cc66184fc305d0abef5ab3c0..5207cf04c88923da8b2e07670144ddb7cc7366d3 100644 (file)
@@ -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 */
index 25a496dd5d79ff77d8474bc6e2803c6ebc6735dd..17d7b1fc8379a8faaa8b3451749af7d56ae687a8 100644 (file)
@@ -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<mediavision::inference::Inference> _inference;
        std::unique_ptr<MediaVision::Common::EngineConfig> _config;
        std::unique_ptr<MetaParser> _parser;
+       std::vector<std::string> _labels;
+       std::vector<std::string> _valid_backends;
+       std::vector<std::string> _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<float> &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
index b80de8b8dba3b61db12e606d8936d2d4e81df82e..131e7daaeae35576d18a19e286e00895f879a694 100644 (file)
@@ -32,6 +32,10 @@ template<typename T, typename V> class ObjectDetection3dAdapter : public mediavi
 private:
        std::unique_ptr<ObjectDetection3d> _object_detection_3d;
        T _source;
+       std::string _model_name;
+       std::string _model_file;
+       std::string _meta_file;
+       std::string _label_file;
 
 public:
        ObjectDetection3dAdapter();
index a1db493fdcf3673d4b5841d7f3cdc68e7a854ad4..cbe86646f7e6a7b745af7aa1421a362a122b783f 100644 (file)
@@ -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<unsigned int> x_vec;
        std::vector<unsigned int> y_vec;
        unsigned int number_of_edges {};
-       std::vector<edge_index_s> edge_index_vec;
+       std::vector<EdgeIndex> edge_index_vec;
 };
 
-enum class object_detection_3d_task_type_e {
+enum class ObjectDetection3dTaskType {
        OBJECT_DETECTION_3D_TASK_NONE = 0,
        OBJECTRON
        // TODO
index 2a5d624365a30a49b1cdacc999452310c9ab8a9d..9512009dcc0ed3c938ac8449dc77834ee87e7eda 100644 (file)
@@ -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
index 6b397a6815be755a9fb789c86acdeb3b2c14924f..2084b1403247d8a3f539e80bc7e60e531591702f 100644 (file)
@@ -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());
index 075cba08366ba049be2313c3bf9d4fda7d513f5d..89619e0580f269dd79f8511482e10bce330bd9c9 100644 (file)
@@ -26,6 +26,7 @@
 #include <unistd.h>
 #include <string>
 #include <algorithm>
+#include <mutex>
 
 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<object_detection_3d_input_s, object_detection_3d_result_s>;
+using ObjectDetection3dTask = ITask<ObjectDetection3dInput, ObjectDetection3dResult>;
+
+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<object_detection_3d_input_s, object_detection_3d_result_s>();
-               task->create(static_cast<int>(object_detection_3d_task_type_e::OBJECTRON));
-
+               task = new ObjectDetection3dAdapter<ObjectDetection3dInput, ObjectDetection3dResult>();
                context->__tasks.insert(make_pair("object_detection_3d", task));
                *out_handle = static_cast<mv_object_detection_3d_h>(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<mutex> 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<mutex> lock(g_object_detection_3d_mutex);
+
+       if (!handle) {
+               LOGE("Handle is NULL.");
+               return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+       }
+
+       try {
+               auto context = static_cast<Context *>(handle);
+               auto task = static_cast<ObjectDetection3dTask *>(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<mutex> lock(g_object_detection_3d_mutex);
+
+       if (!handle) {
+               LOGE("Handle is NULL.");
+               return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+       }
+
+       try {
+               auto context = static_cast<Context *>(handle);
+               auto task = static_cast<ObjectDetection3dTask *>(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<mutex> lock(g_object_detection_3d_mutex);
+
+       if (!handle) {
+               LOGE("Handle is NULL.");
+               return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+       }
+
+       try {
+               auto context = static_cast<Context *>(handle);
+               auto task = static_cast<ObjectDetection3dTask *>(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<mutex> lock(g_object_detection_3d_mutex);
+
+       if (!handle) {
+               LOGE("Handle is NULL.");
+               return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+       }
+
+       try {
+               auto context = static_cast<Context *>(handle);
+               auto task = static_cast<ObjectDetection3dTask *>(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<mutex> lock(g_object_detection_3d_mutex);
+
+       if (!handle) {
+               LOGE("Handle is NULL.");
+               return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+       }
+
+       try {
+               auto context = static_cast<Context *>(handle);
+               auto task = static_cast<ObjectDetection3dTask *>(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<mutex> lock(g_object_detection_3d_mutex);
+
+       if (!handle) {
+               LOGE("Handle is NULL.");
+               return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+       }
+
+       try {
+               auto context = static_cast<Context *>(handle);
+               auto task = static_cast<ObjectDetection3dTask *>(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<mutex> 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<mutex> 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<mutex> 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<Context *>(handle);
                auto task = static_cast<ObjectDetection3dTask *>(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<mutex> 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<Context *>(handle);
                auto task = static_cast<ObjectDetection3dTask *>(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<mutex> 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<Context *>(handle);
                auto task = static_cast<ObjectDetection3dTask *>(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<mutex> 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<Context *>(handle);
                auto task = static_cast<ObjectDetection3dTask *>(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();
index c39112235a91af5372fa819f650714814770a864..fdad14c397fc95bc8a41a3aa70674a0b5f3b30bf 100644 (file)
 #include <algorithm>
 
 #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<Inference>();
        _parser = make_unique<ObjectDetection3dParser>();
 }
 
+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<char *>(_valid_backends[engine_index].data());
+               return;
+       }
+
+       getEngineList();
+
+       if (_valid_backends.size() <= engine_index)
+               throw InvalidParameter("Invalid engine index.");
+
+       *engine_type = const_cast<char *>(_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<char *>(_valid_devices[device_index].data());
+               return;
+       }
+
+       getDeviceList(engine_type);
+
+       if (_valid_devices.size() <= device_index)
+               throw InvalidParameter("Invalid device index.");
+
+       *device_type = const_cast<char *>(_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;
 
index f0a14b781caeade661c4b3197dbec22e6fec0bf5..ad9f51b32909d745500dccf180a6dc911d1dbffa 100644 (file)
@@ -27,30 +27,50 @@ namespace mediavision
 namespace machine_learning
 {
 template<typename T, typename V> ObjectDetection3dAdapter<T, V>::ObjectDetection3dAdapter() : _source()
-{}
+{
+       _object_detection_3d = make_unique<Objectron>(ObjectDetection3dTaskType::OBJECTRON);
+}
 
 template<typename T, typename V> ObjectDetection3dAdapter<T, V>::~ObjectDetection3dAdapter()
 {}
 
 template<typename T, typename V> void ObjectDetection3dAdapter<T, V>::create(int type)
-{
-       switch (static_cast<object_detection_3d_task_type_e>(type)) {
-       case object_detection_3d_task_type_e::OBJECTRON:
-               _object_detection_3d = make_unique<Objectron>();
-               break;
-       default:
-               throw InvalidParameter("Invalid object detection task type.");
-       }
-}
+{}
 
 template<typename T, typename V>
 void ObjectDetection3dAdapter<T, V>::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<int>(ObjectDetection3dTaskType::OBJECTRON);
+               else
+                       throw InvalidParameter("Invalid object detection 3d model name.");
+
+               create(static_cast<int>(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<typename T, typename V>
 void ObjectDetection3dAdapter<T, V>::setEngineInfo(const char *engine_type, const char *device_type)
-{}
+{
+       _object_detection_3d->setEngineInfo(string(engine_type), string(device_type));
+}
 
 template<typename T, typename V> void ObjectDetection3dAdapter<T, V>::configure()
 {
@@ -60,20 +80,28 @@ template<typename T, typename V> void ObjectDetection3dAdapter<T, V>::configure(
 
 template<typename T, typename V>
 void ObjectDetection3dAdapter<T, V>::getNumberOfEngines(unsigned int *number_of_engines)
-{}
+{
+       _object_detection_3d->getNumberOfEngines(number_of_engines);
+}
 
 template<typename T, typename V>
 void ObjectDetection3dAdapter<T, V>::getEngineType(unsigned int engine_index, char **engine_type)
-{}
+{
+       _object_detection_3d->getEngineType(engine_index, engine_type);
+}
 
 template<typename T, typename V>
 void ObjectDetection3dAdapter<T, V>::getNumberOfDevices(const char *engine_type, unsigned int *number_of_devices)
-{}
+{
+       _object_detection_3d->getNumberOfDevices(engine_type, number_of_devices);
+}
 
 template<typename T, typename V>
 void ObjectDetection3dAdapter<T, V>::getDeviceType(const char *engine_type, unsigned int device_index,
                                                                                                   char **device_type)
-{}
+{
+       _object_detection_3d->getDeviceType(engine_type, device_index, device_type);
+}
 
 template<typename T, typename V> void ObjectDetection3dAdapter<T, V>::prepare()
 {
@@ -96,6 +124,6 @@ template<typename T, typename V> V &ObjectDetection3dAdapter<T, V>::getOutput()
        return _object_detection_3d->result();
 }
 
-template class ObjectDetection3dAdapter<object_detection_3d_input_s, object_detection_3d_result_s>;
+template class ObjectDetection3dAdapter<ObjectDetection3dInput, ObjectDetection3dResult>;
 }
 }
\ No newline at end of file
index c6f38b203e7992bda151bd3849de6c3d95710bc0..c32f2f5b052512e15df782120be7a533551da7c4 100644 (file)
@@ -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<string> names;
 
index dc5e994fa0db4d2c63b96d961c1e34692fe1d49a..7e37f9d021902bd23d3362ed195214250995c659 100644 (file)
@@ -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<model_info> 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);
 }