jounery-d commited on
Commit
c7c39b0
·
verified ·
1 Parent(s): 01f4ebb

Upload 3 files

Browse files
Files changed (3) hide show
  1. config/config_spec.yaml +169 -0
  2. config/convert.sh +1 -0
  3. config/readme.txt +76 -0
config/config_spec.yaml ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ qconfig_dict:
2
+ w_observer: minmax #default: minmax. option: minmax percentile
3
+ a_observer: mse #default: mse. option: minmax percentile mse kl
4
+ w_qscheme:
5
+ bit: 8 #default: 8. option: 4 8 mix
6
+ per_channel: true #default: false. option: true false
7
+ a_qscheme:
8
+ bit: 8 # only support 8 now
9
+ per_channel: false # only support false now
10
+ output_layer:
11
+ names: [ ] # assign quant method for specific layers
12
+ a_observer: kl # final output use kl quant take effect probably
13
+ bit: 8
14
+ quantize:
15
+ quantize_type: naive_ptq # default: naive_ptq. option: naive_ptq advanced_ptq
16
+ calib_steps: 16
17
+ backend: Octans #default: Octans. represent AX520
18
+ QuantizationOptimizationPass:
19
+ LayerwiseEqualizationPass: true
20
+ LearnedStepSizePass: false
21
+ BiasCorrectionPass: true
22
+ AdaroundPass: false
23
+ deploy:
24
+ NPUDeploy: true # enable generate axmodel
25
+ export: true # enable generate quant model
26
+ output_bin_name: deploy.axmodel #rename output axmodel. type: string. required: false. default: compiled.axmodel.
27
+ output_path: output #axmodel and log output directory. type: string. required: true.
28
+ model: #required: true
29
+ path: deploy.onnx #input model file path. type: string. required: true.
30
+ data: #required: true
31
+ path: filelist.txt #quantize calibration dataset,only support images list now.
32
+ batch_size: 16
33
+ num_workers: 16
34
+ input_shape: # onnx model input shape
35
+ - 1
36
+ - 3
37
+ - 640
38
+ - 640
39
+ mean:
40
+ - 0
41
+ std:
42
+ - 255
43
+ task: 'det'
44
+ post:
45
+ yolo_type: 'yolov5'
46
+ anchors: ''
47
+ class_names: {
48
+ '0': 'person',
49
+ '1': 'bicycle',
50
+ '2': 'car',
51
+ '3': 'motorcycle',
52
+ '4': 'airplane',
53
+ '5': 'bus',
54
+ '6': 'train',
55
+ '7': 'truck',
56
+ '8': 'boat',
57
+ '9': 'traffic light',
58
+ '10': 'fire hydrant',
59
+ '11': 'stop sign',
60
+ '12': 'parking meter',
61
+ '13': 'bench',
62
+ '14': 'bird',
63
+ '15': 'cat',
64
+ '16': 'dog',
65
+ '17': 'horse',
66
+ '18': 'sheep',
67
+ '19': 'cow',
68
+ '20': 'elephant',
69
+ '21': 'bear',
70
+ '22': 'zebra',
71
+ '23': 'giraffe',
72
+ '24': 'backpack',
73
+ '25': 'umbrella',
74
+ '26': 'handbag',
75
+ '27': 'tie',
76
+ '28': 'suitcase',
77
+ '29': 'frisbee',
78
+ '30': 'skis',
79
+ '31': 'snowboard',
80
+ '32': 'sports ball',
81
+ '33': 'kite',
82
+ '34': 'baseball bat',
83
+ '35': 'baseball glove',
84
+ '36': 'skateboard',
85
+ '37': 'surfboard',
86
+ '38': 'tennis racket',
87
+ '39': 'bottle',
88
+ '40': 'wine glass',
89
+ '41': 'cup',
90
+ '42': 'fork',
91
+ '43': 'knife',
92
+ '44': 'spoon',
93
+ '45': 'bowl',
94
+ '46': 'banana',
95
+ '47': 'apple',
96
+ '48': 'sandwich',
97
+ '49': 'orange',
98
+ '50': 'broccoli',
99
+ '51': 'carrot',
100
+ '52': 'hot dog',
101
+ '53': 'pizza',
102
+ '54': 'donut',
103
+ '55': 'cake',
104
+ '56': 'chair',
105
+ '57': 'couch',
106
+ '58': 'potted plant',
107
+ '59': 'bed',
108
+ '60': 'dining table',
109
+ '61': 'toilet',
110
+ '62': 'tv',
111
+ '63': 'laptop',
112
+ '64': 'mouse',
113
+ '65': 'remote',
114
+ '66': 'keyboard',
115
+ '67': 'cell phone',
116
+ '68': 'microwave',
117
+ '69': 'oven',
118
+ '70': 'toaster',
119
+ '71': 'sink',
120
+ '72': 'refrigerator',
121
+ '73': 'book',
122
+ '74': 'clock',
123
+ '75': 'vase',
124
+ '76': 'scissors',
125
+ '77': 'teddy bear',
126
+ '78': 'hair drier',
127
+ '79': 'toothbrush',
128
+ }
129
+ executing_device: 'cuda'
130
+ UseDVPResize: false
131
+ input_processors: #required: false
132
+ - tensor_name: images #input tensor name in origin model. "DEFAULT" means processor for all input tensors. type: string. required: true.
133
+ tensor_format: RGB #input tensor format in origin model. type: enum. required: false. default: AutoColorSpace. option: AutoColorSpace, BGR, RGB, GRAY.
134
+ tensor_layout: NCHW #input tensor layout in origin model. type: enum. required: false. only support NCHW now.
135
+ src_format: YUV420SP #input format in runtime. type: enum. required: false. default: AutoColorSpace. option: AutoColorSpace, GRAY, BGR, RGB, YUYV422, UYVY422, YUV420SP, YVU420SP.
136
+ src_layout: NCHW #input layout in runtime; type: enum. required: false. default: NCHW. option: NHWC, NCHW.
137
+ src_dtype: U8 #input data type in runtime. type: enum. required: false. default: U8. option: U8, S8, U16, S16, U32, S32, FP16, FP32.
138
+ csc_mode: NoCSC #color space mode. type: enum. required: false. default: NoCSC. option: NoCSC, Matrix, FullRange, LimitedRange.
139
+ csc_mat: [] #color space conversion matrix, 12 elements array that represents a 3x4 matrix. type: float array. required: false. default: [].
140
+ output_processors: #required: false
141
+ - dst_type: #output data type in runtime. type: enum. required: false. default: S8. option: S8, FP32.
142
+ tensor_name: #output tensor name in origin model. required: false.
143
+ - dst_type: #output data type in runtime. required: false.
144
+ tensor_name: #output tensor name in origin model. required: false.
145
+ - dst_type: #output data type in runtime. required: false.
146
+ tensor_name: #output tensor name in origin model. required: false.
147
+ process: #required: false
148
+ seed: 1005
149
+ evaluate: #required: false
150
+ path: 'coco/val.txt'
151
+ analysis_graph_method: false
152
+ analysis_layer_method: false
153
+ analysis_metric: cosine
154
+ analysis_statistical_method: false
155
+ evaluate_fake_quant_float: false
156
+ evaluate_fake_quant_int: false
157
+ evaluate_float: false
158
+ Xsnn: #required: false
159
+ UseMemPoolOptim: true
160
+ UseDVPResize: false
161
+ UseXsnnEval: false
162
+ path: coco/val.txt
163
+ YUVHeight: ''
164
+ YUVWidth: ''
165
+
166
+
167
+
168
+
169
+
config/convert.sh ADDED
@@ -0,0 +1 @@
 
 
1
+ python app/ppq-xs/Helium/myes.py --config config/config_spec.yaml
config/readme.txt ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ 模型转换说明:
3
+
4
+ ##1、环境准备(镜像版或源码版):
5
+ *docker镜像版安装:w4a8quant-1.7.6.tar.gz
6
+ *源码版安装:ppq-xs-1.7.6 (pip -r requirements.txt)
7
+
8
+ ##2、模型从.pt转.onnx
9
+ yolov5系类参考脚本:
10
+ https://github.com/ultralytics/yolov5/blob/master/export.py
11
+
12
+ yolov8/yolov11系类参考脚本:
13
+ https://github.com/ultralytics/ultralytics/blob/main/tests/test_exports.py
14
+
15
+
16
+ ##3、模型从.onnx转换到.axmodel
17
+ 模型配置文件(通用):
18
+ config/config_spec.yaml
19
+
20
+ #模型及量化数据准备:
21
+ 准备量化图片(建议使用训练的图片数据1~100张),将图片路径保存为文件列表filelist.txt
22
+ 修改配置文件如下:
23
+ data:
24
+ path: filelist.txt #quantize calibration dataset,only support images list now.
25
+
26
+ #准备onnx模型:
27
+ 修改配置文件模型路径:
28
+ model:
29
+ path: deploy.onnx #input model file path. type: string. required: true.
30
+
31
+ 修改配置文件模型信息,如下:
32
+ input_shape: # onnx model input shape
33
+ - 1
34
+ - 3
35
+ - 640
36
+ - 640
37
+ mean:
38
+ - 0
39
+ std:
40
+ - 255
41
+
42
+ 修改生成axmodel文件名,如下:
43
+ deploy:
44
+ NPUDeploy: true # enable generate axmodel
45
+ export: true # enable generate quant model
46
+ output_bin_name: deploy.axmodel #rename output axmodel. type: string. required: false. default: compiled.axmodel.
47
+
48
+ #config修改完成后,转换命令如下:
49
+ python app/ppq-xs/Helium/myes.py --config config/config_spec.yaml
50
+
51
+ ## 板端运行sample, 目前提供yolov5、yolov8两个模型参考示例
52
+ samples/demo_yolov5
53
+ samples/demo_yolov8
54
+
55
+ 该示例可以直接运行并绘制出目标框,对用户自己的模型,需修改如下地方:
56
+ #修改模型位置,替换该目录下的模型:
57
+ /data/model/deploy.axmodel
58
+
59
+ #修改模型检测类别数:
60
+ 文件位置:src/detech.h,修改如下:
61
+ /***************************************************************************************************
62
+ * 宏定义
63
+ ***************************************************************************************************/
64
+ #define DET_LABEL_NUM (80) // 对应类别数
65
+
66
+ #修改模型输入shape:
67
+ 文件位置:xpu_infer.cpp,修改如下:
68
+ static int gXpuTestNetWidth = 640; // 网络宽度
69
+ static int gXpuTestNetHeight = 640; // 网络高度
70
+
71
+ #修改完成后,板端加载ko驱动
72
+ 运行目录下run.sh即可
73
+
74
+
75
+
76
+