This commit is contained in:
li-zhenyun
2022-09-25 09:39:27 +08:00
parent 9b5c22c3e4
commit ecf525276b
10 changed files with 140 additions and 12 deletions

View File

@@ -34,8 +34,10 @@
│ visualize.py
│ main.py
├─image -- 自行创建,存放测图片
├─dataset (自行创建,存放测图片)
├─img
│ test_output.png
├─plugins
│ libyolov3postprocess.
@@ -60,7 +62,13 @@
### 2.1 环境变量
<br>
运行模型前要设置环境变量,需要运行的命令已经写进shell脚本,请自行修改bash脚本中的SDK_PATH和ascend_toolkit_path
运行模型前要设置环境变量,命令如下,请自行修改bash脚本中的SDK_PATH和ascend_toolkit_path
```bash
. ${SDK-path}/set_env.sh ## 修改SDK-path为你自己的SDK安装路径
. ${ascend_toolkit_path}/set_env.sh ## 修改ascend_toolkit_path为自己Ascend的ascend_toolkit路径
```
<br>
### 2.2 软件依赖
@@ -75,13 +83,60 @@ numpy|1.21.2
<br>
## 3.模型转换
#### 步骤1 下载onnx模型文件
本工程原型是pytorch模型需要使用atc工具转换为om模型模型权重文件已上传至
https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/ascend_community_projects/Insulator_detection/insulator.onnx
请点击下载,将下载好的模型放到model文件夹下,随后执行脚本
<br>
#### 步骤2 将模型放到models目录下
<br>
#### 步骤3 AIPP配置
由于pipeline中的解码格式为YUV而模型的输入格式为RGB所以需要在atc模型转换的时候配置AIPPAIPP配置的内容如下
```
aipp_op {
aipp_mode: static
input_format : YUV420SP_U8
csc_switch : true
rbuv_swap_switch : false
matrix_r0c0 : 256
matrix_r0c1 : 0
matrix_r0c2 : 359
matrix_r1c0 : 256
matrix_r1c1 : -88
matrix_r1c2 : -183
matrix_r2c0 : 256
matrix_r2c1 : 454
matrix_r2c2 : 0
input_bias_0 : 0
input_bias_1 : 128
input_bias_2 : 128
var_reci_chn_0 : 0.003921568627451
var_reci_chn_1 : 0.003921568627451
var_reci_chn_2 : 0.003921568627451
}
```
#### 步骤4 转换模型
跳转到models目录运行如下命令进行模型转换。
```
bash run.sh
```
模型转换结果如下如果出现ATC run success说明转换模型成功
```bash
ATC start working now, please wait for a moment.
ATC run success, welcome to the next use.
```
## 4.编译运行
<br>
@@ -97,11 +152,44 @@ bash run.sh
```
python main.py
```
查看图片检测结果是否成功
图片结果保存在自己设置的RESULTFILE目录下测试图片结果如下
## 5.评估精度和FPS
<br>
首先在test目录下创建dataset文件夹把要测试的coco数据集的JPGIMAGES和json放到该文件夹下。随后运行parse_COCO.py然后运行testmain获取数据集最后再运行map_calculate获取精度和FPS精度结果保存在output文件夹下
![pipeline](./img/test_output.png)
## 5.评估精度
<br>
首先在test目录下创建dataset文件夹把要测试的coco数据集的JPGIMAGES和json放到该文件夹下。运行如下代码
```bash
python parse_coco.py
python testmain.py
python map_calculate.py
```
精度评估的结果会存放到output文件下评估的结果如下图
![precision](./img/precision.png)
## 6.FPS测试
选择一张1080P的图片放到dataset目录下跳转至python目录
```
python main.py
```
结果如下
![fps](./img/fps.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

View File

@@ -0,0 +1 @@
insulator

View File

@@ -0,0 +1,3 @@
atc --output_type=FP32 --insert_op_conf=yolo_aipp.cfg --input_format=NCHW --framework=5 --model=./insulator.onnx --input_shape="input:1,3,416,416" --output=./insulator --soc_version=Ascend310 --enable_small_channel=1

View File

@@ -0,0 +1,10 @@
CLASS_NUM=1
BIASES_NUM=18
BIASES=12,16,19,36,40,28,36,75,76,55,72,146,142,110,192,243,459,401
SCORE_THRESH=0.3
OBJECTNESS_THRESH=0.3
IOU_THRESH=0.45
YOLO_TYPE=3
ANCHOR_DIM=3
MODEL_TYPE=1
RESIZE_FLAG=0

View File

@@ -0,0 +1,22 @@
aipp_op {
aipp_mode: static
input_format : YUV420SP_U8
csc_switch : true
rbuv_swap_switch : false
matrix_r0c0 : 256
matrix_r0c1 : 0
matrix_r0c2 : 359
matrix_r1c0 : 256
matrix_r1c1 : -88
matrix_r1c2 : -183
matrix_r2c0 : 256
matrix_r2c1 : 454
matrix_r2c2 : 0
input_bias_0 : 0
input_bias_1 : 128
input_bias_2 : 128
var_reci_chn_0 : 0.003921568627451
var_reci_chn_1 : 0.003921568627451
var_reci_chn_2 : 0.003921568627451
}

View File

@@ -29,7 +29,7 @@
"mxpi_tensorinfer0": {
"props": {
"dataSource": "mxpi_imageresize0",
"modelPath": "../model/insulator.om"
"modelPath": "../models/insulator.om"
},
"factory": "mxpi_tensorinfer",
"next": "mxpi_objectpostprocessor0"
@@ -37,8 +37,8 @@
"mxpi_objectpostprocessor0": {
"props": {
"dataSource": "mxpi_tensorinfer0",
"postProcessConfigPath":"../model/yolo.cfg",
"labelPath": "../model/label.names",
"postProcessConfigPath":"../models/yolo.cfg",
"labelPath": "../models/label.names",
"postProcessLibPath": "${MX_SDK_HOME}/lib/modelpostprocessors/libyolov3postprocess.so"
},
"factory": "mxpi_objectpostprocessor",

View File

@@ -43,8 +43,12 @@ if __name__ == '__main__':
exit()
dataInput = MxDataInput()
# It is best to use absolute path
FILENAME = "../image/test.jpg"
RESULTFILE = "../image/output.jpg"
FILENAME = "../dataset/test.jpg"
RESULTFILE = "../dataset/output.jpg"
image = Image.open(INPUT)
if image.format != "JPEG" or image.format != "JPG":
print("the image is not JPG format")
exit()
if os.path.exists(FILENAME) != 1:
print("The test image does not exist. Exit.")
exit()