From fcc67263d974b02daad608a86d0e13955a176c78 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Fri, 9 Apr 2021 17:03:17 +0900 Subject: [PATCH 01/16] Output layer names should be updated by a metafile if it exist Change-Id: I06ae65a07528163cdff0a5fc211e129b6f9607ca Signed-off-by: Tae-Young Chung --- mv_inference/inference/src/Inference.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mv_inference/inference/src/Inference.cpp b/mv_inference/inference/src/Inference.cpp index d430f5d..820ce70 100644 --- a/mv_inference/inference/src/Inference.cpp +++ b/mv_inference/inference/src/Inference.cpp @@ -467,13 +467,19 @@ namespace inference mConfig.mOutputLayerNames = names; + const OutputMetadata& outputMeta = mMetadata.GetOutputMeta(); + if (outputMeta.parsed) { + mConfig.mOutputLayerNames.clear(); + mConfig.mOutputLayerNames.push_back(outputMeta.score.name); + } + inference_engine_layer_property property; inference_engine_tensor_info tensor_info = { std::vector{1}, INFERENCE_TENSOR_SHAPE_NCHW, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, 1}; - for (auto& name : names) { + for (auto& name : mConfig.mOutputLayerNames) { property.layers.insert(std::make_pair(name, tensor_info)); } -- 2.7.4 From 6f7034c886f730ea24658bfa5e1e8dc21f9da688 Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Mon, 12 Apr 2021 10:46:38 +0900 Subject: [PATCH 02/16] [MVQA] Add barcode and face detection Change-Id: Icb8be5d0eed217b5b06861cd1c21d61030ad79a2 Signed-off-by: Kwang Son --- script/mvqa/db.py | 132 +++++++++++++++++++++++++++++++++++++++++++++++++---- script/mvqa/run.py | 10 ++-- 2 files changed, 130 insertions(+), 12 deletions(-) diff --git a/script/mvqa/db.py b/script/mvqa/db.py index 6c58ffd..2394f0d 100644 --- a/script/mvqa/db.py +++ b/script/mvqa/db.py @@ -1,16 +1,17 @@ import sqlite3 import os +import glob +import subprocess DB_PATH = 'mvqa.db' +WIDER_FACE_PREFIX = '/opt/mvdata/WIDER_face/WIDER_val/images/' -dataset = [('Artelab', 1000), - ('ILSVRC2012', 1000), - ('COCO', 500), - ('openimages', 500), +dataset = [('Artelab', 430), + ('WIDER_face', 3226), ] -testset = [('facedetection - CPU',), - ('facedetection - GPU',), +testset = [('barcode detect',), + ('facedetection(cascade) - CPU',), ] @@ -51,7 +52,10 @@ def create(): '''CREATE TABLE 'performance'( id integer PRIMARY KEY, benchmark_id integer NOT NULL, - data text)''') + millisecond integer NOT NULL, + data text NOT NULL, + label text NOT NULL, + note text)''') conn.commit() conn.close() @@ -92,12 +96,122 @@ def insert_benchmark(dataset_id, testset_id, target): return id -def insert_performance(bench_id, text): +def insert_performance(bench_id, time, data, label, text): if not exist(): create() conn = sqlite3.connect(DB_PATH) c = conn.cursor() c.execute( - 'INSERT INTO performance VALUES (null,?,?)', (bench_id, text)) + 'INSERT INTO performance VALUES (null,?,?,?,?,?)', (bench_id, time, data, label, text)) conn.commit() conn.close() + + +def get_all_item(dataset_id): + items = [] + if (dataset_id is 1): + images = glob.glob('/opt/mvdata/ArteLab1D/BarcodeDatasets/*/*.jpg') + for image in images: + items.append((image, image + '.txt')) + return items + elif (dataset_id is 2): + with open('/opt/mvdata/WIDER_face/wider_face_split/wider_face_val_bbx_gt.txt') as f: + bbox = f.readlines() + idx = 0 + while(idx < len(bbox)): + mdata = bbox[idx][:-1] + idx += 1 + cnt = int(bbox[idx]) + idx += 1 + mlabel = bbox[idx:idx+cnt] + slabel = '' + for ele in mlabel: + slabel += ele + idx += cnt + items.append((mdata, slabel)) + return items + else: + raise NotImplementedError + + +class Session: + def __init__(self, dataset_id, testset_id): + self.dataset_id = dataset_id + self.testset_id = testset_id + os.system('sdb shell rm -rf /opt/mvdata') + + def load(self): + pass + + def run(self, item): + pass + + def clean(self, item): + pass + + def verify(self, result, label): + pass + + +class Barcode(Session): + def __init__(self, dataset_id, testset_id): + super().__init__(dataset_id, testset_id) + + def load(self, item): + os.system('sdb push ' + item + ' ' + item) + + def run(self, item): + return subprocess.check_output('sdb shell mv_barcode_assessment ' + item, shell=True) + + def clean(self, item): + os.system('sdb shell rm ' + item) + + def verify(self, result, label): + reform = result.decode('utf-8').split() + with open(label) as f: + ans = f.read().split() + print('result : {} label : {} reform : {} ans : {}'.format( + result, label, reform, ans)) + if(len(ans) != int(reform[0])): + return int(reform[-1][:-2]), 'Fail' + else: + for idx, code in enumerate(ans): + if(reform[idx + 1] != code): + return int(reform[-1][:-2]), 'Fail' + return int(reform[-1][:-2]), 'Pass' + + +class FaceCascadeDetection(Session): + def __init__(self, dataset_id, testset_id): + super().__init__(dataset_id, testset_id) + dirs = glob.glob('/opt/mvdata/WIDER_face/WIDER_val/images/*') + for dir in dirs: + os.system('sdb shell mkdir -p ' + dir) + + def load(self, item): + os.system('sdb push ' + WIDER_FACE_PREFIX + + item + ' ' + WIDER_FACE_PREFIX + item) + + def run(self, item): + return subprocess.check_output('sdb shell mv_face_assessment ' + WIDER_FACE_PREFIX + item + ' 0', shell=True) + + def clean(self, item): + os.system('sdb shell rm ' + WIDER_FACE_PREFIX + item) + + def verify(self, result, label): + """ + https://github.com/Cartucho/mAP + """ + rv = result.decode('utf-8') + reform = rv.split() + task_time = reform[-1][:-2] + return (task_time, rv) + + +def get_session(dataset_id, testset_id): + if(dataset_id == 1): + return Barcode(dataset_id, testset_id) + elif(dataset_id == 2): + return FaceCascadeDetection(dataset_id, testset_id) + else: + raise NotImplementedError diff --git a/script/mvqa/run.py b/script/mvqa/run.py index 8742baa..80254d9 100644 --- a/script/mvqa/run.py +++ b/script/mvqa/run.py @@ -13,6 +13,10 @@ def run_bench(dataset_id, testset_id): # check dataset is fit with testset # check dataset is ready bench_id = db.insert_benchmark(dataset_id, testset_id, target_type) - # insert result - for _ in range(5): - db.insert_performance(bench_id, "Pass, 1.5MB, 10s, ...") + sess = db.get_session(dataset_id, testset_id) + for data, label in db.get_all_item(dataset_id): + sess.load(data) + result = sess.run(data) + sess.clean(data) + ms, save = sess.verify(result, label) + # db.insert_performance(bench_id, ms, data, label, save) -- 2.7.4 From 0bb441f4b670d2735130f30c6264bc1af91a54a0 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Fri, 9 Apr 2021 17:17:37 +0900 Subject: [PATCH 03/16] Add meta files for google hosted models and update testsuite Added meta files which support google hosted models for image classification, and update testsuite to run the models with meta files. Change-Id: If171f82501cfa3b7246358341d30b547d5f1c701 Signed-off-by: Tae-Young Chung --- meta-template/README.md | 15 + meta-template/ic_densenet_224x224.json | 36 ++ meta-template/ic_inception_resnet_v2_299x299.json | 36 ++ meta-template/ic_inception_v3_299x299.json | 36 ++ meta-template/ic_inception_v4_299x299.json | 36 ++ meta-template/ic_mnasnet_224x224.json | 36 ++ meta-template/ic_mobilenet_v1_224x224.json | 36 ++ meta-template/ic_mobilenet_v2_224x224.json | 36 ++ meta-template/ic_nasnet_224x224.json | 36 ++ meta-template/ic_resnet_v2_299x299.json | 36 ++ meta-template/ic_squeezenet_224x224.json | 36 ++ test/testsuites/inference/inference_test_suite.c | 562 +++++++++++++++++++++- 12 files changed, 919 insertions(+), 18 deletions(-) create mode 100644 meta-template/ic_densenet_224x224.json create mode 100644 meta-template/ic_inception_resnet_v2_299x299.json create mode 100644 meta-template/ic_inception_v3_299x299.json create mode 100644 meta-template/ic_inception_v4_299x299.json create mode 100644 meta-template/ic_mnasnet_224x224.json create mode 100644 meta-template/ic_mobilenet_v1_224x224.json create mode 100644 meta-template/ic_mobilenet_v2_224x224.json create mode 100644 meta-template/ic_nasnet_224x224.json create mode 100644 meta-template/ic_resnet_v2_299x299.json create mode 100644 meta-template/ic_squeezenet_224x224.json diff --git a/meta-template/README.md b/meta-template/README.md index e6927d6..1e31cfc 100644 --- a/meta-template/README.md +++ b/meta-template/README.md @@ -122,3 +122,18 @@ in `score`. You can get real value `value` : The classification meta file, thus, illustrates that the model has an input which is named of `input`, `NHWC` shape type with `[1, 224, 224, 3]` dimensions, `MV_INFERENCE_DATA_UINT8` data type, and `RGB888` color space. It requires any preprocess. The meta file illustrates that the model has an ouput which is named of `MobilenetV1/Predictions/Reshape_1`. The tensor is 2-dimensional and its' 2nd index corresponds to the score. In addition, the score is just between 0 ~ 1, but the value requires dequantization with scale and zeropoint values. The score after dequantizing under `threshold`0.3 should be thrown out and the `top_number` of outputs should be given as results. + +To show how to apply meta files to well-know models, we provide example meta files which support google hosted models for image classification as: + +* ic_densenet_224x224.json +* ic_inception_resnet_v2_299x299.json +* ic_inception_v3_299x299.json +* ic_inception_v4_299x299.json +* ic_mnasnet_224x224.json +* ic_mobilenet_v1_224x224.json +* ic_mobilenet_v2_224x224.json +* ic_nasnet_224x224.json +* ic_resnet_v2_299x299.json +* ic_squeezenet_224x224.json + +You can download the models from [Floating point models](https://www.tensorflow.org/lite/guide/hosted_models#floating_point_models) and [AutoML mobile models](https://www.tensorflow.org/lite/guide/hosted_models#automl_mobile_models) and run the them with our meta files. diff --git a/meta-template/ic_densenet_224x224.json b/meta-template/ic_densenet_224x224.json new file mode 100644 index 0000000..9a69d01 --- /dev/null +++ b/meta-template/ic_densenet_224x224.json @@ -0,0 +1,36 @@ +{ + "inputmetadata" : + { + "tensor_info" : [ + { + "name" : "Placeholder", + "shape_type" : 1, + "shape_dims" : [ 1, 224, 224, 3], + "data_type" : 0, + "color_space" : "RGB888" + } + ], + "preprocess" : [ + { + "normalization" : [ + { + "mean" : [123.68, 116.78, 103.94], + "std" : [255.0, 255.0, 255.0] + } + ] + } + ] + }, + "outputmetadata" : + { + "score" : [ + { + "name" : "softmax_tensor", + "index" : [-1, 1], + "top_number" : 5, + "threshold" : 0.6, + "score_type" : 0 + } + ] + } +} diff --git a/meta-template/ic_inception_resnet_v2_299x299.json b/meta-template/ic_inception_resnet_v2_299x299.json new file mode 100644 index 0000000..87d87da --- /dev/null +++ b/meta-template/ic_inception_resnet_v2_299x299.json @@ -0,0 +1,36 @@ +{ + "inputmetadata" : + { + "tensor_info" : [ + { + "name" : "input", + "shape_type" : 1, + "shape_dims" : [ 1, 299, 299, 3], + "data_type" : 0, + "color_space" : "RGB888" + } + ], + "preprocess" : [ + { + "normalization" : [ + { + "mean" : [127.5, 127.5, 127.5], + "std" : [127.5, 127.5, 127.5] + } + ] + } + ] + }, + "outputmetadata" : + { + "score" : [ + { + "name" : "InceptionResnetV2/AuxLogits/Logits/BiasAdd", + "index" : [-1, 1], + "top_number" : 5, + "threshold" : 0.6, + "score_type" : 1 + } + ] + } +} diff --git a/meta-template/ic_inception_v3_299x299.json b/meta-template/ic_inception_v3_299x299.json new file mode 100644 index 0000000..7c2ef9f --- /dev/null +++ b/meta-template/ic_inception_v3_299x299.json @@ -0,0 +1,36 @@ +{ + "inputmetadata" : + { + "tensor_info" : [ + { + "name" : "input", + "shape_type" : 1, + "shape_dims" : [ 1, 299, 299, 3], + "data_type" : 0, + "color_space" : "RGB888" + } + ], + "preprocess" : [ + { + "normalization" : [ + { + "mean" : [127.5, 127.5, 127.5], + "std" : [127.5, 127.5, 127.5] + } + ] + } + ] + }, + "outputmetadata" : + { + "score" : [ + { + "name" : "InceptionV3/Predictions/Reshape_1", + "index" : [-1, 1], + "top_number" : 5, + "threshold" : 0.6, + "score_type" : 0 + } + ] + } +} diff --git a/meta-template/ic_inception_v4_299x299.json b/meta-template/ic_inception_v4_299x299.json new file mode 100644 index 0000000..8cd3f47 --- /dev/null +++ b/meta-template/ic_inception_v4_299x299.json @@ -0,0 +1,36 @@ +{ + "inputmetadata" : + { + "tensor_info" : [ + { + "name" : "input", + "shape_type" : 1, + "shape_dims" : [ 1, 299, 299, 3], + "data_type" : 0, + "color_space" : "RGB888" + } + ], + "preprocess" : [ + { + "normalization" : [ + { + "mean" : [127.5, 127.5, 127.5], + "std" : [127.5, 127.5, 127.5] + } + ] + } + ] + }, + "outputmetadata" : + { + "score" : [ + { + "name" : "InceptionV4/Logits/Predictions", + "index" : [-1, 1], + "top_number" : 5, + "threshold" : 0.6, + "score_type" : 0 + } + ] + } +} diff --git a/meta-template/ic_mnasnet_224x224.json b/meta-template/ic_mnasnet_224x224.json new file mode 100644 index 0000000..83938df --- /dev/null +++ b/meta-template/ic_mnasnet_224x224.json @@ -0,0 +1,36 @@ +{ + "inputmetadata" : + { + "tensor_info" : [ + { + "name" : "input", + "shape_type" : 1, + "shape_dims" : [ 1, 224, 224, 3], + "data_type" : 0, + "color_space" : "RGB888" + } + ], + "preprocess" : [ + { + "normalization" : [ + { + "mean" : [123.675, 116.279, 103.529], + "std" : [58.395, 57.119, 57.375] + } + ] + } + ] + }, + "outputmetadata" : + { + "score" : [ + { + "name" : "output", + "index" : [-1, 1], + "top_number" : 5, + "threshold" : 0.6, + "score_type" : 1 + } + ] + } +} diff --git a/meta-template/ic_mobilenet_v1_224x224.json b/meta-template/ic_mobilenet_v1_224x224.json new file mode 100644 index 0000000..2599d8c --- /dev/null +++ b/meta-template/ic_mobilenet_v1_224x224.json @@ -0,0 +1,36 @@ +{ + "inputmetadata" : + { + "tensor_info" : [ + { + "name" : "input", + "shape_type" : 1, + "shape_dims" : [ 1, 224, 224, 3], + "data_type" : 0, + "color_space" : "RGB888" + } + ], + "preprocess" : [ + { + "normalization" : [ + { + "mean" : [127.5, 127.5, 127.5], + "std" : [127.5, 127.5, 127.5] + } + ] + } + ] + }, + "outputmetadata" : + { + "score" : [ + { + "name" : "MobilenetV1/Predictions/Reshape_1", + "index" : [-1, 1], + "top_number" : 5, + "threshold" : 0.6, + "score_type" : 0 + } + ] + } +} diff --git a/meta-template/ic_mobilenet_v2_224x224.json b/meta-template/ic_mobilenet_v2_224x224.json new file mode 100644 index 0000000..c0c976b --- /dev/null +++ b/meta-template/ic_mobilenet_v2_224x224.json @@ -0,0 +1,36 @@ +{ + "inputmetadata" : + { + "tensor_info" : [ + { + "name" : "input", + "shape_type" : 1, + "shape_dims" : [ 1, 224, 224, 3], + "data_type" : 0, + "color_space" : "RGB888" + } + ], + "preprocess" : [ + { + "normalization" : [ + { + "mean" : [127.5, 127.5, 127.5], + "std" : [127.5, 127.5, 127.5] + } + ] + } + ] + }, + "outputmetadata" : + { + "score" : [ + { + "name" : "MobilenetV2/Predictions/Reshape_1", + "index" : [-1, 1], + "top_number" : 5, + "threshold" : 0.6, + "score_type" : 0 + } + ] + } +} diff --git a/meta-template/ic_nasnet_224x224.json b/meta-template/ic_nasnet_224x224.json new file mode 100644 index 0000000..8448561 --- /dev/null +++ b/meta-template/ic_nasnet_224x224.json @@ -0,0 +1,36 @@ +{ + "inputmetadata" : + { + "tensor_info" : [ + { + "name" : "input", + "shape_type" : 1, + "shape_dims" : [ 1, 224, 224, 3], + "data_type" : 0, + "color_space" : "RGB888" + } + ], + "preprocess" : [ + { + "normalization" : [ + { + "mean" : [127.5, 127.5, 127.5], + "std" : [127.5, 127.5, 127.5] + } + ] + } + ] + }, + "outputmetadata" : + { + "score" : [ + { + "name" : "final_layer/predictions", + "index" : [-1, 1], + "top_number" : 5, + "threshold" : 0.6, + "score_type" : 0 + } + ] + } +} diff --git a/meta-template/ic_resnet_v2_299x299.json b/meta-template/ic_resnet_v2_299x299.json new file mode 100644 index 0000000..865652c --- /dev/null +++ b/meta-template/ic_resnet_v2_299x299.json @@ -0,0 +1,36 @@ +{ + "inputmetadata" : + { + "tensor_info" : [ + { + "name" : "input", + "shape_type" : 1, + "shape_dims" : [ 1, 299, 299, 3], + "data_type" : 0, + "color_space" : "RGB888" + } + ], + "preprocess" : [ + { + "normalization" : [ + { + "mean" : [127.5, 127.5, 127.5], + "std" : [127.5, 127.5, 127.5] + } + ] + } + ] + }, + "outputmetadata" : + { + "score" : [ + { + "name" : "output", + "index" : [-1, 1], + "top_number" : 5, + "threshold" : 0.6, + "score_type" : 1 + } + ] + } +} diff --git a/meta-template/ic_squeezenet_224x224.json b/meta-template/ic_squeezenet_224x224.json new file mode 100644 index 0000000..fdf00e2 --- /dev/null +++ b/meta-template/ic_squeezenet_224x224.json @@ -0,0 +1,36 @@ +{ + "inputmetadata" : + { + "tensor_info" : [ + { + "name" : "Placeholder", + "shape_type" : 1, + "shape_dims" : [ 1, 224, 224, 3], + "data_type" : 0, + "color_space" : "RGB888" + } + ], + "preprocess" : [ + { + "normalization" : [ + { + "mean" : [127.5, 127.5, 127.5], + "std" : [127.5, 127.5, 127.5] + } + ] + } + ] + }, + "outputmetadata" : + { + "score" : [ + { + "name" : "softmax_tensor", + "index" : [-1, 1], + "top_number" : 5, + "threshold" : 0.3, + "score_type" : 0 + } + ] + } +} diff --git a/test/testsuites/inference/inference_test_suite.c b/test/testsuites/inference/inference_test_suite.c index e006c6a..eb1e5bb 100644 --- a/test/testsuites/inference/inference_test_suite.c +++ b/test/testsuites/inference/inference_test_suite.c @@ -44,6 +44,49 @@ #define IC_Q_TFLITE_WEIGHT_PATH \ "/usr/share/capi-media-vision/models/IC_Q/tflite/ic_tflite_model.tflite" +/* + * Hosted models + */ +#define IC_LABEL_MOBILENET_V1_224_PATH\ + "/usr/share/capi-media-vision/models/IC/tflite/ic_mobilenet_v1_label.txt" +#define IC_TFLITE_WEIGHT_MOBILENET_V1_224_PATH \ + "/usr/share/capi-media-vision/models/IC/tflite/ic_mobilenet_v1_224x224.tflite" +#define IC_LABEL_MOBILENET_V2_224_PATH\ + "/usr/share/capi-media-vision/models/IC/tflite/ic_mobilenet_v2_label.txt" +#define IC_TFLITE_WEIGHT_MOBILENET_V2_224_PATH \ + "/usr/share/capi-media-vision/models/IC/tflite/ic_mobilenet_v2_224x224.tflite" +#define IC_LABEL_DENSENET_224_PATH\ + "/usr/share/capi-media-vision/models/IC/tflite/ic_densenet_label.txt" +#define IC_TFLITE_WEIGHT_DENSENET_224_PATH \ + "/usr/share/capi-media-vision/models/IC/tflite/ic_densenet_224x224.tflite" +#define IC_LABEL_INCEPTION_RESENET_299_PATH\ + "/usr/share/capi-media-vision/models/IC/tflite/ic_densenet_label.txt" +#define IC_TFLITE_WEIGHT_INCEPTION_RESENET_299_PATH \ + "/usr/share/capi-media-vision/models/IC/tflite/ic_inception_resnet_v2_299x299.tflite" +#define IC_LABEL_INCEPTION_V3_299_PATH\ + "/usr/share/capi-media-vision/models/IC/tflite/ic_inception_v3_label.txt" +#define IC_TFLITE_WEIGHT_INCEPTION_V3_299_PATH \ + "/usr/share/capi-media-vision/models/IC/tflite/ic_inception_v3_299x299.tflite" +#define IC_LABEL_INCEPTION_V4_299_PATH\ + "/usr/share/capi-media-vision/models/IC/tflite/ic_inception_v4_label.txt" +#define IC_TFLITE_WEIGHT_INCEPTION_V4_299_PATH \ + "/usr/share/capi-media-vision/models/IC/tflite/ic_inception_v4_299x299.tflite" +#define IC_LABEL_NASNET_224_PATH\ + "/usr/share/capi-media-vision/models/IC/tflite/ic_nasnet_label.txt" +#define IC_TFLITE_WEIGHT_NASNET_224_PATH \ + "/usr/share/capi-media-vision/models/IC/tflite/ic_nasnet_224x224.tflite" +#define IC_LABEL_MNASNET_224_PATH\ + "/usr/share/capi-media-vision/models/IC/tflite/ic_mnasnet_label.txt" +#define IC_TFLITE_WEIGHT_MNASNET_224_PATH \ + "/usr/share/capi-media-vision/models/IC/tflite/ic_mnasnet_224x224.tflite" +#define IC_LABEL_RESNET_V2_299_PATH\ + "/usr/share/capi-media-vision/models/IC/tflite/ic_resnet_v2_label.txt" +#define IC_TFLITE_WEIGHT_RESNET_V2_299_PATH \ + "/usr/share/capi-media-vision/models/IC/tflite/ic_resnet_v2_299x299.tflite" +#define IC_LABEL_SQUEEZENET_224_PATH\ + "/usr/share/capi-media-vision/models/IC/tflite/ic_squeezenet_label.txt" +#define IC_TFLITE_WEIGHT_SQUEEZENET_224_PATH \ + "/usr/share/capi-media-vision/models/IC/tflite/ic_squeezenet_224x224.tflite" #define IC_VIVANTE_LABEL_PATH \ "/usr/share/capi-media-vision/models/IC/vivante/ic_label.txt" @@ -508,7 +551,7 @@ int perform_configuration(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; @@ -590,7 +633,7 @@ int perform_tflite_mobilenetv1_config(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; @@ -653,7 +696,7 @@ int perform_armnn_mobilenetv1_config(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; @@ -716,7 +759,7 @@ int perform_one_mobilenetv1_quant_config(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; @@ -779,7 +822,7 @@ int perform_vivante_inceptionv3_config(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; @@ -847,7 +890,7 @@ int perform_opencv_caffe_squeezenet_config(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; @@ -905,18 +948,401 @@ int perform_opencv_caffe_squeezenet_config(mv_engine_config_h *engine_cfg) 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 int options[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + const int options[] = { 1, 2, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19 }; 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" }; @@ -994,6 +1420,106 @@ int perform_image_classification() 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); @@ -1024,7 +1550,7 @@ int perform_image_classification() break; } } break; - case 8: { + case 18: { if (mvSource) { int err2 = mv_destroy_source(mvSource); if (err2 != MEDIA_VISION_ERROR_NONE) @@ -1072,7 +1598,7 @@ int perform_image_classification() printf("elapsed time : %lu(ms)\n", timeDiff); } break; - case 9: { + case 19: { //perform destroy if (engine_cfg) { err = mv_destroy_engine_config(engine_cfg); @@ -1170,7 +1696,7 @@ int perform_tflite_mobilenetv1ssd_config(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; @@ -1236,7 +1762,7 @@ int perform_opencv_mobilenetv1ssd_config(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; @@ -1305,7 +1831,7 @@ int perform_armnn_mobilenetv1ssd_config(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; @@ -1597,7 +2123,7 @@ int perform_tflite_mobilenetv1ssd_face(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; @@ -1660,7 +2186,7 @@ int perform_opencv_resnet10ssd_face(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; @@ -1725,7 +2251,7 @@ int perform_armnn_mobilenetv1ssd_face(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; @@ -2011,7 +2537,7 @@ int perform_tflite_TweakCNN(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; @@ -2069,7 +2595,7 @@ int perform_opencv_cnncascade(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; @@ -2342,7 +2868,7 @@ int perform_armnn_cpm_config(mv_engine_config_h *engine_cfg) if (handle) { int err2 = mv_destroy_engine_config(handle); if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine cofniguration.\n"); + printf("Fail to destroy engine configuration.\n"); } } return err; -- 2.7.4 From 790d4193377b80063680ae03dd19e5d505bda7dd Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Tue, 13 Apr 2021 16:36:45 +0900 Subject: [PATCH 04/16] Change load data method - Change method to download single data of dataset from NAS server Change-Id: I69c46a9ab1761bdf80e3ff4913dad93de8afcaef Signed-off-by: Kwang Son --- script/mvqa/db.py | 105 ++++++++++++++++++++++++------------------------- script/mvqa/run.py | 6 +-- script/nas_config.json | 6 +++ 3 files changed, 60 insertions(+), 57 deletions(-) create mode 100644 script/nas_config.json diff --git a/script/mvqa/db.py b/script/mvqa/db.py index 2394f0d..f7c35b5 100644 --- a/script/mvqa/db.py +++ b/script/mvqa/db.py @@ -1,13 +1,12 @@ import sqlite3 import os -import glob import subprocess +import json DB_PATH = 'mvqa.db' -WIDER_FACE_PREFIX = '/opt/mvdata/WIDER_face/WIDER_val/images/' -dataset = [('Artelab', 430), - ('WIDER_face', 3226), +dataset = [('Artelab',), + ('WIDER_face',), ] testset = [('barcode detect',), @@ -28,9 +27,8 @@ def create(): c.execute( '''CREATE TABLE 'dataset'( id integer PRIMARY KEY, - name text NOT NULL, - size integer NOT NULL)''') - c.executemany('INSERT INTO dataset VALUES (null,?,?)', dataset) + name text NOT NULL)''') + c.executemany('INSERT INTO dataset VALUES (null,?)', dataset) conn.commit() c.execute( @@ -67,7 +65,7 @@ def print_dataset_list(): c = conn.cursor() ret = c.execute('SELECT * FROM dataset') for row in ret: - print(row[:2]) + print(row) conn.close() @@ -107,38 +105,16 @@ def insert_performance(bench_id, time, data, label, text): conn.close() -def get_all_item(dataset_id): - items = [] - if (dataset_id is 1): - images = glob.glob('/opt/mvdata/ArteLab1D/BarcodeDatasets/*/*.jpg') - for image in images: - items.append((image, image + '.txt')) - return items - elif (dataset_id is 2): - with open('/opt/mvdata/WIDER_face/wider_face_split/wider_face_val_bbx_gt.txt') as f: - bbox = f.readlines() - idx = 0 - while(idx < len(bbox)): - mdata = bbox[idx][:-1] - idx += 1 - cnt = int(bbox[idx]) - idx += 1 - mlabel = bbox[idx:idx+cnt] - slabel = '' - for ele in mlabel: - slabel += ele - idx += cnt - items.append((mdata, slabel)) - return items - else: - raise NotImplementedError - - class Session: def __init__(self, dataset_id, testset_id): self.dataset_id = dataset_id self.testset_id = testset_id + assert(os.path.exists('nas_config.json')) + with open('nas_config.json') as f: + nas_config = json.load(f) + self.nas_config = nas_config os.system('sdb shell rm -rf /opt/mvdata') + os.system('rm -f db_meta.json') def load(self): pass @@ -152,27 +128,50 @@ class Session: def verify(self, result, label): pass + def get_db_meta(self): + self.remote_db = 'wget --user=' + self.nas_config['user'] + ' --password=' + self.nas_config['password'] + \ + ' ftp://' + self.nas_config['ip'] + ':' + \ + self.nas_config['db_index_path'] + '/' + \ + dataset[self.dataset_id - 1][0] + '/' + os.system(self.remote_db + 'db_meta.json') + with open('db_meta.json') as f: + meta = json.load(f) + os.system('rm db_meta.json') + return meta['data'] + class Barcode(Session): def __init__(self, dataset_id, testset_id): super().__init__(dataset_id, testset_id) def load(self, item): - os.system('sdb push ' + item + ' ' + item) + item = item.replace('(', '\(') + item = item.replace(')', '\)') + file_path = os.path.basename(item) + os.system(self.remote_db + item) + os.system('sdb push ' + file_path + ' /tmp/' + file_path) def run(self, item): - return subprocess.check_output('sdb shell mv_barcode_assessment ' + item, shell=True) + item = item.replace('(', '\(') + item = item.replace(')', '\)') + file_path = os.path.basename(item) + return subprocess.check_output('sdb shell mv_barcode_assessment "/tmp/' + file_path + '"', shell=True) def clean(self, item): - os.system('sdb shell rm ' + item) + item = item.replace('(', '\(') + item = item.replace(')', '\)') + file_path = os.path.basename(item) + os.system('sdb shell rm "/tmp/' + file_path + '"') + os.system('rm ' + file_path) def verify(self, result, label): reform = result.decode('utf-8').split() - with open(label) as f: - ans = f.read().split() - print('result : {} label : {} reform : {} ans : {}'.format( - result, label, reform, ans)) - if(len(ans) != int(reform[0])): + ans = label.split() + try: + cnt = int(reform[0]) + except: + return int(reform[-1][:-2]), 'Fatal' + if(len(ans) != cnt): return int(reform[-1][:-2]), 'Fail' else: for idx, code in enumerate(ans): @@ -184,27 +183,25 @@ class Barcode(Session): class FaceCascadeDetection(Session): def __init__(self, dataset_id, testset_id): super().__init__(dataset_id, testset_id) - dirs = glob.glob('/opt/mvdata/WIDER_face/WIDER_val/images/*') - for dir in dirs: - os.system('sdb shell mkdir -p ' + dir) def load(self, item): - os.system('sdb push ' + WIDER_FACE_PREFIX + - item + ' ' + WIDER_FACE_PREFIX + item) + file_path = os.path.basename(item) + os.system(self.remote_db + item) + os.system('sdb push ' + file_path + ' /tmp/' + file_path) def run(self, item): - return subprocess.check_output('sdb shell mv_face_assessment ' + WIDER_FACE_PREFIX + item + ' 0', shell=True) + file_path = os.path.basename(item) + return subprocess.check_output('sdb shell mv_face_assessment /tmp/' + file_path + ' 0', shell=True) def clean(self, item): - os.system('sdb shell rm ' + WIDER_FACE_PREFIX + item) + file_path = os.path.basename(item) + os.system('sdb shell rm /tmp/' + file_path) + os.system('rm ' + file_path) def verify(self, result, label): - """ - https://github.com/Cartucho/mAP - """ rv = result.decode('utf-8') reform = rv.split() - task_time = reform[-1][:-2] + task_time = int(reform[-1][:-2]) return (task_time, rv) diff --git a/script/mvqa/run.py b/script/mvqa/run.py index 80254d9..e8dc2eb 100644 --- a/script/mvqa/run.py +++ b/script/mvqa/run.py @@ -12,11 +12,11 @@ def run_bench(dataset_id, testset_id): 'sdb devices | tail -1 | cut -f 3', shell=True) # check dataset is fit with testset # check dataset is ready - bench_id = db.insert_benchmark(dataset_id, testset_id, target_type) sess = db.get_session(dataset_id, testset_id) - for data, label in db.get_all_item(dataset_id): + bench_id = db.insert_benchmark(dataset_id, testset_id, target_type) + for data, label in sess.get_db_meta(): sess.load(data) result = sess.run(data) sess.clean(data) ms, save = sess.verify(result, label) - # db.insert_performance(bench_id, ms, data, label, save) + db.insert_performance(bench_id, ms, data, label, save) diff --git a/script/nas_config.json b/script/nas_config.json new file mode 100644 index 0000000..77bf042 --- /dev/null +++ b/script/nas_config.json @@ -0,0 +1,6 @@ +{ + "user": "", + "password": "", + "ip": "", + "db_index_path": "" +} \ No newline at end of file -- 2.7.4 From 93dd9357b1c23bb24b029ae3df8cbd77f4b3f276 Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Tue, 20 Apr 2021 13:27:39 +0900 Subject: [PATCH 05/16] Add Face detection using TFlite Change-Id: I62f9de68a9d101525e2fc0df0f5791d2ed1d4f4a Signed-off-by: Kwang Son --- script/mvqa/db.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/script/mvqa/db.py b/script/mvqa/db.py index f7c35b5..ce55aee 100644 --- a/script/mvqa/db.py +++ b/script/mvqa/db.py @@ -11,6 +11,7 @@ dataset = [('Artelab',), testset = [('barcode detect',), ('facedetection(cascade) - CPU',), + ('facedetection(TFlite, mobilenetv1ssd) - CPU',), ] @@ -205,10 +206,31 @@ class FaceCascadeDetection(Session): return (task_time, rv) +class FaceDetectionTFlite(FaceCascadeDetection): + def run(self, item): + file_path = os.path.basename(item) + command = '3\n2\n1\n5\n1\n6\n/tmp/' + \ + file_path + '\n2\n2\n' + subp = subprocess.run(['sdb', 'shell', 'mv_infer_test_suite'], + stdout=subprocess.PIPE, input=command.encode('UTF-8')) + return subp.stdout + + def verify(self, result, label): + rv = result.decode('utf-8') + trunk = rv[rv.find('callback:'):] + time_target = 'time : ' + task_time = trunk[trunk.find( + time_target) + len(time_target): trunk.find('(ms)')] + return (task_time, trunk[:trunk.find('(ms)')]) + + def get_session(dataset_id, testset_id): if(dataset_id == 1): return Barcode(dataset_id, testset_id) elif(dataset_id == 2): - return FaceCascadeDetection(dataset_id, testset_id) + if(testset_id == 2): + return FaceCascadeDetection(dataset_id, testset_id) + else: + return FaceDetectionTFlite(dataset_id, testset_id) else: raise NotImplementedError -- 2.7.4 From ffd8013e4d78f77a7a1379d4244d7279247ca225 Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Wed, 21 Apr 2021 13:29:11 +0900 Subject: [PATCH 06/16] Add readme file for MVQA Change-Id: I21a60641bac220bbb9ca3e34a4134fbaba85aa25 Signed-off-by: Kwang Son --- script/README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 script/README.md diff --git a/script/README.md b/script/README.md new file mode 100644 index 0000000..c8e05a5 --- /dev/null +++ b/script/README.md @@ -0,0 +1,34 @@ +# Media Vision Quality Assessment +Media Vision has unit test(TCT or test bench) to check functionality however does not have quality check (accuracy, memory, speed) for API. +Moreover, tizen support multiple target devices and profiles that developer hard to get compare of the various algorithms. +MVQA(Media Vision Quality Assessment) help to measure API(convention vision algorithm or deep learning) quality across devices and profile. + +## Goal +Depends on hardware target or profile, MVQA measure each API quality and show it as charts. + +## Prerequisite +Dataset for testing and place it on NAS server. + +## How to run +1. change current directory to script and fill nas_config.json to communicate with server. +e.g.) +```json +{ + "user": "iamroot", + "password": "rootpass", + "ip": "xxx.yyy.123.456", + "db_index_path": "/mvtest" +} +``` +note that `db_index_path` is path for dataset root. + +2. run python script for information +```shell +$ python3 mvqa_main.py -h +``` + or run it with test, dataset id. +```shell +$ python3 mvqa_main.py --dataset 1 --testset 1 +``` + +3. program will store result as sql dataset (check mvqa.db file) \ No newline at end of file -- 2.7.4 From d4278823a1d63309a365cd7b8baa063a7c90f4ef Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Wed, 10 Mar 2021 11:38:24 +0900 Subject: [PATCH 07/16] Add manifest manifest is used for apply smack rule in RPM packages. Change-Id: I385cb7ffd3ddce4a552f6c65d9e29685dd862809 Signed-off-by: Kwang Son --- packaging/capi-media-vision.spec | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 1d72b2d..a6a518e 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -243,6 +243,7 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj %{_libdir}/pkgconfig/*common.pc %files barcode +%manifest %{name}.manifest %license LICENSE.APLv2 %{_libdir}/libmv_barcode*.so @@ -251,6 +252,7 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj %{_libdir}/pkgconfig/*barcode.pc %files face +%manifest %{name}.manifest %license LICENSE.APLv2 %{_libdir}/libmv_face*.so @@ -259,6 +261,7 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj %{_libdir}/pkgconfig/*face.pc %files image +%manifest %{name}.manifest %license LICENSE.APLv2 %{_libdir}/libmv_image.so @@ -267,6 +270,7 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj %{_libdir}/pkgconfig/*image.pc %files surveillance +%manifest %{name}.manifest %license LICENSE.APLv2 %{_libdir}/libmv_surveillance*.so @@ -275,6 +279,7 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj %{_libdir}/pkgconfig/*surveillance.pc %files inference +%manifest %{name}.manifest %license LICENSE.APLv2 %{_libdir}/libmv_inference*.so @@ -283,6 +288,7 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj %{_libdir}/pkgconfig/*inference.pc %files testsuite +%manifest %{name}.manifest %license LICENSE.APLv2 %{_libdir}/libmv_*helper.so %{_libdir}/libmv_testsuite*.so -- 2.7.4 From 09a10ec6e67b76889ad956feb3b7b5cf53dc38fa Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Wed, 10 Mar 2021 13:10:15 +0900 Subject: [PATCH 08/16] Remove vulnerable strcpy() and strcat(), use memcpy() instead. Fix svace issue PROC_USE.VULERABLE WGID: 456309 Change-Id: Ic547e9faa06aef0fd70def6ad1e829c15b795f69 Signed-off-by: Tae-Young Chung --- test/testsuites/barcode/barcode_test_suite.c | 7 ++++--- test/testsuites/image/image_test_suite.c | 13 ++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/test/testsuites/barcode/barcode_test_suite.c b/test/testsuites/barcode/barcode_test_suite.c index 381944c..f89ff3d 100644 --- a/test/testsuites/barcode/barcode_test_suite.c +++ b/test/testsuites/barcode/barcode_test_suite.c @@ -637,13 +637,14 @@ int generate_barcode_to_source(barcode_model_s model) goto clean_all; } } else { - jpeg_file_name = (char*)malloc(strlen(model.file_name) + 5); + size_t size = strlen(model.file_name); + jpeg_file_name = (char*)malloc(size + 5); if (jpeg_file_name == NULL) { err = MEDIA_VISION_ERROR_OUT_OF_MEMORY; goto clean_all; } - strcpy(jpeg_file_name, model.file_name); - strcat(jpeg_file_name, ".jpg"); + strncpy(jpeg_file_name, model.file_name, size); + strncat(jpeg_file_name, ".jpg", 4); } err = save_image_from_buffer(jpeg_file_name, data_buffer, &image_data, 100); if (MEDIA_VISION_ERROR_NONE != err) { diff --git a/test/testsuites/image/image_test_suite.c b/test/testsuites/image/image_test_suite.c index da2aa72..f1fb4fe 100644 --- a/test/testsuites/image/image_test_suite.c +++ b/test/testsuites/image/image_test_suite.c @@ -28,6 +28,8 @@ #include #define FILE_PATH_SIZE 1024 +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) typedef enum { SOURCE_TYPE_GENERATION, @@ -94,8 +96,12 @@ void testing_object_fill( "generated from \"%s\"", (char*)source); } else if (OBJECT_TYPE_IMAGE_TRACKING_MODEL == object_type) { - strcpy(target->origin_label, "generated from image object which is "); - strcat(target->origin_label, ((testing_object_h)source)->actual_label); + char *title = "generated from image object which is "; + memcpy(target->origin_label, title, strlen(title)); + memcpy(target->origin_label + strlen(title), ((testing_object_h)source)->actual_label, + testing_object_maximum_label_length - strlen(title)); + int pos = MIN(strlen(title) + strlen(((testing_object_h)source)->actual_label), testing_object_maximum_label_length - 1); + target->origin_label[pos] = '\0'; } else { snprintf( target->origin_label, @@ -136,7 +142,8 @@ void testing_object_fill( "cloned ", number_of_cloning, " from ", type_name, " which is "); - strcat(target->actual_label, target->origin_label); + memcpy(target->actual_label+strlen(target->actual_label), target->origin_label, + testing_object_maximum_label_length - strlen(target->actual_label)); break; } case SOURCE_TYPE_EMPTY: { -- 2.7.4 From dd274f730debdd4670f18895613766167fc77a19 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Wed, 24 Mar 2021 16:07:06 +0900 Subject: [PATCH 09/16] Fix uninitialized Bvh* bvh_ member variable Coverity issue(WGID 1192835): Uninitialized pointer field(CWE-457) Change-Id: I28ee00646f3a70196dcfec08b819657148447a2d Signed-off-by: Tae-Young Chung --- mv_inference/inference/include/BvhParser.h | 3 +++ packaging/capi-media-vision.spec | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mv_inference/inference/include/BvhParser.h b/mv_inference/inference/include/BvhParser.h index a7c03fd..c96bedb 100644 --- a/mv_inference/inference/include/BvhParser.h +++ b/mv_inference/inference/include/BvhParser.h @@ -17,6 +17,9 @@ namespace inference /** Bvh Parser class that is responsible for parsing .bvh file */ class BvhParser { public: + BvhParser() : bvh_(NULL) {}; + ~BvhParser() = default; + /** Parses single bvh file and stored data into bvh structure * @param path The path to file to be parsed * @param bvh The pointer to bvh object where parsed data will be stored diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index a6a518e..0fdb2e2 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,7 +1,7 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API Version: 0.7.0 -Release: 3 +Release: 4 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause Source0: %{name}-%{version}.tar.gz -- 2.7.4 From 904880a10115c528c98abc27e216dde2449eafbe Mon Sep 17 00:00:00 2001 From: Inki Dae Date: Wed, 28 Apr 2021 16:52:16 +0900 Subject: [PATCH 10/16] mv_inference: fix coverity issue This patch returns an error if mPreProc.Run call failed correctly. Change-Id: Ie8b75481e773115a1253ac448175da6cd0efa99d Signed-off-by: Inki Dae --- mv_inference/inference/src/Inference.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mv_inference/inference/src/Inference.cpp b/mv_inference/inference/src/Inference.cpp index 820ce70..db2068f 100644 --- a/mv_inference/inference/src/Inference.cpp +++ b/mv_inference/inference/src/Inference.cpp @@ -1108,6 +1108,10 @@ namespace inference int data_type = ConvertToCv(tensor_buffer.data_type); ret = mPreProc.Run(cvSource, colorspace, data_type, layerInfo, opt, tensor_buffer.buffer); + if (ret != MEDIA_VISION_ERROR_NONE) { + LOGE("Fail to run preprocess."); + return ret; + } } } else { for (auto& buffer : mInputTensorBuffers.getAllTensorBuffer()) { -- 2.7.4 From 76596b737533d09d90ca97ba6a7d9cca9ef97f0b Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Thu, 29 Apr 2021 12:50:55 +0900 Subject: [PATCH 11/16] Fix failure of SetInputLayerProperty If inputMeta isn't used, property is empty resulting to failure of SetInputLayerProperty(). property, which is set to inference engine backends through inference engine interface, should be set by mConfig, regardless of inputMeta usage. Change-Id: I4424d3c935288ee66ac3fab966e0e06f13a22e7f Signed-off-by: Tae-Young Chung --- mv_inference/inference/src/Inference.cpp | 42 ++++++++++++-------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/mv_inference/inference/src/Inference.cpp b/mv_inference/inference/src/Inference.cpp index db2068f..061c00f 100644 --- a/mv_inference/inference/src/Inference.cpp +++ b/mv_inference/inference/src/Inference.cpp @@ -423,34 +423,24 @@ namespace inference // the tensor info given by a user will be used. // If the plugin supports that, the given info will be ignored. - for (auto& layer : inputMeta.layer) { + for (auto& name : mConfig.mInputLayerNames) { inference_engine_tensor_info tensor_info; - if (inputMeta.parsed) { - tensor_info.data_type = ConvertToIE(layer.second.dataType); - - tensor_info.shape_type = layer.second.shapeType; - tensor_info.size = 1; - for (auto& dim : layer.second.dims) { - tensor_info.shape.push_back(dim); - tensor_info.size *= dim; - } - } else { - tensor_info.data_type = ConvertToIE(dataType); - - // In case of OpenCV, only supports NCHW - tensor_info.shape_type = INFERENCE_TENSOR_SHAPE_NCHW; - // modify to handle multiple tensor infos - tensor_info.shape.push_back(mConfig.mTensorInfo.dim); - tensor_info.shape.push_back(mConfig.mTensorInfo.ch); - tensor_info.shape.push_back(mConfig.mTensorInfo.height); - tensor_info.shape.push_back(mConfig.mTensorInfo.width); - - tensor_info.size = 1; - for (auto& dim : tensor_info.shape) { - tensor_info.size *= dim; - } + tensor_info.data_type = ConvertToIE(dataType); + + // In case of OpenCV, only supports NCHW + tensor_info.shape_type = INFERENCE_TENSOR_SHAPE_NCHW; + // modify to handle multiple tensor infos + tensor_info.shape.push_back(mConfig.mTensorInfo.dim); + tensor_info.shape.push_back(mConfig.mTensorInfo.ch); + tensor_info.shape.push_back(mConfig.mTensorInfo.height); + tensor_info.shape.push_back(mConfig.mTensorInfo.width); + + tensor_info.size = 1; + for (auto& dim : tensor_info.shape) { + tensor_info.size *= dim; } - property.layers.insert(std::make_pair(layer.first, tensor_info)); + + property.layers.insert(std::make_pair(name, tensor_info)); } int ret = mBackend->SetInputLayerProperty(property); -- 2.7.4 From 954aabf92059bde43253a47937e2d876a5e6b426 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Mon, 19 Apr 2021 17:21:56 +0900 Subject: [PATCH 12/16] Add rotation functionality and CLAHE preprocessing in Barcode module Change-Id: I806ad1e20a2b3a436b14b26d41218dbfa3c7fe32 Signed-off-by: Tae-Young Chung (cherry picked from commit a9bcad59c6c72b617a836e0e4687f0a9ef52a7e6) --- include/mv_barcode_detect.h | 63 ++++++ mv_barcode/barcode_detector/CMakeLists.txt | 10 +- mv_barcode/barcode_detector/include/BarcodeUtils.h | 13 ++ mv_barcode/barcode_detector/src/BarcodeUtils.cpp | 100 ++++++++++ .../src/mv_barcode_detect_open.cpp | 218 +++++++++++++++------ 5 files changed, 338 insertions(+), 66 deletions(-) diff --git a/include/mv_barcode_detect.h b/include/mv_barcode_detect.h index bb9c893..61944ba 100644 --- a/include/mv_barcode_detect.h +++ b/include/mv_barcode_detect.h @@ -44,6 +44,52 @@ extern "C" { #define MV_BARCODE_DETECT_ATTR_TARGET "MV_BARCODE_DETECT_ATTR_TARGET" /**< Target: 0-all, 1-1D, 2-2D*/ /** + * @brief Use MV_BARCODE_DETECT_ATTR_ROTATION_DEGREE + * to set rotation degree attribute of the engine configuration. + * + * @since_tizen 6.5 + * @see #MV_BARCODE_DETECT_ATTR_ROTATION_COUNT + * @see #MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION + */ +#define MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES "MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES" + +/** + * @brief Use MV_BARCODE_DETECT_ATTR_ROTATION_COUNT + * to set rotation count attribute of the engine configuration. + * @details If #MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES, #MV_BARCODE_DETECT_ATTR_ROTATION_COUNT, + * and #MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION are set to + * 20, 9, and MV_BARCODE_DETECT_ATTR_ROTATION_CLOCKWISE, repectively,\n + * detection will be tried with 20, 40, 60, ... 180 degrees as well as 0 degrees.\n + * Similarly, -20, -40, -60, ... will be tried for #MV_BARCODE_DETECT_ATTR_ROTATION_COUNTER_CLOCKWISE and + * -20, +20, -40, +40, ... will be tried iteratively for #MV_BARCODE_DETECT_ATTR_ROTATION_ALL. + * + * @since_tizen 6.5 + * @see #MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES + * @see #MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION + * @see mv_barcode_detect_attr_rotation_direction_e + */ +#define MV_BARCODE_DETECT_ATTR_ROTATION_COUNT "MV_BARCODE_DETECT_ATTR_ROTATION_COUNT" + +/** + * @brief Use MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION + * to set rotation direction attribute of the engine configuration. + * + * @since_tizen 6.5 + * @see #MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES + * @see #MV_BARCODE_DETECT_ATTR_ROTATION_COUNT + * @see mv_barcode_detect_attr_rotation_direction_e + */ +#define MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION "MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION" + +/** + * @brief Use MV_BARCODE_DETECT_ATTR_USE_ENHANCEMENT + * to enable image quality enhancement attribute of the engine configuration. + * + * @since_tizen 6.5 + */ +#define MV_BARCODE_DETECT_ATTR_USE_ENHANCEMENT "MV_BARCODE_DETECT_ATTR_USE_ENHANCEMENT" + +/** * @brief Enumeration to target attribute * * @since_tizen @if MOBILE 2.4 @else 3.0 @endif @@ -54,6 +100,23 @@ typedef enum { MV_BARCODE_DETECT_ATTR_TARGET_2D_BARCODE, /**< 2D barcode only */ } mv_barcode_detect_attr_target_e; +/** + * @brief Enumeration for rotation direction attribute. + * @details Set one of rotation direction, which are:\n + * #MV_BARCODE_DETECT_ATTR_ROTATION_CLOCKWISE - clockwise rotation,\n + * #MV_BARCODE_DETECT_ATTR_ROTATION_COUNTER_CLOCKWISE - counter clockwise rotation,\n + * #MV_BARCODE_DETECT_ATTR_ROTATION_ALL - clockwise and counter clockwise rotation iteratively.\n + * + * @since_tizen 6.5 + * @see #MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION + * @see #MV_BARCODE_DETECT_ATTR_ROTATION_COUNT + */ +typedef enum { + MV_BARCODE_DETECT_ATTR_ROTATION_CLOCKWISE, /**< Clockwise */ + MV_BARCODE_DETECT_ATTR_ROTATION_COUNTER_CLOCKWISE, /**< Counter clockwise */ + MV_BARCODE_DETECT_ATTR_ROTATION_ALL, /**< Clockwise and counter clockwise */ +} mv_barcode_detect_attr_rotation_direction_e; + /** * @brief Called when barcode detection is completed. diff --git a/mv_barcode/barcode_detector/CMakeLists.txt b/mv_barcode/barcode_detector/CMakeLists.txt index 8ff4612..123d3fb 100644 --- a/mv_barcode/barcode_detector/CMakeLists.txt +++ b/mv_barcode/barcode_detector/CMakeLists.txt @@ -15,12 +15,20 @@ file(GLOB MV_BARCODE_DET_INC_LIST "${PROJECT_SOURCE_DIR}/include/*.h") file(GLOB MV_BARCODE_DET_SRC_LIST "${PROJECT_SOURCE_DIR}/src/*.cpp" "${PROJECT_SOURCE_DIR}/src/*.c") +find_package(OpenCV REQUIRED core imgproc) +if(NOT OpenCV_FOUND) + message(SEND_ERROR "Failed to find OpenCV") + return() +else() + include_directories(${OpenCV_INCLUDE_DIRS}) +endif() + if(FORCED_STATIC_BUILD) add_library(${PROJECT_NAME} STATIC ${MV_BARCODE_DET_INC_LIST} ${MV_BARCODE_DET_SRC_LIST}) else() add_library(${PROJECT_NAME} SHARED ${MV_BARCODE_DET_INC_LIST} ${MV_BARCODE_DET_SRC_LIST}) endif() -target_link_libraries(${PROJECT_NAME} ${MV_COMMON_LIB_NAME} zbar dlog) +target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${MV_COMMON_LIB_NAME} zbar dlog) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/mv_barcode/barcode_detector/include/BarcodeUtils.h b/mv_barcode/barcode_detector/include/BarcodeUtils.h index 58f30c6..4b06ae5 100644 --- a/mv_barcode/barcode_detector/include/BarcodeUtils.h +++ b/mv_barcode/barcode_detector/include/BarcodeUtils.h @@ -18,6 +18,8 @@ #define __MEDIA_VISION_BARCODE_UTILS_H__ #include "mv_common.h" +#include +#include namespace zbar { class Image; @@ -37,6 +39,17 @@ namespace Barcode { */ int convertSourceMV2Zbar(mv_source_h mvSource, zbar::Image& zbarSource); +/** + * @brief This function converts media vision image handle to cv::Mat with gray color. + * + * @since_tizen 6.5 + * @param [in] mvSource Media vision image handle + * @param [out] cv::Mat + * @return @c MEDIA_VISION_ERROR_NONE on success, + otherwise a negative error value + */ +int convertSourceMV2GrayCV(mv_source_h mvSource, cv::Mat& cvSource); + } /* Barcode */ } /* MediaVision */ diff --git a/mv_barcode/barcode_detector/src/BarcodeUtils.cpp b/mv_barcode/barcode_detector/src/BarcodeUtils.cpp index b8c70d9..6f4c7d2 100644 --- a/mv_barcode/barcode_detector/src/BarcodeUtils.cpp +++ b/mv_barcode/barcode_detector/src/BarcodeUtils.cpp @@ -103,5 +103,105 @@ int convertSourceMV2Zbar(mv_source_h mvSource, zbar::Image& zbarSource) return err; } +int convertSourceMV2GrayCV(mv_source_h mvSource, cv::Mat& cvSource) +{ + MEDIA_VISION_INSTANCE_CHECK(mvSource); + + int depth = CV_8U; // Default depth. 1 byte for channel. + unsigned int channelsNumber = 0u; + unsigned int width = 0u, height = 0u; + unsigned int bufferSize = 0u; + unsigned char *buffer = NULL; + + mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID; + + MEDIA_VISION_ASSERT(mv_source_get_width(mvSource, &width), + "Failed to get the width."); + MEDIA_VISION_ASSERT(mv_source_get_height(mvSource, &height), + "Failed to get the height."); + MEDIA_VISION_ASSERT(mv_source_get_colorspace(mvSource, &colorspace), + "Failed to get the colorspace."); + MEDIA_VISION_ASSERT(mv_source_get_buffer(mvSource, &buffer, &bufferSize), + "Failed to get the buffer size."); + + int conversionType = -1; /* Type of conversion from given colorspace to gray */ + switch(colorspace) { + case MEDIA_VISION_COLORSPACE_INVALID: + LOGE("Error: mv_source has invalid colorspace."); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + case MEDIA_VISION_COLORSPACE_Y800: + channelsNumber = 1; + /* Without convertion */ + break; + case MEDIA_VISION_COLORSPACE_I420: + channelsNumber = 1; + height *= 1.5; + conversionType = cv::COLOR_YUV2GRAY_I420; + break; + case MEDIA_VISION_COLORSPACE_NV12: + channelsNumber = 1; + height *= 1.5; + conversionType = cv::COLOR_YUV2GRAY_NV12; + break; + case MEDIA_VISION_COLORSPACE_YV12: + channelsNumber = 1; + height *= 1.5; + conversionType = cv::COLOR_YUV2GRAY_YV12; + break; + case MEDIA_VISION_COLORSPACE_NV21: + channelsNumber = 1; + height *= 1.5; + conversionType = cv::COLOR_YUV2GRAY_NV21; + break; + case MEDIA_VISION_COLORSPACE_YUYV: + channelsNumber = 2; + conversionType = cv::COLOR_YUV2GRAY_YUYV; + break; + case MEDIA_VISION_COLORSPACE_UYVY: + channelsNumber = 2; + conversionType = cv::COLOR_YUV2GRAY_UYVY; + break; + case MEDIA_VISION_COLORSPACE_422P: + channelsNumber = 2; + conversionType = cv::COLOR_YUV2GRAY_Y422; + break; + case MEDIA_VISION_COLORSPACE_RGB565: + channelsNumber = 2; + conversionType = cv::COLOR_BGR5652GRAY; + break; + case MEDIA_VISION_COLORSPACE_RGB888: + channelsNumber = 3; + conversionType = cv::COLOR_RGB2GRAY; + break; + case MEDIA_VISION_COLORSPACE_RGBA: + channelsNumber = 4; + conversionType = cv::COLOR_RGBA2GRAY; + break; + default: + LOGE("Error: mv_source has unsupported colorspace."); + return MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT; + } + + if (conversionType == -1) {/* Without conversion */ + cvSource = cv::Mat(cv::Size(width, height), + CV_MAKETYPE(depth, channelsNumber), buffer).clone(); + } else {/* With conversion */ + /* Class for representation the given image as cv::Mat before conversion */ + cv::Mat origin; + + try { + origin = cv::Mat(cv::Size(width, height), + CV_MAKETYPE(depth, channelsNumber), buffer); + + cv::cvtColor(origin, cvSource, conversionType); + } catch (const cv::Exception &e) { + LOGE("Failed to cvtColor with %s", e.what()); + return MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT; + } + } + + return MEDIA_VISION_ERROR_NONE; +} + } /* Barcode */ } /* MediaVision */ diff --git a/mv_barcode/barcode_detector/src/mv_barcode_detect_open.cpp b/mv_barcode/barcode_detector/src/mv_barcode_detect_open.cpp index 0d4be8e..54dee63 100644 --- a/mv_barcode/barcode_detector/src/mv_barcode_detect_open.cpp +++ b/mv_barcode/barcode_detector/src/mv_barcode_detect_open.cpp @@ -20,7 +20,9 @@ #include "BarcodeUtils.h" #include - +#include +#include +#include #include using namespace MediaVision::Barcode; @@ -35,29 +37,16 @@ int mv_barcode_detect_open( if (!source || !detect_cb) return MEDIA_VISION_ERROR_INVALID_PARAMETER; - zbar::Image image; - int err = convertSourceMV2Zbar(source, image); - if (err != MEDIA_VISION_ERROR_NONE) { - LOGW("convertSourceMV2Zbar failed"); - return err; - } - - zbar::Image greyImage = image.convert("Y800"); - if (!greyImage.get_data()) { - LOGE("fail to image convert by zbar"); - return MEDIA_VISION_ERROR_INVALID_OPERATION; - } - - greyImage.set_crop(roi.point.x, roi.point.y, roi.width, roi.height); zbar::ImageScanner scanner; int target_val; - err = mv_engine_config_get_int_attribute( + int err = mv_engine_config_get_int_attribute( engine_cfg, "MV_BARCODE_DETECT_ATTR_TARGET", &target_val); if (err != MEDIA_VISION_ERROR_NONE || engine_cfg == NULL) { - LOGW("mv_engine_config_get_int_attribute failed"); + LOGW("mv_engine_config_get_int_attribute failed." + "MV_BARCODE_DETECT_ATTR_TARGET_ALL is used as default"); /* Default value */ target_val = 0; } @@ -110,65 +99,164 @@ int mv_barcode_detect_open( LOGW("Unavailable target value %d", target_val); } - int numberOfBarcodes = scanner.scan(greyImage); - LOGI("ZBar scanner has found %i barcodes on the mv_source_h", - numberOfBarcodes); - mv_quadrangle_s *barcodeLocations = NULL; - mv_barcode_type_e *types = NULL; - - if (numberOfBarcodes == 0) { - LOGI("Call the detect callback for 0 detected barcodes"); - detect_cb(source, engine_cfg, barcodeLocations, NULL, - types, numberOfBarcodes, user_data); - return MEDIA_VISION_ERROR_NONE; - } else if (numberOfBarcodes < 0) { - LOGW("Incorrect number of barcodes (%i), detection is terminated", - numberOfBarcodes); - return MEDIA_VISION_ERROR_INTERNAL; + int rotateDegree = 0; + int rotateNumber = 0; + int rotateDirection = 0; + bool isEnhancementMode = false; + if (engine_cfg != NULL) { + err = mv_engine_config_get_int_attribute( + engine_cfg, + MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES, + &rotateDegree); + if (err != MEDIA_VISION_ERROR_NONE) { + LOGE("mv_engine_config_get_int_attribute failed to get MV_BARCODE_DETECT_ATTR_ROTATE_DEGREES"); + return err; + } + + err = mv_engine_config_get_int_attribute( + engine_cfg, + MV_BARCODE_DETECT_ATTR_ROTATION_COUNT, + &rotateNumber); + if (err != MEDIA_VISION_ERROR_NONE) { + LOGE("mv_engine_config_get_int_attribute failed to get MV_BARCODE_DETECT_ATTR_ROTATE_COUNT"); + return err; + } + + err = mv_engine_config_get_int_attribute( + engine_cfg, + MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION, + &rotateDirection); + if (err != MEDIA_VISION_ERROR_NONE) { + LOGE("mv_engine_config_get_int_attribute failed to get MV_BARCODE_DETECT_ATTR_ROTATE_DIRECTION"); + return err; + } + + err = mv_engine_config_get_bool_attribute( + engine_cfg, + MV_BARCODE_DETECT_ATTR_USE_ENHANCEMENT, + &isEnhancementMode); + if (err != MEDIA_VISION_ERROR_NONE) { + LOGE("mv_engine_config_get_bool_attribute failed to get MV_BARCODE_DETECT_ATTR_USE_ENHANCEMENT"); + return err; + } } - const char **messagesArray = new const char*[numberOfBarcodes]; - barcodeLocations = new mv_quadrangle_s[numberOfBarcodes]; - types = new mv_barcode_type_e[numberOfBarcodes]; + cv::Mat graySource; + cv::Mat rotMat, rotBuffer; + err = convertSourceMV2GrayCV(source, graySource); + if (err != MEDIA_VISION_ERROR_NONE) { + LOGE("Failed to convertSourceMV2GrayCV[%d]", err); + return err; + } - int i = 0; - /* extract results and prepare them for callback passing */ - for (zbar::SymbolIterator symbol = greyImage.symbol_begin(); - symbol != greyImage.symbol_end(); - ++symbol, ++i) { - Barcode curBarcode(*symbol); + cv::Mat rawBuffer = graySource(cv::Rect(roi.point.x, roi.point.y, roi.width, roi.height)); - size_t messageLength = curBarcode.getMessage().size(); - char *curMessage = new char[messageLength + 1]; - curBarcode.getMessage().copy(curMessage, messageLength); - curMessage[messageLength] = '\0'; - messagesArray[i] = curMessage; + if (isEnhancementMode) { + cv::Mat clacheBuffer; + cv::Ptr clache = cv::createCLAHE(); + clache->setClipLimit(2.0); + clache->apply(rawBuffer, clacheBuffer); - types[i] = curBarcode.getType(); + cv::threshold(clacheBuffer, rawBuffer, 240, 255, cv::THRESH_TRUNC | cv::THRESH_OTSU); + } - LOGI("barcode type: %d with message %s", types[i], curMessage); - int err = curBarcode.calculateLocation(barcodeLocations[i]); - if (err != MEDIA_VISION_ERROR_NONE) { - LOGW("Can't determine location for barcode, detection is terminated"); - for (int j = 0; j <= i; ++j) + std::vector barcodeMessages; + std::vector barcodeLocations; + std::vector barcodeTypes; + zbar::Image _image; + + LOGI("%d numbers with %d degree to %d direction", rotateNumber, rotateDegree, rotateDirection); + + if (rotateDirection == MV_BARCODE_DETECT_ATTR_ROTATION_ALL) + rotateNumber *= 2; + + rotateNumber++; + + int degree = 0; + for (int i = 0; i < rotateNumber; ++i) { + if (rotateDirection == MV_BARCODE_DETECT_ATTR_ROTATION_CLOCKWISE) { + degree = -1 * rotateDegree * i; + } else if (rotateDirection == MV_BARCODE_DETECT_ATTR_ROTATION_COUNTER_CLOCKWISE) { + degree = rotateDegree * i; + } else { // MV_BARCODE_DETECT_ATTR_ROTATE_ALL + if (i%2) { + degree = -1 * rotateDegree * ((i+1)/2); + } else { + degree = rotateDegree * (i/2); + } + } + + rotMat = cv::getRotationMatrix2D(cv::Point((roi.width/2), (roi.height/2)), degree, 1.0); + warpAffine(rawBuffer, rotBuffer, rotMat, rawBuffer.size()); + + _image.set_format("Y800"); + _image.set_size(rotBuffer.cols, rotBuffer.rows); + _image.set_data(rotBuffer.data, rotBuffer.total() * rotBuffer.elemSize()); + + LOGW("%p", _image.get_data()); + if (!_image.get_data()) { + LOGE("fail to get image data"); + return MEDIA_VISION_ERROR_INVALID_OPERATION; + } + + int numberOfBarcodes = scanner.scan(_image); + if (numberOfBarcodes <= 0) + continue; + + LOGI("[rot:%d]: %d barcodes detected", i, numberOfBarcodes); + barcodeMessages.clear(); + barcodeTypes.clear(); + barcodeLocations.clear(); + bool isDetected = true; + for (zbar::SymbolIterator symbol = _image.symbol_begin(); + symbol != _image.symbol_end(); ++symbol) { + + Barcode curBarcode(*symbol); + mv_quadrangle_s location; + int err = curBarcode.calculateLocation(location); + if (err != MEDIA_VISION_ERROR_NONE) { + isDetected = false; + break; + } + + barcodeMessages.push_back(curBarcode.getMessage()); + barcodeTypes.push_back(curBarcode.getType()); + barcodeLocations.push_back(location); + } + + if (isDetected) { + LOGI("Call the detect callback for %d detected barcodes", numberOfBarcodes); + const char **messagesArray = new const char*[numberOfBarcodes]; + mv_barcode_type_e *types = new mv_barcode_type_e[numberOfBarcodes]; + mv_quadrangle_s *locations = new mv_quadrangle_s[numberOfBarcodes]; + + for (int i = 0; i < numberOfBarcodes; ++i) { + + size_t messageLength = barcodeMessages[i].size(); + char *curMessage = new char[messageLength + 1]; + barcodeMessages[i].copy(curMessage, messageLength); + curMessage[messageLength] = '\0'; + messagesArray[i] = curMessage; + + types[i] = barcodeTypes[i]; + locations[i] = barcodeLocations[i]; + LOGI("%d: barcode with %s with type %d", i, messagesArray[i], types[i]); + } + detect_cb(source, engine_cfg, locations, messagesArray, types, + numberOfBarcodes, user_data); + LOGI("Clean the memory from barcodes messages and types"); + for (int j = 0; j < numberOfBarcodes; ++j) delete[] messagesArray[j]; delete[] messagesArray; - delete[] barcodeLocations; + delete[] locations; delete[] types; - return err; + + return MEDIA_VISION_ERROR_NONE; } } - - LOGI("Call the detect callback for %i detected barcodes", numberOfBarcodes); - detect_cb(source, engine_cfg, barcodeLocations, messagesArray, types, - numberOfBarcodes, user_data); - - LOGI("Clean the memory from barcodes messages, locations and types"); - for (int j = 0; j < numberOfBarcodes; ++j) - delete[] messagesArray[j]; - delete[] messagesArray; - delete[] barcodeLocations; - delete[] types; + LOGI("Call the detect callback for 0 detected barcodes"); + detect_cb(source, engine_cfg, NULL, NULL, + NULL, 0, user_data); return MEDIA_VISION_ERROR_NONE; } -- 2.7.4 From 382670a074210e0479f28db66ba46f82f3c57d6d Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Thu, 6 May 2021 16:23:14 +0900 Subject: [PATCH 13/16] Add new attributes to media-vision-config.json New attributes as rotation and image enhancement features in barcode detection, - MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES - MV_BARCODE_DETECT_ATTR_ROTATION_COUNT - MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION - MV_BARCODE_DETECT_ATTR_USE_ENHANCEMENT, should be added to media-vision-config.json Change-Id: I2d6dcbd215d50e32dd9a43ac31f7e11309aa38a0 Signed-off-by: Tae-Young Chung --- media-vision-config.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/media-vision-config.json b/media-vision-config.json index 59dbeaf..c5ee5af 100644 --- a/media-vision-config.json +++ b/media-vision-config.json @@ -57,6 +57,26 @@ "value" : 0 }, { + "name" : "MV_BARCODE_DETECT_ATTR_ROTATION_DEGREES", + "type" : "integer", + "value" : 0 + }, + { + "name" : "MV_BARCODE_DETECT_ATTR_ROTATION_COUNT", + "type" : "integer", + "value" : 0 + }, + { + "name" : "MV_BARCODE_DETECT_ATTR_ROTATION_DIRECTION", + "type" : "integer", + "value" : 0 + }, + { + "name" : "MV_BARCODE_DETECT_ATTR_USE_ENHANCEMENT", + "type" : "boolean", + "value" : false + }, + { "name" : "MV_IMAGE_RECOGNITION_OBJECT_SCALE_FACTOR", "type" : "double", "value" : 1.2 -- 2.7.4 From 61827f0e5266689b828cef4047ed568abef2f39d Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Thu, 6 May 2021 16:37:53 +0900 Subject: [PATCH 14/16] Remove MEDIA_VISION_COLORSPACE_INVALID case in convertSourceMV2GrayCV() It is one of colorspace which is not supported. We don't need to separate it from other not supported error cases. Change-Id: I2a757ed7338897f5638527aac7c2daec01661386 Signed-off-by: Tae-Young Chung --- mv_barcode/barcode_detector/src/BarcodeUtils.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/mv_barcode/barcode_detector/src/BarcodeUtils.cpp b/mv_barcode/barcode_detector/src/BarcodeUtils.cpp index 6f4c7d2..3aca258 100644 --- a/mv_barcode/barcode_detector/src/BarcodeUtils.cpp +++ b/mv_barcode/barcode_detector/src/BarcodeUtils.cpp @@ -126,9 +126,6 @@ int convertSourceMV2GrayCV(mv_source_h mvSource, cv::Mat& cvSource) int conversionType = -1; /* Type of conversion from given colorspace to gray */ switch(colorspace) { - case MEDIA_VISION_COLORSPACE_INVALID: - LOGE("Error: mv_source has invalid colorspace."); - return MEDIA_VISION_ERROR_INVALID_PARAMETER; case MEDIA_VISION_COLORSPACE_Y800: channelsNumber = 1; /* Without convertion */ -- 2.7.4 From fa04ac1a75716dc5bf5abcd0d9493f278714bc2b Mon Sep 17 00:00:00 2001 From: Hyunsoo Park Date: Tue, 11 May 2021 15:07:53 +0900 Subject: [PATCH 15/16] [Face/Barcode] Handle Error return Change-Id: Ia1fcefc4b567fb67924113b64c9ac22ccc6094d9 Signed-off-by: Hyunsoo Park --- test/assessment/barcode/assessment_barcode.cpp | 27 +++++++++++++++---------- test/assessment/face/assessment_face.cpp | 28 ++++++++++++++------------ 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/test/assessment/barcode/assessment_barcode.cpp b/test/assessment/barcode/assessment_barcode.cpp index fd4e14b..9e69292 100644 --- a/test/assessment/barcode/assessment_barcode.cpp +++ b/test/assessment/barcode/assessment_barcode.cpp @@ -25,6 +25,8 @@ #include #include +#include +#include #define MAX_ARGS 2 @@ -111,7 +113,7 @@ void barcode_detected_cb( MEDIA_VISION_FUNCTION_LEAVE(); } -void perform_detect(struct arguments *arguments) +int perform_detect(struct arguments *arguments) { MEDIA_VISION_FUNCTION_ENTER(); @@ -123,8 +125,9 @@ void perform_detect(struct arguments *arguments) unsigned int image_height = 0; int int_value = MV_BARCODE_DETECT_ATTR_TARGET_ALL; mv_rectangle_s roi = { {0, 0}, 0, 0 }; + int err = MEDIA_VISION_ERROR_NONE; - int err = load_image_to_buffer(arguments->source, + err = load_image_to_buffer(arguments->source, &data_buffer, &buffer_size, &image_width, &image_height); if (MEDIA_VISION_ERROR_NONE != err) { @@ -133,8 +136,10 @@ void perform_detect(struct arguments *arguments) } err = mv_create_engine_config(&mv_engine_config); - if (MEDIA_VISION_ERROR_NONE != err) + if (MEDIA_VISION_ERROR_NONE != err) { LOGE("Errors were occurred during creating the media engine config : %i", err); + goto out; + } if (MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE == mv_engine_config_get_int_attribute( @@ -160,9 +165,8 @@ void perform_detect(struct arguments *arguments) roi.width = image_width; roi.height = image_height; err = mv_barcode_detect(source, mv_engine_config, roi, barcode_detected_cb, NULL); - if (MEDIA_VISION_ERROR_NONE != err) { + if (MEDIA_VISION_ERROR_NONE != err) LOGE("Errors were occurred during barcode detection!!! code : %i", err); - } out: if (MEDIA_VISION_ERROR_NONE != err) printf("-1\n"); @@ -187,6 +191,7 @@ out: } MEDIA_VISION_FUNCTION_LEAVE(); + return err; } static error_t parse_opt (int key, char *arg, struct argp_state *state) @@ -223,13 +228,13 @@ int main(int argc, char *argv[]) struct arguments arguments; argp_parse (&argp, argc, argv, 0, 0, &arguments); - clock_gettime(CLOCK_MONOTONIC, &s_tspec); - perform_detect(&arguments); - clock_gettime(CLOCK_MONOTONIC, &e_tspec); + std::chrono::system_clock::time_point StartTime = std::chrono::system_clock::now(); + int err = perform_detect(&arguments); + std::chrono::milliseconds ms = std::chrono::duration_cast(std::chrono::system_clock::now() - StartTime); + std::cout << ms.count() << "ms" << std::endl; - struct timespec diffspec = diff(s_tspec, e_tspec); - unsigned long timeDiff = gettotalmillisec(diffspec); - printf("%lums\n", timeDiff); + if (err != MEDIA_VISION_ERROR_NONE) + printf("ERROR: Action is finished with error code: %i\n", err); LOGI("Media Vision Assessment-Barcode is closed."); diff --git a/test/assessment/face/assessment_face.cpp b/test/assessment/face/assessment_face.cpp index f94ebda..bbaa0e5 100644 --- a/test/assessment/face/assessment_face.cpp +++ b/test/assessment/face/assessment_face.cpp @@ -26,6 +26,8 @@ #include #include +#include +#include #define MAX_ARGS 3 @@ -119,7 +121,7 @@ int load_image_to_buffer(char *source, return MEDIA_VISION_ERROR_NONE; } -void perform_detect(struct arguments *arguments) +int perform_detect(struct arguments *arguments) { MEDIA_VISION_FUNCTION_ENTER(); @@ -139,8 +141,10 @@ void perform_detect(struct arguments *arguments) } err = mv_create_engine_config(&mv_engine_config); - if (MEDIA_VISION_ERROR_NONE != err) + if (MEDIA_VISION_ERROR_NONE != err) { LOGE("Errors were occurred during creating the media engine config : %i", err); + goto out; + } mv_engine_config_set_string_attribute( mv_engine_config, @@ -161,9 +165,9 @@ void perform_detect(struct arguments *arguments) } err = mv_face_detect(source, mv_engine_config, on_face_detected_cb, NULL); - if (MEDIA_VISION_ERROR_NONE != err) { + if (MEDIA_VISION_ERROR_NONE != err) LOGE("Errors were occurred during face detection!!! code : %i", err); - } + out: if (MEDIA_VISION_ERROR_NONE != err) printf("-1\n"); @@ -183,6 +187,7 @@ out: } MEDIA_VISION_FUNCTION_LEAVE(); + return err; } static error_t parse_opt (int key, char *arg, struct argp_state *state) @@ -216,21 +221,18 @@ static struct argp argp = { NULL, parse_opt, args_doc, doc }; int main(int argc, char *argv[]) { - struct timespec s_tspec; - struct timespec e_tspec; - LOGI("Media Vision Assessment-Face is launched."); struct arguments arguments; argp_parse (&argp, argc, argv, 0, 0, &arguments); - clock_gettime(CLOCK_MONOTONIC, &s_tspec); - perform_detect(&arguments); - clock_gettime(CLOCK_MONOTONIC, &e_tspec); + std::chrono::system_clock::time_point StartTime = std::chrono::system_clock::now(); + int err = perform_detect(&arguments); + std::chrono::milliseconds ms = std::chrono::duration_cast(std::chrono::system_clock::now() - StartTime); + std::cout << ms.count() << "ms" << std::endl; - struct timespec diffspec = diff(s_tspec, e_tspec); - unsigned long timeDiff = gettotalmillisec(diffspec); - printf("%lums\n", timeDiff); + if (err != MEDIA_VISION_ERROR_NONE) + printf("ERROR: Action is finished with error code: %i\n", err); LOGI("Media Vision Assessment-Face is closed."); -- 2.7.4 From 70ade6e975076f08cf13bc3fde6cc4e21e478e61 Mon Sep 17 00:00:00 2001 From: Hyunsoo Park Date: Wed, 2 Jun 2021 09:23:17 +0900 Subject: [PATCH 16/16] Change path of configuration file Change-Id: I957ea08224f9fb7654f0e79520f975cc2a293f08 Signed-off-by: Hyunsoo Park --- packaging/capi-media-vision.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 0fdb2e2..3f21335 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -184,8 +184,8 @@ export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" %endif -export CFLAGS+=" -DSYSCONFDIR=\\\"%{_sysconfdir}\\\"" -export CXXFLAGS+=" -DSYSCONFDIR=\\\"%{_sysconfdir}\\\"" +export CFLAGS+=" -DSYSCONFDIR=\\\"%{_hal_sysconfdir}\\\"" +export CXXFLAGS+=" -DSYSCONFDIR=\\\"%{_hal_sysconfdir}\\\"" export CFLAGS+=" -DMV_CONFIG_PATH=\\\"%{TZ_SYS_RO_SHARE}/%{name}/\\\"" export CXXFLAGS+=" -DMV_CONFIG_PATH=\\\"%{TZ_SYS_RO_SHARE}/%{name}/\\\"" -- 2.7.4