diff --git a/.gitignore b/.gitignore index 9a6361d..a8e1fbc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /input/ -/output/ \ No newline at end of file +/output/ + +!/input/model_onnx.py diff --git a/conv.py b/conv.py index a7d4f5c..58fead7 100644 --- a/conv.py +++ b/conv.py @@ -1,63 +1,72 @@ from rknn.api import RKNN import os +# for suffix in ["n", "s", "m", "l", "x"]: for suffix in ["n", "s", "m", "l", "x"]: - for soc in ["rk3562","rk3566", "rk3568", "rk3588"]: - INPUT_MODEL = 'yolov8{}.onnx'.format(suffix) - WIDTH = 320 - HEIGHT = 320 - OUTPUT_MODEL_BASENAME = 'yolov8{}'.format(suffix) - QUANTIZATION = False - DATASET = './dataset_coco10.txt' + # for soc in ["rk3562","rk3566", "rk3568", "rk3588"]: + for soc in ["rk3588"]: + # for QUANTIZATION in [True, False]: + for QUANTIZATION in [True]: + INPUT_MODEL = 'yolov8{}.onnx'.format(suffix) + WIDTH = 320 + HEIGHT = 320 + OUTPUT_MODEL_BASENAME = 'yolov8{}'.format(suffix) + # QUANTIZATION = False + DATASET = './datasets/coco20/dataset_coco20.txt' - # Config - MEAN_VALUES = [[0, 0, 0]] - STD_VALUES = [[255, 255, 255]] - QUANT_IMG_RGB2BGR = True - QUANTIZED_DTYPE = "asymmetric_quantized-8" - QUANTIZED_ALGORITHM = "normal" - QUANTIZED_METHOD = "channel" - FLOAT_DTYPE = "float16" - OPTIMIZATION_LEVEL = 2 - TARGET_PLATFORM = soc - CUSTOM_STRING = None - REMOVE_WEIGHT = None - COMPRESS_WEIGHT = False - SINGLE_CORE_MODE = False - MODEL_PRUNNING = False - OP_TARGET = None - DYNAMIC_INPUT = None + # Config + MEAN_VALUES = [[0, 0, 0]] + STD_VALUES = [[255, 255, 255]] + QUANT_IMG_RGB2BGR = True + QUANTIZED_DTYPE = "asymmetric_quantized-8" + QUANTIZED_ALGORITHM = "normal" + QUANTIZED_METHOD = "channel" + FLOAT_DTYPE = "float16" + OPTIMIZATION_LEVEL = 2 + TARGET_PLATFORM = soc + CUSTOM_STRING = None + REMOVE_WEIGHT = None + COMPRESS_WEIGHT = False + SINGLE_CORE_MODE = False + MODEL_PRUNNING = False + OP_TARGET = None + DYNAMIC_INPUT = None - OUTPUT_MODEL_FILE = "./output/{}/{}-{}x{}-{}.rknn".format(soc, OUTPUT_MODEL_BASENAME, WIDTH, HEIGHT, soc) - os.makedirs("./output/{}".format(soc), exist_ok=True) + if QUANTIZATION: + quant_suff = "-i8" + else: + quant_suff = "" + + OUTPUT_MODEL_FILE = "./output/{}/{}-{}x{}{}-{}.rknn".format(soc, OUTPUT_MODEL_BASENAME, WIDTH, HEIGHT, quant_suff, soc) + os.makedirs("./output/{}".format(soc), exist_ok=True) - rknn = RKNN() - rknn.config(mean_values=MEAN_VALUES, - std_values=STD_VALUES, - quant_img_RGB2BGR=QUANT_IMG_RGB2BGR, - quantized_dtype=QUANTIZED_DTYPE, - quantized_algorithm=QUANTIZED_ALGORITHM, - quantized_method=QUANTIZED_METHOD, - float_dtype=FLOAT_DTYPE, - optimization_level=OPTIMIZATION_LEVEL, - target_platform=TARGET_PLATFORM, - custom_string=CUSTOM_STRING, - remove_weight=REMOVE_WEIGHT, - compress_weight=COMPRESS_WEIGHT, - single_core_mode=SINGLE_CORE_MODE, - model_pruning=MODEL_PRUNNING, - op_target=OP_TARGET, - dynamic_input=DYNAMIC_INPUT) + rknn = RKNN() + rknn.config(mean_values=MEAN_VALUES, + std_values=STD_VALUES, + quant_img_RGB2BGR=QUANT_IMG_RGB2BGR, + quantized_dtype=QUANTIZED_DTYPE, + quantized_algorithm=QUANTIZED_ALGORITHM, + quantized_method=QUANTIZED_METHOD, + float_dtype=FLOAT_DTYPE, + optimization_level=OPTIMIZATION_LEVEL, + target_platform=TARGET_PLATFORM, + custom_string=CUSTOM_STRING, + remove_weight=REMOVE_WEIGHT, + compress_weight=COMPRESS_WEIGHT, + single_core_mode=SINGLE_CORE_MODE, + model_pruning=MODEL_PRUNNING, + op_target=OP_TARGET, + dynamic_input=DYNAMIC_INPUT) - # if rknn.load_pytorch("./input/" + INPUT_MODEL, [[HEIGHT, WIDTH, 3]]) != 0: - if rknn.load_onnx("./input/" + INPUT_MODEL) != 0: - print('Error loading model.') - exit() + # if rknn.load_pytorch("./input/" + INPUT_MODEL, [[HEIGHT, WIDTH, 3]]) != 0: + if rknn.load_onnx("./input/" + INPUT_MODEL) != 0: + print('Error loading model.') + exit() - if rknn.build(do_quantization=QUANTIZATION, dataset=DATASET) != 0: - print('Error building model.') - exit() + if rknn.build(do_quantization=QUANTIZATION, dataset=DATASET) != 0: + print('Error building model.') + exit() - if rknn.export_rknn(OUTPUT_MODEL_FILE) != 0: - print('Error exporting rknn model.') - exit() + if rknn.export_rknn(OUTPUT_MODEL_FILE) != 0: + print('Error exporting rknn model.') + exit() diff --git a/dataset_coco10.txt b/dataset_coco10.txt deleted file mode 100644 index 60b8311..0000000 --- a/dataset_coco10.txt +++ /dev/null @@ -1,10 +0,0 @@ -datasets/coco10/000000000285.jpg -datasets/coco10/000000000785.jpg -datasets/coco10/000000001296.jpg -datasets/coco10/000000001000.jpg -datasets/coco10/000000000776.jpg -datasets/coco10/000000000139.jpg -datasets/coco10/000000000632.jpg -datasets/coco10/000000000872.jpg -datasets/coco10/000000000724.jpg -datasets/coco10/000000001268.jpg diff --git a/datasets/coco10/dataset_coco10.txt b/datasets/coco10/dataset_coco10.txt new file mode 100644 index 0000000..be1119f --- /dev/null +++ b/datasets/coco10/dataset_coco10.txt @@ -0,0 +1,10 @@ +./000000000285.jpg +./000000000785.jpg +./000000001296.jpg +./000000001000.jpg +./000000000776.jpg +./000000000139.jpg +./000000000632.jpg +./000000000872.jpg +./000000000724.jpg +./000000001268.jpg diff --git a/datasets/coco20/000000005001.jpg b/datasets/coco20/000000005001.jpg new file mode 100644 index 0000000..a7d4437 Binary files /dev/null and b/datasets/coco20/000000005001.jpg differ diff --git a/datasets/coco20/000000038829.jpg b/datasets/coco20/000000038829.jpg new file mode 100644 index 0000000..f275500 Binary files /dev/null and b/datasets/coco20/000000038829.jpg differ diff --git a/datasets/coco20/000000052891.jpg b/datasets/coco20/000000052891.jpg new file mode 100644 index 0000000..57344ef Binary files /dev/null and b/datasets/coco20/000000052891.jpg differ diff --git a/datasets/coco20/000000075612.jpg b/datasets/coco20/000000075612.jpg new file mode 100644 index 0000000..16555e4 Binary files /dev/null and b/datasets/coco20/000000075612.jpg differ diff --git a/datasets/coco20/000000098261.jpg b/datasets/coco20/000000098261.jpg new file mode 100644 index 0000000..57412f7 Binary files /dev/null and b/datasets/coco20/000000098261.jpg differ diff --git a/datasets/coco20/000000181542.jpg b/datasets/coco20/000000181542.jpg new file mode 100644 index 0000000..e3676d3 Binary files /dev/null and b/datasets/coco20/000000181542.jpg differ diff --git a/datasets/coco20/000000215245.jpg b/datasets/coco20/000000215245.jpg new file mode 100644 index 0000000..624e4f1 Binary files /dev/null and b/datasets/coco20/000000215245.jpg differ diff --git a/datasets/coco20/000000277005.jpg b/datasets/coco20/000000277005.jpg new file mode 100644 index 0000000..629cb6e Binary files /dev/null and b/datasets/coco20/000000277005.jpg differ diff --git a/datasets/coco20/000000288685.jpg b/datasets/coco20/000000288685.jpg new file mode 100644 index 0000000..4dc759d Binary files /dev/null and b/datasets/coco20/000000288685.jpg differ diff --git a/datasets/coco20/000000301421.jpg b/datasets/coco20/000000301421.jpg new file mode 100644 index 0000000..2cbfa4e Binary files /dev/null and b/datasets/coco20/000000301421.jpg differ diff --git a/datasets/coco20/000000334371.jpg b/datasets/coco20/000000334371.jpg new file mode 100644 index 0000000..b47ac6d Binary files /dev/null and b/datasets/coco20/000000334371.jpg differ diff --git a/datasets/coco20/000000348481.jpg b/datasets/coco20/000000348481.jpg new file mode 100644 index 0000000..a2cb75c Binary files /dev/null and b/datasets/coco20/000000348481.jpg differ diff --git a/datasets/coco20/000000373353.jpg b/datasets/coco20/000000373353.jpg new file mode 100644 index 0000000..c092511 Binary files /dev/null and b/datasets/coco20/000000373353.jpg differ diff --git a/datasets/coco20/000000397681.jpg b/datasets/coco20/000000397681.jpg new file mode 100644 index 0000000..5b94259 Binary files /dev/null and b/datasets/coco20/000000397681.jpg differ diff --git a/datasets/coco20/000000414673.jpg b/datasets/coco20/000000414673.jpg new file mode 100644 index 0000000..587c370 Binary files /dev/null and b/datasets/coco20/000000414673.jpg differ diff --git a/datasets/coco20/000000419312.jpg b/datasets/coco20/000000419312.jpg new file mode 100644 index 0000000..274ea87 Binary files /dev/null and b/datasets/coco20/000000419312.jpg differ diff --git a/datasets/coco20/000000465822.jpg b/datasets/coco20/000000465822.jpg new file mode 100644 index 0000000..3510d11 Binary files /dev/null and b/datasets/coco20/000000465822.jpg differ diff --git a/datasets/coco20/000000475732.jpg b/datasets/coco20/000000475732.jpg new file mode 100644 index 0000000..51d9685 Binary files /dev/null and b/datasets/coco20/000000475732.jpg differ diff --git a/datasets/coco20/000000559707.jpg b/datasets/coco20/000000559707.jpg new file mode 100644 index 0000000..4811ef1 Binary files /dev/null and b/datasets/coco20/000000559707.jpg differ diff --git a/datasets/coco20/000000574315.jpg b/datasets/coco20/000000574315.jpg new file mode 100644 index 0000000..ad06b6d Binary files /dev/null and b/datasets/coco20/000000574315.jpg differ diff --git a/datasets/coco20/dataset_coco20.txt b/datasets/coco20/dataset_coco20.txt new file mode 100644 index 0000000..d180176 --- /dev/null +++ b/datasets/coco20/dataset_coco20.txt @@ -0,0 +1,20 @@ +./000000005001.jpg +./000000038829.jpg +./000000052891.jpg +./000000075612.jpg +./000000098261.jpg +./000000181542.jpg +./000000215245.jpg +./000000277005.jpg +./000000288685.jpg +./000000301421.jpg +./000000334371.jpg +./000000348481.jpg +./000000373353.jpg +./000000397681.jpg +./000000414673.jpg +./000000419312.jpg +./000000465822.jpg +./000000475732.jpg +./000000559707.jpg +./000000574315.jpg \ No newline at end of file