This commit is contained in:
MarcA711
2023-12-25 01:45:02 +01:00
parent f0cea8b81f
commit 36a637dd0a
25 changed files with 95 additions and 64 deletions

4
.gitignore vendored
View File

@@ -1,2 +1,4 @@
/input/
/output/
/output/
!/input/model_onnx.py

115
conv.py
View File

@@ -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()

View File

@@ -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

View File

@@ -0,0 +1,10 @@
./000000000285.jpg
./000000000785.jpg
./000000001296.jpg
./000000001000.jpg
./000000000776.jpg
./000000000139.jpg
./000000000632.jpg
./000000000872.jpg
./000000000724.jpg
./000000001268.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 281 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

View File

@@ -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