Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
fd85f9db
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
1 年多 前同步成功
通知
51
Star
1434
Fork
344
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
16
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSlim
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
16
合并请求
16
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
fd85f9db
编写于
8月 18, 2022
作者:
G
Guanghua Yu
提交者:
GitHub
8月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix YOLO series act demo some bug (#1359)
上级
3d0755b1
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
37 addition
and
45 deletion
+37
-45
example/auto_compression/detection/configs/ppyoloe_l_qat_dis.yaml
...auto_compression/detection/configs/ppyoloe_l_qat_dis.yaml
+1
-0
example/auto_compression/detection/configs/ppyoloe_s_qat_dis.yaml
...auto_compression/detection/configs/ppyoloe_s_qat_dis.yaml
+1
-0
example/auto_compression/pytorch_yolo_series/README.md
example/auto_compression/pytorch_yolo_series/README.md
+18
-32
example/auto_compression/pytorch_yolo_series/configs/yolov5s_qat_dis.yaml
...pression/pytorch_yolo_series/configs/yolov5s_qat_dis.yaml
+0
-1
example/auto_compression/pytorch_yolo_series/eval.py
example/auto_compression/pytorch_yolo_series/eval.py
+4
-1
example/auto_compression/pytorch_yolo_series/post_process.py
example/auto_compression/pytorch_yolo_series/post_process.py
+2
-2
example/post_training_quantization/pytorch_yolo_series/configs/yolov5s_ptq.yaml
...quantization/pytorch_yolo_series/configs/yolov5s_ptq.yaml
+1
-1
example/post_training_quantization/pytorch_yolo_series/eval.py
...le/post_training_quantization/pytorch_yolo_series/eval.py
+6
-4
example/post_training_quantization/pytorch_yolo_series/post_process.py
...training_quantization/pytorch_yolo_series/post_process.py
+4
-4
未找到文件。
example/auto_compression/detection/configs/ppyoloe_l_qat_dis.yaml
浏览文件 @
fd85f9db
...
...
@@ -13,6 +13,7 @@ Distillation:
loss
:
soft_label
Quantization
:
onnx_format
:
true
use_pact
:
true
activation_quantize_type
:
'
moving_average_abs_max'
quantize_op_types
:
...
...
example/auto_compression/detection/configs/ppyoloe_s_qat_dis.yaml
浏览文件 @
fd85f9db
...
...
@@ -13,6 +13,7 @@ Distillation:
loss
:
soft_label
Quantization
:
onnx_format
:
true
use_pact
:
true
activation_quantize_type
:
'
moving_average_abs_max'
quantize_op_types
:
...
...
example/auto_compression/pytorch_yolo_series/README.md
浏览文件 @
fd85f9db
...
...
@@ -33,7 +33,7 @@
| YOLOv7 | ACT量化训练 | 640
*640 | **50.9** | 36MB | - | - | **4.55ms*
*
|
[
config
](
./configs/yolov7_qat_dis.yaml
)
|
[
Infer Model
](
https://bj.bcebos.com/v1/paddle-slim-models/act/yolov7_quant.tar
)
|
[
ONNX Model
](
https://bj.bcebos.com/v1/paddle-slim-models/act/yolov7_quant.onnx
)
|
| | | | | | | | | |
| YOLOv7-Tiny | Base模型 | 640
*
640 | 37.3 | 24MB | 5.06ms | 2.32ms | - | - |
[
Model
](
https://paddle-slim-models.bj.bcebos.com/act/yolov7-tiny.onnx
)
|
| YOLOv7-Tiny | 离线量化 | 640
*
640 |
-
| 6.1MB | - | - | 1.68ms | - | - |
| YOLOv7-Tiny | 离线量化 | 640
*
640 |
35.8
| 6.1MB | - | - | 1.68ms | - | - |
| YOLOv7-Tiny | ACT量化训练 | 640
*640 | **37.0** | 6.1MB | - | - | **1.68ms*
*
|
[
config
](
./configs/yolov7_tiny_qat_dis.yaml
)
|
[
Infer Model
](
https://bj.bcebos.com/v1/paddle-slim-models/act/yolov7_tiny_quant.tar
)
|
[
ONNX Model
](
https://bj.bcebos.com/v1/paddle-slim-models/act/yolov7_tiny_quant.onnx
)
|
说明:
...
...
@@ -43,15 +43,15 @@
## 3. 自动压缩流程
#### 3.1 准备环境
-
PaddlePaddle
develop每日版本 (可从
[
Paddle官网
](
https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/develop/install/pip/linux-pip.html
)
下载
安装)
-
PaddlePaddle
>= 2.3.2版本 (可从
[
Paddle官网
](
https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html
)
根据相应环境的安装指令进行
安装)
-
PaddleSlim develop 版本
(1)安装paddlepaddle
:
```
shell
(1)安装paddlepaddle
```
# CPU
pip
install
paddlepaddle
pip install paddlepaddle
==2.3.2
# GPU
pip
install
paddlepaddle-gpu
pip install paddlepaddle-gpu
==2.3.2
```
(2)安装paddleslim:
...
...
@@ -90,22 +90,22 @@ dataset/coco/
-
YOLOv5:
可通过
[
ultralytics/yolov5
](
https://github.com/ultralytics/yolov5
)
官方的
[
导出教程
](
https://github.com/ultralytics/yolov5/issues/251
)
来准备ONNX模型。也可以下载准备好的
[
yolov5s.onnx
](
https://paddle-slim-models.bj.bcebos.com/act/yolov5s.onnx
)
。
```
shell
python export.py
--weights
yolov5s.pt
--include
onnx
```
本示例模型使用
[
ultralytics/yolov5
](
https://github.com/ultralytics/yolov5
)
的master分支导出,要求v6.1之后的ONNX模型,可以根据
官方的
[
导出教程
](
https://github.com/ultralytics/yolov5/issues/251
)
来准备ONNX模型。也可以下载准备好的
[
yolov5s.onnx
](
https://paddle-slim-models.bj.bcebos.com/act/yolov5s.onnx
)
。
```
shell
python export.py
--weights
yolov5s.pt
--include
onnx
```
-
YOLOv6:
可通过
[
meituan/YOLOv6
](
https://github.com/meituan/YOLOv6
)
官方的
[
导出教程
](
https://github.com/meituan/YOLOv6/blob/main/deploy/ONNX/README.md
)
来准备ONNX模型。也可以下载已经准备好的
[
yolov6s.onnx
](
https://paddle-slim-models.bj.bcebos.com/act/yolov6s.onnx
)
。
可通过
[
meituan/YOLOv6
](
https://github.com/meituan/YOLOv6
)
官方的
[
导出教程
](
https://github.com/meituan/YOLOv6/blob/main/deploy/ONNX/README.md
)
来准备ONNX模型。也可以下载已经准备好的
[
yolov6s.onnx
](
https://paddle-slim-models.bj.bcebos.com/act/yolov6s.onnx
)
。
-
YOLOv7: 可通过
[
WongKinYiu/yolov7
](
https://github.com/WongKinYiu/yolov7
)
的导出脚本来准备ONNX模型,具体步骤如下:
```
shell
git clone https://github.com/WongKinYiu/yolov7.git
python export.py
--weights
yolov7-tiny.pt
--grid
```
```
shell
git clone https://github.com/WongKinYiu/yolov7.git
python export.py
--weights
yolov7-tiny.pt
--grid
```
**注意**
:目前ACT支持不带NMS
模型,使用如上命令导出即可。也可以直接下载我们已经准备好的
[
yolov7.onnx
](
https://paddle-slim-models.bj.bcebos.com/act/yolov7-tiny.onnx
)
。
**注意**
:目前ACT支持
**不带NMS**
模型,使用如上命令导出即可。也可以直接下载我们已经准备好的
[
yolov7.onnx
](
https://paddle-slim-models.bj.bcebos.com/act/yolov7-tiny.onnx
)
。
#### 3.4 自动压缩并产出模型
...
...
@@ -138,25 +138,11 @@ python eval.py --config_path=./configs/yolov7_tiny_qat_dis.yaml
#### 导出至ONNX使用TensorRT部署
-
首先安装Paddle2onnx:
```
shell
pip
install
paddle2onnx
==
1.0.0rc3
```
-
然后将量化模型导出至ONNX:
```
shell
paddle2onnx
--model_dir
output/
\
--model_filename
model.pdmodel
\
--params_filename
model.pdiparams
\
--opset_version
13
\
--enable_onnx_checker
True
\
--save_file
yolov7_quant.onnx
\
--deploy_backend
tensorrt
```
执行完自动压缩后会默认在
`save_dir`
中生成
`quant_model.onnx`
的ONNX模型文件,可以直接使用TensorRT测试脚本进行验证。
-
进行测试:
```
shell
python yolov7_onnx_trt.py
--model_path
=
yolov7_quant
.onnx
--image_file
=
images/000000570688.jpg
--precision
=
int8
python yolov7_onnx_trt.py
--model_path
=
output/quant_model
.onnx
--image_file
=
images/000000570688.jpg
--precision
=
int8
```
#### Paddle-TensorRT部署
...
...
example/auto_compression/pytorch_yolo_series/configs/yolov5s_qat_dis.yaml
浏览文件 @
fd85f9db
...
...
@@ -15,7 +15,6 @@ Distillation:
Quantization
:
onnx_format
:
true
use_pact
:
true
onnx_format
:
False
activation_quantize_type
:
'
moving_average_abs_max'
quantize_op_types
:
-
conv2d
...
...
example/auto_compression/pytorch_yolo_series/eval.py
浏览文件 @
fd85f9db
...
...
@@ -32,6 +32,8 @@ def argsparser():
default
=
None
,
help
=
"path of compression strategy config."
,
required
=
True
)
parser
.
add_argument
(
'--batch_size'
,
type
=
int
,
default
=
1
,
help
=
"Batch size of model input."
)
parser
.
add_argument
(
'--devices'
,
type
=
str
,
...
...
@@ -83,7 +85,8 @@ def main():
anno_path
=
global_config
[
'val_anno_path'
])
global
anno_file
anno_file
=
dataset
.
ann_file
val_loader
=
paddle
.
io
.
DataLoader
(
dataset
,
batch_size
=
1
)
val_loader
=
paddle
.
io
.
DataLoader
(
dataset
,
batch_size
=
FLAGS
.
batch_size
,
drop_last
=
True
)
eval
()
...
...
example/auto_compression/pytorch_yolo_series/post_process.py
浏览文件 @
fd85f9db
...
...
@@ -159,8 +159,8 @@ class YOLOPostProcess(object):
if
len
(
pred
.
shape
)
==
1
:
pred
=
pred
[
np
.
newaxis
,
:]
pred_bboxes
=
pred
[:,
:
4
]
scale
_factor
=
np
.
tile
(
scale_factor
[
i
][::
-
1
],
(
1
,
2
))
pred_bboxes
/=
scale
_factor
scale
=
np
.
tile
(
scale_factor
[
i
][::
-
1
],
(
2
))
pred_bboxes
/=
scale
bbox
=
np
.
concatenate
(
[
pred
[:,
-
1
][:,
np
.
newaxis
],
pred
[:,
-
2
][:,
np
.
newaxis
],
...
...
example/post_training_quantization/pytorch_yolo_series/configs/yolov5s_ptq.yaml
浏览文件 @
fd85f9db
arch
:
YOLOv5
model_dir
:
./yolov5s.onnx
dataset_dir
:
/
dataset/coco/
dataset_dir
:
dataset/coco/
train_image_dir
:
train2017
val_image_dir
:
val2017
train_anno_path
:
annotations/instances_train2017.json
...
...
example/post_training_quantization/pytorch_yolo_series/eval.py
浏览文件 @
fd85f9db
...
...
@@ -20,7 +20,7 @@ from tqdm import tqdm
import
paddle
from
paddleslim.common
import
load_config
as
load_slim_config
from
paddleslim.common
import
load_inference_model
from
post_process
import
YOLO
v6
PostProcess
,
coco_metric
from
post_process
import
YOLOPostProcess
,
coco_metric
from
dataset
import
COCOValDataset
...
...
@@ -32,6 +32,8 @@ def argsparser():
default
=
None
,
help
=
"path of compression strategy config."
,
required
=
True
)
parser
.
add_argument
(
'--batch_size'
,
type
=
int
,
default
=
1
,
help
=
"Batch size of model input."
)
parser
.
add_argument
(
'--devices'
,
type
=
str
,
...
...
@@ -60,8 +62,7 @@ def eval():
feed
=
{
feed_target_names
[
0
]:
data_all
[
'image'
]},
fetch_list
=
fetch_targets
,
return_numpy
=
False
)
res
=
{}
postprocess
=
YOLOv6PostProcess
(
postprocess
=
YOLOPostProcess
(
score_threshold
=
0.001
,
nms_threshold
=
0.65
,
multi_label
=
True
)
res
=
postprocess
(
np
.
array
(
outs
[
0
]),
data_all
[
'scale_factor'
])
bboxes_list
.
append
(
res
[
'bbox'
])
...
...
@@ -83,7 +84,8 @@ def main():
anno_path
=
config
[
'val_anno_path'
])
global
anno_file
anno_file
=
dataset
.
ann_file
val_loader
=
paddle
.
io
.
DataLoader
(
dataset
,
batch_size
=
1
)
val_loader
=
paddle
.
io
.
DataLoader
(
dataset
,
batch_size
=
FLAGS
.
batch_size
,
drop_last
=
True
)
eval
()
...
...
example/post_training_quantization/pytorch_yolo_series/post_process.py
浏览文件 @
fd85f9db
...
...
@@ -70,9 +70,9 @@ def nms(boxes, scores, iou_threshold):
return
keep
class
YOLO
v6
PostProcess
(
object
):
class
YOLOPostProcess
(
object
):
"""
Post process of YOLO
v6
network.
Post process of YOLO
serise
network.
args:
score_threshold(float): Threshold to filter out bounding boxes with low
confidence score. If not provided, consider all boxes.
...
...
@@ -159,8 +159,8 @@ class YOLOv6PostProcess(object):
if
len
(
pred
.
shape
)
==
1
:
pred
=
pred
[
np
.
newaxis
,
:]
pred_bboxes
=
pred
[:,
:
4
]
scale
_factor
=
np
.
tile
(
scale_factor
[
i
][::
-
1
],
(
1
,
2
))
pred_bboxes
/=
scale
_factor
scale
=
np
.
tile
(
scale_factor
[
i
][::
-
1
],
(
2
))
pred_bboxes
/=
scale
bbox
=
np
.
concatenate
(
[
pred
[:,
-
1
][:,
np
.
newaxis
],
pred
[:,
-
2
][:,
np
.
newaxis
],
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录