return err;
}
-int perform_tflite_mobilenetv1_config(mv_engine_config_h *engine_cfg)
+int perform_tflite_mobilenetv1_config(mv_engine_config_h handle)
{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
const char *inputNodeName = "input_2";
const char *outputNodeName[] = { "dense_3/Softmax" };
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, IC_TFLITE_WEIGHT_PATH);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE,
- MV_INFERENCE_DATA_FLOAT32);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_LABEL_PATH);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE,
- 127.0);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE,
- 127.0);
-
- mv_engine_config_set_double_attribute(
- handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH,
- 224);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT,
- 224);
-
- mv_engine_config_set_int_attribute(handle,
- MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3);
-
- mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME,
- inputNodeName);
-
- mv_engine_config_set_array_string_attribute(
- handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1);
-
- *engine_cfg = handle;
- return err;
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
+ IC_TFLITE_WEIGHT_PATH));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_LABEL_PATH));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_MEAN_VALUE, 127.0));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_STD_VALUE, 127.0));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_TFLITE));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 224));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 224));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName));
+ RET_IF_FAIL(mv_engine_config_set_array_string_attribute(
+ handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1));
+ return MEDIA_VISION_ERROR_NONE;
}
-int perform_armnn_mobilenetv1_config(mv_engine_config_h *engine_cfg)
+int perform_armnn_mobilenetv1_config(mv_engine_config_h handle)
{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
const char *inputNodeName = "input_2";
const char *outputNodeName[] = { "dense_3/Softmax" };
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, IC_TFLITE_WEIGHT_PATH);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE,
- MV_INFERENCE_DATA_FLOAT32);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_LABEL_PATH);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE,
- 127.0);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE,
- 127.0);
-
- mv_engine_config_set_double_attribute(
- handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_ARMNN);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH,
- 224);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT,
- 224);
-
- mv_engine_config_set_int_attribute(handle,
- MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3);
-
- mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME,
- inputNodeName);
-
- mv_engine_config_set_array_string_attribute(
- handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1);
-
- *engine_cfg = handle;
- return err;
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
+ IC_TFLITE_WEIGHT_PATH));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_LABEL_PATH));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_MEAN_VALUE, 127.0));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_STD_VALUE, 127.0));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_ARMNN));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 224));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 224));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName));
+ RET_IF_FAIL(mv_engine_config_set_array_string_attribute(
+ handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1));
+ return MEDIA_VISION_ERROR_NONE;
}
-int perform_one_mobilenetv1_quant_config(mv_engine_config_h *engine_cfg)
+int perform_one_mobilenetv1_quant_config(mv_engine_config_h handle)
{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
const char *inputNodeName = "input";
const char *outputNodeName[] = { "MobilenetV1/Predictions/Reshape_1" };
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, IC_Q_TFLITE_WEIGHT_PATH);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE,
- MV_INFERENCE_DATA_UINT8);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_Q_LABEL_PATH);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE,
- 0.0);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE,
- 1.0);
-
- mv_engine_config_set_double_attribute(
- handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_ONE);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH,
- 224);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT,
- 224);
-
- mv_engine_config_set_int_attribute(handle,
- MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3);
-
- mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME,
- inputNodeName);
-
- mv_engine_config_set_array_string_attribute(
- handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1);
-
- *engine_cfg = handle;
- return err;
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
+ IC_Q_TFLITE_WEIGHT_PATH));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_UINT8));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_Q_LABEL_PATH));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_MEAN_VALUE, 0.0));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_STD_VALUE, 1.0));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_ONE));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 224));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 224));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName));
+ RET_IF_FAIL(mv_engine_config_set_array_string_attribute(
+ handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1));
+ return MEDIA_VISION_ERROR_NONE;
}
-int perform_vivante_inceptionv3_config(mv_engine_config_h *engine_cfg)
+int perform_vivante_inceptionv3_config(mv_engine_config_h handle)
{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
const char *inputNodeName = "input";
const char *outputNodeName[] = { "InceptionV3/Predictions/Peshape_1" };
- mv_engine_config_set_string_attribute(handle,
- MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- IC_VIVANTE_WEIGHT_PATH);
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
+ IC_VIVANTE_WEIGHT_PATH));
- mv_engine_config_set_string_attribute(
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
handle, MV_INFERENCE_MODEL_CONFIGURATION_FILE_PATH,
- IC_VIVANTE_CONFIG_PATH);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE,
- MV_INFERENCE_DATA_UINT8);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_VIVANTE_LABEL_PATH);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE,
- 0.0);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE,
- 1.0);
-
- mv_engine_config_set_double_attribute(
- handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_MLAPI);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_DEVICE_TYPE,
- MV_INFERENCE_TARGET_DEVICE_CUSTOM);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH,
- 299);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT,
- 299);
-
- mv_engine_config_set_int_attribute(handle,
- MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3);
-
- mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME,
- inputNodeName);
-
- mv_engine_config_set_array_string_attribute(
- handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1);
-
- *engine_cfg = handle;
- return err;
+ IC_VIVANTE_CONFIG_PATH));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_UINT8));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_VIVANTE_LABEL_PATH));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_MEAN_VALUE, 0.0));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_STD_VALUE, 1.0));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_MLAPI));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_TARGET_DEVICE_TYPE,
+ MV_INFERENCE_TARGET_DEVICE_CUSTOM));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 299));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 299));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName));
+ RET_IF_FAIL(mv_engine_config_set_array_string_attribute(
+ handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1));
+ return MEDIA_VISION_ERROR_NONE;
}
-int perform_opencv_caffe_squeezenet_config(mv_engine_config_h *engine_cfg)
+int perform_opencv_caffe_squeezenet_config(mv_engine_config_h handle)
{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
const char *inputNodeName = "data";
const char *outputNodeName[] = { "prob" };
- mv_engine_config_set_string_attribute(handle,
- MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- IC_OPENCV_WEIGHT_CAFFE_PATH);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE,
- MV_INFERENCE_DATA_FLOAT32);
-
- mv_engine_config_set_string_attribute(
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
+ IC_OPENCV_WEIGHT_CAFFE_PATH));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
handle, MV_INFERENCE_MODEL_CONFIGURATION_FILE_PATH,
- IC_OPENCV_CONFIG_CAFFE_PATH);
-
- mv_engine_config_set_string_attribute(handle,
- MV_INFERENCE_MODEL_USER_FILE_PATH,
- IC_OPENCV_LABEL_CAFFE_PATH);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE,
- 0.0);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE,
- 1.0);
-
- mv_engine_config_set_double_attribute(
- handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_OPENCV);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH,
- 227);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT,
- 227);
-
- mv_engine_config_set_int_attribute(handle,
- MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3);
-
- mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME,
- inputNodeName);
-
- mv_engine_config_set_array_string_attribute(
- handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1);
-
- *engine_cfg = handle;
- return err;
-}
-
-
-int perform_hosted_tflite_mobilenetv1_224_config(mv_engine_config_h *engine_cfg)
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- IC_TFLITE_WEIGHT_MOBILENET_V1_224_PATH);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
- IC_LABEL_MOBILENET_V1_224_PATH);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- *engine_cfg = handle;
- return err;
-}
-
-int perform_hosted_tflite_mobilenetv2_224_config(mv_engine_config_h *engine_cfg)
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- IC_TFLITE_WEIGHT_MOBILENET_V2_224_PATH);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
- IC_LABEL_MOBILENET_V2_224_PATH);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- *engine_cfg = handle;
- return err;
-}
-
-int perform_hosted_tflite_densenet_224_config(mv_engine_config_h *engine_cfg)
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- IC_TFLITE_WEIGHT_DENSENET_224_PATH);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
- IC_LABEL_DENSENET_224_PATH);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- *engine_cfg = handle;
- return err;
-}
-
-int perform_hosted_tflite_inception_resnet_299_config(mv_engine_config_h *engine_cfg)
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- IC_TFLITE_WEIGHT_INCEPTION_RESENET_299_PATH);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
- IC_LABEL_INCEPTION_RESENET_299_PATH);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- *engine_cfg = handle;
- return err;
-}
-
-int perform_hosted_tflite_inception_v3_config(mv_engine_config_h *engine_cfg)
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- IC_TFLITE_WEIGHT_INCEPTION_V3_299_PATH);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
- IC_LABEL_INCEPTION_V3_299_PATH);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- *engine_cfg = handle;
- return err;
-}
-
-int perform_hosted_tflite_inception_v4_config(mv_engine_config_h *engine_cfg)
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- IC_TFLITE_WEIGHT_INCEPTION_V4_299_PATH);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
- IC_LABEL_INCEPTION_V4_299_PATH);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- *engine_cfg = handle;
- return err;
-}
-
-int perform_hosted_tflite_nasnet_config(mv_engine_config_h *engine_cfg)
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- IC_TFLITE_WEIGHT_NASNET_224_PATH);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
- IC_LABEL_NASNET_224_PATH);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- *engine_cfg = handle;
- return err;
-}
-
-int perform_hosted_tflite_mnasnet_config(mv_engine_config_h *engine_cfg)
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- IC_TFLITE_WEIGHT_MNASNET_224_PATH);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
- IC_LABEL_MNASNET_224_PATH);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- *engine_cfg = handle;
- return err;
-}
-
-int perform_hosted_tflite_resnet_config(mv_engine_config_h *engine_cfg)
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- IC_TFLITE_WEIGHT_RESNET_V2_299_PATH);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
- IC_LABEL_RESNET_V2_299_PATH);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- *engine_cfg = handle;
- return err;
-}
-
-int perform_hosted_tflite_squeezenet_config(mv_engine_config_h *engine_cfg)
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- IC_TFLITE_WEIGHT_SQUEEZENET_224_PATH);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
- IC_LABEL_SQUEEZENET_224_PATH);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- *engine_cfg = handle;
- return err;
-}
-
-int perform_image_classification()
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- int sel_opt = 0;
- const char *names[] = { "Configuration",
- "TFLite(cpu + Mobilenet)",
- "OpenCV(cpu + Squeezenet)",
- "ARMNN(cpu + Mobilenet)",
- "ONE(cpu + Mobilenet_Q)",
- "Vivante(NPU + Inceptionv3)",
- "Hosted: TFLite(cpu + Mobilenet V1)", // 7
- "Hosted: TFLite(cpu + Mobilenet V2)",
- "Hosted: TFLite(cpu + Densenet)",
- "Hosted: TFLite(cpu + Inception Resnet)",
- "Hosted: TFLite(cpu + Inception V3)",
- "Hosted: TFLite(cpu + Inception V4)",
- "Hosted: TFLite(cpu + Nasnet)",
- "Hosted: TFLite(cpu + Mnasnet)",
- "Hosted: TFLite(cpu + Resnet)",
- "Hosted: TFLite(cpu + Squeezenet)", //16
- "Prepare",
- "Run",
- "Back" };
-
- mv_engine_config_h engine_cfg = NULL;
- mv_inference_h infer = NULL;
- mv_source_h mvSource = NULL;
-
- while (sel_opt == 0) {
- sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names));
- switch (sel_opt) {
- case 1: {
- //perform configuration
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- engine_cfg = NULL;
- }
-
- err = perform_configuration(&engine_cfg);
- } break;
- case 2: {
- // perform TFLite
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- engine_cfg = NULL;
- }
-
- err = perform_tflite_mobilenetv1_config(&engine_cfg);
- } break;
-
- case 3: {
- // perform OpenCV
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- engine_cfg = NULL;
- }
-
- err = perform_opencv_caffe_squeezenet_config(&engine_cfg);
- } break;
- case 4: {
- // perform ARMNN
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_armnn_mobilenetv1_config(&engine_cfg);
- } break;
- case 5: {
- // perform ONE(On-device Neural Engine)
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_one_mobilenetv1_quant_config(&engine_cfg);
- } break;
- case 6: {
- // perform Vivante
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_vivante_inceptionv3_config(&engine_cfg);
- } break;
- case 7: {
- // perform hosted mobilenetv1
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_hosted_tflite_mobilenetv1_224_config(&engine_cfg);
- } break;
- case 8: {
- // perform hosted mobilenetv2
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_hosted_tflite_mobilenetv2_224_config(&engine_cfg);
- } break;
- case 9: {
- // perform hosted densenet
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_hosted_tflite_densenet_224_config(&engine_cfg);
- } break;
- case 10: {
- // perform hosted inception resnet
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_hosted_tflite_inception_resnet_299_config(&engine_cfg);
- } break;
- case 11: {
- // perform hosted inception v3
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_hosted_tflite_inception_v3_config(&engine_cfg);
- } break;
- case 12: {
- // perform hosted inception v4
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_hosted_tflite_inception_v4_config(&engine_cfg);
- } break;
- case 13: {
- // perform hosted nasnet
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_hosted_tflite_nasnet_config(&engine_cfg);
- } break;
- case 14: {
- // perform hosted mnasnet
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_hosted_tflite_mnasnet_config(&engine_cfg);
- } break;
- case 15: {
- // perform hosted resnet
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_hosted_tflite_resnet_config(&engine_cfg);
- } break;
- case 16: {
- // perform hosted squeezenet
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_hosted_tflite_squeezenet_config(&engine_cfg);
- } break;
- case 17: {
- //create - configure - prepare
- if (infer) {
- int err2 = mv_inference_destroy(infer);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy inference handle [err:%i]\n", err2);
- infer = NULL;
- }
-
- // inference
- // create handle
- err = mv_inference_create(&infer);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create inference handle [err:%i]\n", err);
- break;
- }
-
- // configure
- err = mv_inference_configure(infer, engine_cfg);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to configure inference handle\n");
- break;
- }
-
- // prepare
- err = mv_inference_prepare(infer);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to prepare inference handle.");
- break;
- }
- } break;
- case 18: {
- if (mvSource) {
- int err2 = mv_destroy_source(mvSource);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy mvSource.\n");
- mvSource = NULL;
- }
-
- char *in_file_name = NULL;
- /* Load media source */
- while (input_string("Input file name to be inferred:", 1024,
- &(in_file_name)) == -1)
- printf("Incorrect input! Try again.\n");
-
- err = mv_create_source(&mvSource);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create mvSource.\n");
- free(in_file_name);
- break;
- }
-
- err = load_mv_source_from_file(in_file_name, mvSource);
- if (MEDIA_VISION_ERROR_NONE != err) {
- int err2 = mv_destroy_source(mvSource);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy mvSource. error code:%i\n", err2);
- mvSource = NULL;
- free(in_file_name);
- break;
- }
- free(in_file_name);
-
- struct timespec s_tspec;
- struct timespec e_tspec;
-
- clock_gettime(CLOCK_MONOTONIC, &s_tspec);
-
- // Run
- err = mv_inference_image_classify(mvSource, infer, NULL,
- _image_classified_cb, NULL);
-
- clock_gettime(CLOCK_MONOTONIC, &e_tspec);
-
- struct timespec diffspec = diff(s_tspec, e_tspec);
- unsigned long timeDiff = gettotalmillisec(diffspec);
- printf("elapsed time : %lu(ms)\n", timeDiff);
-
- } break;
- case 19: {
- //perform destroy
- if (engine_cfg) {
- err = mv_destroy_engine_config(engine_cfg);
- if (err != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err);
- engine_cfg = NULL;
- }
-
- if (infer) {
- err = mv_inference_destroy(infer);
- if (err != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy inference handle [err:%i]\n", err);
- infer = NULL;
- }
-
- if (mvSource) {
- err = mv_destroy_source(mvSource);
- if (err != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy mvSource [err:%i]\n", err);
- mvSource = NULL;
- }
- } break;
- default:
- printf("Invalid option.\n");
- sel_opt = 0;
- continue;
- }
-
- int do_another = 0;
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("ERROR: Action is finished with error code:%i\n", err);
- }
-
- sel_opt = 0;
- while (sel_opt == 0) {
- sel_opt = show_menu_yes_or_no("Run Image Classification again?: ");
- switch (sel_opt) {
- case 1:
- do_another = 1;
- break;
- case 2:
- do_another = 0;
- break;
- default:
- printf("Invalid option.\n");
- sel_opt = 0;
- }
- }
-
- sel_opt = (do_another == 1) ? 0 : 1;
- }
-
- if (engine_cfg) {
- err = mv_destroy_engine_config(engine_cfg);
- if (err != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err);
- engine_cfg = NULL;
- }
-
- if (infer) {
- err = mv_inference_destroy(infer);
- if (err != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy inference handle [err:%i]\n", err);
- infer = NULL;
- }
-
- if (mvSource) {
- err = mv_destroy_source(mvSource);
- if (err != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy mvSource [err:%i]\n", err);
- mvSource = NULL;
- }
-
+ IC_OPENCV_CONFIG_CAFFE_PATH));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
+ IC_OPENCV_LABEL_CAFFE_PATH));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_MEAN_VALUE, 0.0));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_STD_VALUE, 1.0));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_OPENCV));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 227));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 227));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName));
+ RET_IF_FAIL(mv_engine_config_set_array_string_attribute(
+ handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1));
return MEDIA_VISION_ERROR_NONE;
}
-/*
- *
- * Object Detection
- *
- */
-int perform_tflite_mobilenetv1ssd_config(mv_engine_config_h *engine_cfg)
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
- const char *inputNodeName = "normalized_input_image_tensor";
- const char *outputNodeName[] = { "TFLite_Detection_PostProcess",
- "TFLite_Detection_PostProcess:1",
- "TFLite_Detection_PostProcess:2",
- "TFLite_Detection_PostProcess:3" };
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, OD_TFLITE_WEIGHT_PATH);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE,
- MV_INFERENCE_DATA_FLOAT32);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH, OD_LABEL_PATH);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE,
- 127.5);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE,
- 127.5);
-
- mv_engine_config_set_double_attribute(
- handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH,
- 300);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT,
- 300);
-
- mv_engine_config_set_int_attribute(handle,
- MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3);
-
- mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME,
- inputNodeName);
-
- mv_engine_config_set_array_string_attribute(
- handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 4);
-
- *engine_cfg = handle;
- return err;
-}
-
-int perform_opencv_mobilenetv1ssd_config(mv_engine_config_h *engine_cfg)
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
- const char *inputNodeName = "data";
- const char *outputNodeName[1] = { "detection_out" };
-
- mv_engine_config_set_string_attribute(handle,
- MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- OD_OPENCV_WEIGHT_CAFFE_PATH);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_CONFIGURATION_FILE_PATH,
- OD_OPENCV_CONFIG_CAFFE_PATH);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE,
- MV_INFERENCE_DATA_FLOAT32);
-
- mv_engine_config_set_string_attribute(handle,
- MV_INFERENCE_MODEL_USER_FILE_PATH,
- OD_OPENCV_LABEL_CAFFE_PATH);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE,
- 127.5);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE,
- 127.5);
-
- mv_engine_config_set_double_attribute(
- handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_OPENCV);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH,
- 300);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT,
- 300);
-
- mv_engine_config_set_int_attribute(handle,
- MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3);
-
- mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME,
- inputNodeName);
-
- mv_engine_config_set_array_string_attribute(
- handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1);
-
- *engine_cfg = handle;
- return err;
-}
-
-int perform_armnn_mobilenetv1ssd_config(mv_engine_config_h *engine_cfg)
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
- const char *inputNodeName = "normalized_input_image_tensor";
- const char *outputNodeName[] = { "TFLite_Detection_PostProcess",
- "TFLite_Detection_PostProcess:1",
- "TFLite_Detection_PostProcess:2",
- "TFLite_Detection_PostProcess:3" };
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, OD_TFLITE_WEIGHT_PATH);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE,
- MV_INFERENCE_DATA_FLOAT32);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH, OD_LABEL_PATH);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE,
- 127.5);
-
- mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE,
- 127.5);
-
- mv_engine_config_set_double_attribute(
- handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_ARMNN);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH,
- 300);
-
- mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT,
- 300);
-
- mv_engine_config_set_int_attribute(handle,
- MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3);
-
- mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME,
- inputNodeName);
-
- mv_engine_config_set_array_string_attribute(
- handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 4);
-
- *engine_cfg = handle;
- return err;
-}
-
-int perform_hosted_tflite_mobilenetv1ssd_300_config(mv_engine_config_h *engine_cfg)
-{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- OD_TFLITE_WEIGHT_MOBILENET_V1_SSD_300_PATH);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
- OD_LABEL_MOBILENET_V1_SSD_300_PATH);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
-
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
-
- *engine_cfg = handle;
- return err;
-}
-
-int perform_hosted_tflite_mobilenetv2ssd_320_config(mv_engine_config_h *engine_cfg)
+int perform_image_classification()
{
int err = MEDIA_VISION_ERROR_NONE;
+ mv_engine_config_h engine_cfg = NULL;
+ const char *names[] = {
+ "TFLite(cpu + Mobilenet)",
+ "OpenCV(cpu + Squeezenet)",
+ "ARMNN(cpu + Mobilenet)",
+ "ONE(cpu + Mobilenet_Q)",
+ "Vivante(NPU + Inceptionv3)",
+ "Hosted: TFLite(cpu + Mobilenet V1)",
+ "Hosted: TFLite(cpu + Mobilenet V2)",
+ "Hosted: TFLite(cpu + Densenet)",
+ "Hosted: TFLite(cpu + Inception Resnet)",
+ "Hosted: TFLite(cpu + Inception V3)",
+ "Hosted: TFLite(cpu + Inception V4)",
+ "Hosted: TFLite(cpu + Nasnet)",
+ "Hosted: TFLite(cpu + Mnasnet)",
+ "Hosted: TFLite(cpu + Resnet)",
+ "Hosted: TFLite(cpu + Squeezenet)",
+ };
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
+ int sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names));
+ if (sel_opt <= 0 || sel_opt > ARRAY_SIZE(names)) {
+ printf("Invalid option");
+ return -1;
}
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- OD_TFLITE_WEIGHT_MOBILENET_V2_SSD_320_PATH);
-
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
- OD_LABEL_MOBILENET_V2_SSD_320_PATH);
+ RET_IF_FAIL(mv_create_engine_config(&engine_cfg));
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
+ switch (sel_opt) {
+ case 1: {
+ err = perform_tflite_mobilenetv1_config(engine_cfg);
+ } break;
+ case 2: {
+ err = perform_opencv_caffe_squeezenet_config(engine_cfg);
+ } break;
+ case 3: {
+ err = perform_armnn_mobilenetv1_config(engine_cfg);
+ } break;
+ case 4: {
+ err = perform_one_mobilenetv1_quant_config(engine_cfg);
+ } break;
+ case 5: {
+ err = perform_vivante_inceptionv3_config(engine_cfg);
+ } break;
+ case 6: {
+ err = engine_config_user_hosted_tflite_cpu(
+ engine_cfg, IC_TFLITE_WEIGHT_MOBILENET_V1_224_PATH,
+ IC_LABEL_MOBILENET_V1_224_PATH);
+ } break;
+ case 7: {
+ err = engine_config_user_hosted_tflite_cpu(
+ engine_cfg, IC_TFLITE_WEIGHT_MOBILENET_V2_224_PATH,
+ IC_LABEL_MOBILENET_V2_224_PATH);
+ } break;
+ case 8: {
+ err = engine_config_user_hosted_tflite_cpu(
+ engine_cfg, IC_TFLITE_WEIGHT_DENSENET_224_PATH,
+ IC_LABEL_DENSENET_224_PATH);
+ } break;
+ case 9: {
+ err = engine_config_user_hosted_tflite_cpu(
+ engine_cfg, IC_TFLITE_WEIGHT_INCEPTION_RESENET_299_PATH,
+ IC_LABEL_INCEPTION_RESENET_299_PATH);
+ } break;
+ case 10: {
+ err = engine_config_user_hosted_tflite_cpu(
+ engine_cfg, IC_TFLITE_WEIGHT_INCEPTION_V3_299_PATH,
+ IC_LABEL_INCEPTION_V3_299_PATH);
+ } break;
+ case 11: {
+ err = engine_config_user_hosted_tflite_cpu(
+ engine_cfg, IC_TFLITE_WEIGHT_INCEPTION_V4_299_PATH,
+ IC_LABEL_INCEPTION_V4_299_PATH);
+ } break;
+ case 12: {
+ err = engine_config_user_hosted_tflite_cpu(
+ engine_cfg, IC_TFLITE_WEIGHT_NASNET_224_PATH,
+ IC_LABEL_NASNET_224_PATH);
+ } break;
+ case 13: {
+ err = engine_config_user_hosted_tflite_cpu(
+ engine_cfg, IC_TFLITE_WEIGHT_MNASNET_224_PATH,
+ IC_LABEL_MNASNET_224_PATH);
+ } break;
+ case 14: {
+ err = engine_config_user_hosted_tflite_cpu(
+ engine_cfg, IC_TFLITE_WEIGHT_RESNET_V2_299_PATH,
+ IC_LABEL_RESNET_V2_299_PATH);
+ } break;
+ case 15: {
+ err = engine_config_user_hosted_tflite_cpu(
+ engine_cfg, IC_TFLITE_WEIGHT_SQUEEZENET_224_PATH,
+ IC_LABEL_SQUEEZENET_224_PATH);
+ } break;
+ }
+ if (err != MEDIA_VISION_ERROR_NONE) {
+ printf("Fail to perform config [err:%i]\n", err);
+ goto clean_image_engine;
+ }
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
+ err = mv_inference_task_helper(engine_cfg, TASK_IC);
+ if (err != MEDIA_VISION_ERROR_NONE)
+ printf("Fail to detect with engine [err:%i]\n", err);
- *engine_cfg = handle;
+clean_image_engine:
+ RET_IF_FAIL(mv_destroy_engine_config(engine_cfg));
return err;
}
-int perform_hosted_tflite_quant_efficient_config(mv_engine_config_h *engine_cfg)
+/*
+ *
+ * Object Detection
+ *
+ */
+int perform_tflite_mobilenetv1ssd_config(mv_engine_config_h handle)
{
- int err = MEDIA_VISION_ERROR_NONE;
-
- mv_engine_config_h handle = NULL;
- err = mv_create_engine_config(&handle);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create engine configuration handle.\n");
- if (handle) {
- int err2 = mv_destroy_engine_config(handle);
- if (err2 != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to destroy engine configuration.\n");
- }
- }
- return err;
- }
+ const char *inputNodeName = "normalized_input_image_tensor";
+ const char *outputNodeName[] = { "TFLite_Detection_PostProcess",
+ "TFLite_Detection_PostProcess:1",
+ "TFLite_Detection_PostProcess:2",
+ "TFLite_Detection_PostProcess:3" };
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
- OD_TFLITE_WEIGHT_QUANT_EFFICIENT_PATH);
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
+ OD_TFLITE_WEIGHT_PATH));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_USER_FILE_PATH, OD_LABEL_PATH));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_MEAN_VALUE, 127.5));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_STD_VALUE, 127.5));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_TFLITE));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 300));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 300));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName));
+ RET_IF_FAIL(mv_engine_config_set_array_string_attribute(
+ handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 4));
+ return MEDIA_VISION_ERROR_NONE;
+}
- mv_engine_config_set_string_attribute(
- handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
- OD_LABEL_QUANT_EFFICIENT_PATH);
+int perform_opencv_mobilenetv1ssd_config(mv_engine_config_h handle)
+{
+ const char *inputNodeName = "data";
+ const char *outputNodeName[1] = { "detection_out" };
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_BACKEND_TYPE,
- MV_INFERENCE_BACKEND_TFLITE);
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
+ OD_OPENCV_WEIGHT_CAFFE_PATH));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_CONFIGURATION_FILE_PATH,
+ OD_OPENCV_CONFIG_CAFFE_PATH));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_USER_FILE_PATH,
+ OD_OPENCV_LABEL_CAFFE_PATH));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_MEAN_VALUE, 127.5));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_STD_VALUE, 127.5));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_OPENCV));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 300));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 300));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName));
+ RET_IF_FAIL(mv_engine_config_set_array_string_attribute(
+ handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1));
+ return MEDIA_VISION_ERROR_NONE;
+}
- mv_engine_config_set_int_attribute(
- handle, MV_INFERENCE_TARGET_TYPE,
- MV_INFERENCE_TARGET_CPU);
+int perform_armnn_mobilenetv1ssd_config(mv_engine_config_h handle)
+{
+ const char *inputNodeName = "normalized_input_image_tensor";
+ const char *outputNodeName[] = { "TFLite_Detection_PostProcess",
+ "TFLite_Detection_PostProcess:1",
+ "TFLite_Detection_PostProcess:2",
+ "TFLite_Detection_PostProcess:3" };
- *engine_cfg = handle;
- return err;
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
+ OD_TFLITE_WEIGHT_PATH));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_MODEL_USER_FILE_PATH, OD_LABEL_PATH));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_MEAN_VALUE, 127.5));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_MODEL_STD_VALUE, 127.5));
+ RET_IF_FAIL(mv_engine_config_set_double_attribute(
+ handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_ARMNN));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 300));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 300));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3));
+ RET_IF_FAIL(mv_engine_config_set_string_attribute(
+ handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName));
+ RET_IF_FAIL(mv_engine_config_set_array_string_attribute(
+ handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 4));
+ return MEDIA_VISION_ERROR_NONE;
}
int perform_object_detection()
{
int err = MEDIA_VISION_ERROR_NONE;
-
- int sel_opt = 0;
- const char *names[] = { "Configuration",
- "TFLITE(CPU) + MobileNetV1+SSD",
- "OPENCV(CPU) + MobileNetV1+SSD",
- "ARMNN(CPU) + MobileNetV1+SSD",
- "Hosted: TFLite(cpu + MobilenetV1+SSD)",
- "Hosted: TFLite(cpu + MobilenetV2+SSD)",
- "Hosted: TFLite(Quant + EfficientDet)",
- "Prepare",
- "Run",
- "Back" };
-
mv_engine_config_h engine_cfg = NULL;
- mv_inference_h infer = NULL;
- mv_source_h mvSource = NULL;
-
- while (sel_opt == 0) {
- sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names));
- switch (sel_opt) {
- case 1: {
- //perform configuration
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- engine_cfg = NULL;
- }
-
- err = perform_configuration(&engine_cfg);
- } break;
- case 2: {
- //perform TFlite MobileSSD config
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- engine_cfg = NULL;
- }
-
- err = perform_tflite_mobilenetv1ssd_config(&engine_cfg);
- } break;
- case 3: {
- //perform OpenCV MobileSSD config
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_opencv_mobilenetv1ssd_config(&engine_cfg);
- } break;
- case 4: {
- //perform ARMNN MobileSSD config
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_armnn_mobilenetv1ssd_config(&engine_cfg);
- } break;
- case 5: {
- //perform hosted mobilenet v1 + ssd
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_hosted_tflite_mobilenetv1ssd_300_config(&engine_cfg);
- } break;
- case 6: {
- //perform hosted mobilenet v2 + ssd
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_hosted_tflite_mobilenetv2ssd_320_config(&engine_cfg);
- } break;
- case 7: {
- //perform hosted quantized efficientdet
- if (engine_cfg) {
- int err2 = mv_destroy_engine_config(engine_cfg);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err2);
- }
-
- err = perform_hosted_tflite_quant_efficient_config(&engine_cfg);
- } break;
- case 8: {
- // create - configure - prepare
- if (infer) {
- int err2 = mv_inference_destroy(infer);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy inference handle [err:%i]\n", err2);
- infer = NULL;
- }
-
- // inference
- // create handle
- err = mv_inference_create(&infer);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create inference handle [err:%i]\n", err);
- break;
- }
-
- //configure
- err = mv_inference_configure(infer, engine_cfg);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to configure inference handle [err:%i]\n", err);
- break;
- }
-
- //prepare
- err = mv_inference_prepare(infer);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to prepare inference handle");
- break;
- }
- } break;
- case 9: {
- if (mvSource) {
- int err2 = mv_destroy_source(mvSource);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy mvSource\n");
- mvSource = NULL;
- }
-
- char *in_file_name = NULL;
- /* Load media source */
- while (input_string("Input file name to be inferred:", 1024,
- &(in_file_name)) == -1)
- printf("Incorrect input! Try again.\n");
-
- err = mv_create_source(&mvSource);
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("Fail to create mvSource.\n");
- free(in_file_name);
- break;
- }
-
- err = load_mv_source_from_file(in_file_name, mvSource);
- if (err != MEDIA_VISION_ERROR_NONE) {
- int err2 = mv_destroy_source(mvSource);
- if (err2 != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy mvSource.\n");
- mvSource = NULL;
- free(in_file_name);
- break;
- }
- free(in_file_name);
-
- struct timespec s_tspec;
- struct timespec e_tspec;
-
- clock_gettime(CLOCK_MONOTONIC, &s_tspec);
-
- // Object Detect
- err = mv_inference_object_detect(mvSource, infer,
- _object_detected_cb, NULL);
-
- clock_gettime(CLOCK_MONOTONIC, &e_tspec);
-
- struct timespec diffspec = diff(s_tspec, e_tspec);
- unsigned long timeDiff = gettotalmillisec(diffspec);
- printf("elapsed time : %lu(ms)\n", timeDiff);
-
- } break;
- case 10: {
- //perform destroy
- if (engine_cfg) {
- err = mv_destroy_engine_config(engine_cfg);
- if (err != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err);
- engine_cfg = NULL;
- }
-
- if (infer) {
- err = mv_inference_destroy(infer);
- if (err != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy inference handle [err:%i]\n", err);
- infer = NULL;
- }
-
- if (mvSource) {
- err = mv_destroy_source(mvSource);
- if (err != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy mvSource.\n");
- mvSource = NULL;
- }
- } break;
- default:
- printf("Invalid option.\n");
- sel_opt = 0;
- continue;
- }
-
- int do_another = 0;
- if (err != MEDIA_VISION_ERROR_NONE) {
- printf("ERROR: Action is finished with error code:%i\n", err);
- }
-
- sel_opt = 0;
- while (sel_opt == 0) {
- sel_opt = show_menu_yes_or_no("Run Object Detection again?:");
- switch (sel_opt) {
- case 1:
- do_another = 1;
- break;
- case 2:
- do_another = 0;
- break;
- default:
- printf("Invalid option.\n");
- sel_opt = 0;
- }
- }
+ const char *names[] = {
+ "TFLITE(CPU) + MobileNetV1+SSD",
+ "OPENCV(CPU) + MobileNetV1+SSD",
+ "ARMNN(CPU) + MobileNetV1+SSD",
+ "Hosted: TFLite(cpu + MobilenetV1+SSD)",
+ "Hosted: TFLite(cpu + MobilenetV2+SSD)",
+ "Hosted: TFLite(Quant + EfficientDet)",
+ };
- sel_opt = (do_another == 1) ? 0 : 1;
+ int sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names));
+ if (sel_opt <= 0 || sel_opt > ARRAY_SIZE(names)) {
+ printf("Invalid option");
+ return -1;
}
- if (engine_cfg) {
- err = mv_destroy_engine_config(engine_cfg);
- if (err != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy engine_cfg [err:%i]\n", err);
- engine_cfg = NULL;
- }
+ RET_IF_FAIL(mv_create_engine_config(&engine_cfg));
- if (infer) {
- err = mv_inference_destroy(infer);
- if (err != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy inference handle [err:%i]\n", err);
- infer = NULL;
+ switch (sel_opt) {
+ case 1: {
+ err = perform_tflite_mobilenetv1ssd_config(engine_cfg);
+ } break;
+ case 2: {
+ err = perform_opencv_mobilenetv1ssd_config(engine_cfg);
+ } break;
+ case 3: {
+ err = perform_armnn_mobilenetv1ssd_config(engine_cfg);
+ } break;
+ case 4: {
+ err = engine_config_user_hosted_tflite_cpu(
+ engine_cfg, OD_TFLITE_WEIGHT_MOBILENET_V1_SSD_300_PATH,
+ OD_LABEL_MOBILENET_V1_SSD_300_PATH);
+ } break;
+ case 5: {
+ err = engine_config_user_hosted_tflite_cpu(
+ engine_cfg, OD_TFLITE_WEIGHT_MOBILENET_V2_SSD_320_PATH,
+ OD_LABEL_MOBILENET_V2_SSD_320_PATH);
+ } break;
+ case 6: {
+ err = engine_config_user_hosted_tflite_cpu(
+ engine_cfg, OD_TFLITE_WEIGHT_QUANT_EFFICIENT_PATH,
+ OD_LABEL_QUANT_EFFICIENT_PATH);
+ } break;
}
-
- if (mvSource) {
- err = mv_destroy_source(mvSource);
- if (err != MEDIA_VISION_ERROR_NONE)
- printf("Fail to destroy mvSource\n");
- mvSource = NULL;
+ if (err != MEDIA_VISION_ERROR_NONE) {
+ printf("Fail to perform config [err:%i]\n", err);
+ goto clean_object_detect_engine;
}
- return MEDIA_VISION_ERROR_NONE;
+ err = mv_inference_task_helper(engine_cfg, TASK_OD);
+ if (err != MEDIA_VISION_ERROR_NONE)
+ printf("Fail to detect with engine [err:%i]\n", err);
+
+clean_object_detect_engine:
+ RET_IF_FAIL(mv_destroy_engine_config(engine_cfg));
+ return err;
}
int perform_tflite_mobilenetv1ssd_face(mv_engine_config_h handle)
return MEDIA_VISION_ERROR_NONE;
}
+int engine_config_user_hosted_tflite_cpu(mv_engine_config_h handle,
+ const char *tf_weight,
+ const char *user_file)
+{
+ RET_IF_FAIL(engine_config_hosted_tflite_cpu(handle, tf_weight));
+ RET_IF_FAIL(mv_engine_config_set_int_attribute(
+ handle, MV_INFERENCE_MODEL_USER_FILE_PATH, user_file));
+ return MEDIA_VISION_ERROR_NONE;
+}
+
int perform_armnn_cpm_config(mv_engine_config_h handle)
{
const char *inputNodeName = "image";