Skip to content

Commit 07ad721

Browse files
authored
[Other] Add accuracy evaluation scripts (#1034)
* add accuracy scripts * add accuracy scripts * Add FlyCV doc * fix conflict * fix conflict * fix conflict
1 parent 34bea76 commit 07ad721

24 files changed

Lines changed: 1361 additions & 0 deletions

tests/acc_eval/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 模型精度批量验证脚本
2+
3+
本目录下的Python脚本可以在CPU/GPU/昆仑芯/昇腾,以及后续的新增硬件上, 完成对高优模型的精度批量验证.
4+
各模型的精度测试代码是基于Python部署demo修改而成, 当后续有新增硬件或者新增模型时,用户可以通过同样的方式(新增option和模型),添加新的Python代码来完成精度验证.
5+
6+
7+
## 用法
8+
9+
### 1.准备数据集
10+
- 分类模型需要ImageNet验证集以及标签
11+
- 检测模型需要COCO2017验证集以及标签
12+
- 分割模型需要Cityscape验证集以及标签
13+
- PP-OCRv2/v3的数据集在准备脚本中会自行下载.
14+
15+
请将准备好的数据集解压至dataset目录中使用
16+
17+
### 2.精度验证
18+
分类/检测/分割/OCR四个场景的精度验证启用方式是一样的.
19+
其中分类, 检测和分割模型会返回预测精度, OCR模型会返回与GPU预测结果的差异.
20+
21+
```bash
22+
# 进入分类模型目录下
23+
cd classification
24+
# 执行prepare.sh脚本,自动下载并解压模型至models文件夹下
25+
bash prepare.sh
26+
# 首先修改run.sh中的TARGET_DEVICE为想测试的硬件,之后执行run.sh脚本
27+
bash run.sh
28+
# 验证完毕的输出以及精度数据,会保存至log文件夹下,用户自行查看
29+
```
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import fastdeploy as fd
2+
import cv2
3+
import os
4+
5+
6+
def parse_arguments():
7+
import argparse
8+
import ast
9+
parser = argparse.ArgumentParser()
10+
parser.add_argument(
11+
"--model", required=True, help="Path of PaddleClas model.")
12+
parser.add_argument(
13+
"--image", type=str, required=True, help="Path of test image file.")
14+
parser.add_argument(
15+
"--topk", type=int, default=1, help="Return topk results.")
16+
parser.add_argument(
17+
"--device",
18+
type=str,
19+
default='cpu',
20+
help="Type of inference device, support 'cpu' or 'gpu' or 'ipu' or 'kunlunxin' or 'ascend' ."
21+
)
22+
parser.add_argument(
23+
"--use_trt",
24+
type=ast.literal_eval,
25+
default=False,
26+
help="Wether to use tensorrt.")
27+
return parser.parse_args()
28+
29+
30+
def build_option(args):
31+
option = fd.RuntimeOption()
32+
33+
if args.device.lower() == "gpu":
34+
option.use_gpu()
35+
36+
if args.device.lower() == "ipu":
37+
option.use_ipu()
38+
39+
if args.device.lower() == "kunlunxin":
40+
option.use_kunlunxin()
41+
42+
if args.device.lower() == "ascend":
43+
option.use_ascend()
44+
45+
if args.use_trt:
46+
option.use_trt_backend()
47+
return option
48+
49+
50+
args = parse_arguments()
51+
52+
# 配置runtime,加载模型
53+
runtime_option = build_option(args)
54+
55+
model_file = os.path.join(args.model, "inference.pdmodel")
56+
params_file = os.path.join(args.model, "inference.pdiparams")
57+
config_file = os.path.join(args.model, "inference_cls.yaml")
58+
model = fd.vision.classification.PaddleClasModel(
59+
model_file, params_file, config_file, runtime_option=runtime_option)
60+
61+
res = fd.vision.evaluation.eval_classify(
62+
model=model,
63+
image_file_path="../dataset/imagenet/",
64+
label_file_path="../dataset/imagenet/val_list.txt",
65+
topk=1)
66+
print(res)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
mkdir models
2+
cd models
3+
4+
wget https://bj.bcebos.com/paddlehub/fastdeploy/PPLCNet_x1_0_infer.tgz
5+
wget https://bj.bcebos.com/paddlehub/fastdeploy/PPLCNetV2_base_infer.tgz
6+
wget https://bj.bcebos.com/paddlehub/fastdeploy/EfficientNetB7_infer.tgz
7+
wget https://bj.bcebos.com/paddlehub/fastdeploy/EfficientNetB0_small_infer.tgz
8+
wget https://bj.bcebos.com/paddlehub/fastdeploy/GhostNet_x1_3_ssld_infer.tgz
9+
wget https://bj.bcebos.com/paddlehub/fastdeploy/GhostNet_x0_5_infer.tgz
10+
wget https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV1_x0_25_infer.tgz
11+
wget https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV1_ssld_infer.tgz
12+
wget https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV2_x0_25_infer.tgz
13+
wget https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV2_ssld_infer.tgz
14+
wget https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV3_small_x0_35_ssld_infer.tgz
15+
wget https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV3_large_x1_0_ssld_infer.tgz
16+
wget https://bj.bcebos.com/paddlehub/fastdeploy/ShuffleNetV2_x0_25_infer.tgz
17+
wget https://bj.bcebos.com/paddlehub/fastdeploy/ShuffleNetV2_x2_0_infer.tgz
18+
wget https://bj.bcebos.com/paddlehub/fastdeploy/SqueezeNet1_1_infer.tgz
19+
wget https://bj.bcebos.com/paddlehub/fastdeploy/InceptionV3_infer.tgz
20+
wget https://bj.bcebos.com/paddlehub/fastdeploy/PPHGNet_tiny_ssld_infer.tgz
21+
wget https://bj.bcebos.com/paddlehub/fastdeploy/PPHGNet_base_ssld_infer.tgz
22+
wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz
23+
24+
ls *.tgz | xargs -n1 tar xzvf
25+
26+
rm -rf *.tgz
27+
28+
cd ..
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
TARGET_DEVICE=ascend
2+
3+
model_dir=`ls ./models/`
4+
5+
for MODEL_NAME in $model_dir
6+
do
7+
python infer.py --model ./models/$MODEL_NAME --image None --device $TARGET_DEVICE 2>&1 | tee ./log/${MODEL_NAME}_acc.log
8+
done
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import fastdeploy as fd
2+
import cv2
3+
import os
4+
5+
6+
def parse_arguments():
7+
import argparse
8+
import ast
9+
parser = argparse.ArgumentParser()
10+
parser.add_argument(
11+
"--model_dir",
12+
default=None,
13+
help="Path of PaddleDetection model directory")
14+
parser.add_argument(
15+
"--image", default=None, help="Path of test image file.")
16+
parser.add_argument(
17+
"--device",
18+
type=str,
19+
default='cpu',
20+
help="Type of inference device, support 'cpu' or 'gpu'.")
21+
parser.add_argument(
22+
"--use_trt",
23+
type=ast.literal_eval,
24+
default=False,
25+
help="Wether to use tensorrt.")
26+
return parser.parse_args()
27+
28+
29+
def build_option(args):
30+
option = fd.RuntimeOption()
31+
32+
if args.device.lower() == "gpu":
33+
option.use_gpu()
34+
35+
if args.device.lower() == "kunlunxin":
36+
option.use_kunlunxin()
37+
38+
if args.device.lower() == "ascend":
39+
option.use_ascend()
40+
41+
if args.use_trt:
42+
option.use_trt_backend()
43+
option.set_trt_input_shape("image", [1, 3, 640, 640])
44+
option.set_trt_input_shape("scale_factor", [1, 2])
45+
return option
46+
47+
48+
args = parse_arguments()
49+
50+
if args.model_dir is None:
51+
model_dir = fd.download_model(name='faster_rcnn_r50_vd_fpn_2x_coco')
52+
else:
53+
model_dir = args.model_dir
54+
55+
model_file = os.path.join(model_dir, "model.pdmodel")
56+
params_file = os.path.join(model_dir, "model.pdiparams")
57+
config_file = os.path.join(model_dir, "infer_cfg.yml")
58+
59+
# 配置runtime,加载模型
60+
runtime_option = build_option(args)
61+
model = fd.vision.detection.FasterRCNN(
62+
model_file, params_file, config_file, runtime_option=runtime_option)
63+
64+
image_file_path = "../dataset/coco/val2017"
65+
annotation_file_path = "../dataset/coco/annotations/instances_val2017.json"
66+
67+
res = fd.vision.evaluation.eval_detection(model, image_file_path,
68+
annotation_file_path)
69+
print(res)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import fastdeploy as fd
2+
import cv2
3+
import os
4+
5+
6+
def parse_arguments():
7+
import argparse
8+
import ast
9+
parser = argparse.ArgumentParser()
10+
parser.add_argument(
11+
"--model_dir",
12+
default=None,
13+
help="Path of PaddleDetection model directory")
14+
parser.add_argument(
15+
"--image", default=None, help="Path of test image file.")
16+
parser.add_argument(
17+
"--device",
18+
type=str,
19+
default='cpu',
20+
help="Type of inference device, support 'cpu' or 'gpu'.")
21+
parser.add_argument(
22+
"--use_trt",
23+
type=ast.literal_eval,
24+
default=False,
25+
help="Wether to use tensorrt.")
26+
return parser.parse_args()
27+
28+
29+
def build_option(args):
30+
option = fd.RuntimeOption()
31+
32+
if args.device.lower() == "gpu":
33+
# option.use_gpu()
34+
print(
35+
"""GPU inference with Backend::Paddle in python has not been supported yet. \
36+
\nWill ignore this option.""")
37+
38+
if args.use_trt:
39+
# TODO(qiuyanjun): may remove TRT option
40+
# Backend::TRT has not been supported yet.
41+
print(
42+
"""Backend::TRT has not been supported yet, will ignore this option.\
43+
\nPaddleDetection/MaskRCNN has only support Backend::Paddle now."""
44+
)
45+
46+
if args.device.lower() == "kunlunxin":
47+
option.use_kunlunxin()
48+
49+
if args.device.lower() == "ascend":
50+
option.use_ascend()
51+
52+
return option
53+
54+
55+
args = parse_arguments()
56+
57+
if args.model_dir is None:
58+
model_dir = fd.download_model(name='mask_rcnn_r50_1x_coco')
59+
else:
60+
model_dir = args.model_dir
61+
62+
model_file = os.path.join(model_dir, "model.pdmodel")
63+
params_file = os.path.join(model_dir, "model.pdiparams")
64+
config_file = os.path.join(model_dir, "infer_cfg.yml")
65+
66+
# 配置runtime,加载模型
67+
runtime_option = build_option(args)
68+
model = fd.vision.detection.MaskRCNN(
69+
model_file, params_file, config_file, runtime_option=runtime_option)
70+
71+
image_file_path = "../dataset/coco/val2017"
72+
annotation_file_path = "../dataset/coco/annotations/instances_val2017.json"
73+
74+
res = fd.vision.evaluation.eval_detection(model, image_file_path,
75+
annotation_file_path)
76+
print(res)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import fastdeploy as fd
2+
import cv2
3+
import os
4+
5+
6+
def parse_arguments():
7+
import argparse
8+
import ast
9+
parser = argparse.ArgumentParser()
10+
parser.add_argument(
11+
"--model_dir",
12+
default=None,
13+
help="Path of PaddleDetection model directory")
14+
parser.add_argument(
15+
"--image", default=None, help="Path of test image file.")
16+
parser.add_argument(
17+
"--device",
18+
type=str,
19+
default='cpu',
20+
help="Type of inference device, support 'cpu' or 'gpu'.")
21+
parser.add_argument(
22+
"--use_trt",
23+
type=ast.literal_eval,
24+
default=False,
25+
help="Wether to use tensorrt.")
26+
return parser.parse_args()
27+
28+
29+
def build_option(args):
30+
option = fd.RuntimeOption()
31+
32+
if args.device.lower() == "gpu":
33+
option.use_gpu()
34+
35+
if args.device.lower() == "kunlunxin":
36+
option.use_kunlunxin()
37+
38+
if args.device.lower() == "ascend":
39+
option.use_ascend()
40+
41+
if args.use_trt:
42+
option.use_trt_backend()
43+
return option
44+
45+
46+
args = parse_arguments()
47+
48+
if args.model_dir is None:
49+
model_dir = fd.download_model(name='picodet_l_320_coco_lcnet')
50+
else:
51+
model_dir = args.model_dir
52+
53+
model_file = os.path.join(model_dir, "model.pdmodel")
54+
params_file = os.path.join(model_dir, "model.pdiparams")
55+
config_file = os.path.join(model_dir, "infer_cfg.yml")
56+
57+
# 配置runtime,加载模型
58+
runtime_option = build_option(args)
59+
model = fd.vision.detection.PicoDet(
60+
model_file, params_file, config_file, runtime_option=runtime_option)
61+
62+
image_file_path = "../dataset/coco/val2017"
63+
annotation_file_path = "../dataset/coco/annotations/instances_val2017.json"
64+
65+
res = fd.vision.evaluation.eval_detection(model, image_file_path,
66+
annotation_file_path)
67+
print(res)

0 commit comments

Comments
 (0)