Skip to content

Commit 121de32

Browse files
committed
modify readme and add demo dir
1 parent bf54b4d commit 121de32

17 files changed

+195
-194
lines changed

README.md

+64-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,65 @@
11
# PPDetectionPytorch
2-
> use pytorch to reimplement paddle detection
2+
3+
> use pytorch to reimplement paddle detection
4+
5+
[简体中文](README_cn.md) | [English](README_en.md)
6+
7+
## 说明
8+
本项目旨在:
9+
- 学习目标检测和PPDetection代码
10+
- 使得PPDetection的模型能在pytorch上使用
11+
- 提供为paddle转pytorch提供参考
12+
13+
## TODO
14+
- [ ] yolov3 推理部分的目标检测况坐标转换部分
15+
- [ ] 旋转框检测模型PP-YOLOE-R
16+
- [ ] 小目标检测模型PP-YOLOE-SOD
17+
- [ ] PP-Human v2
18+
- [ ] PP-Vehicle
19+
- [ ] 目标检测模型训练部分
20+
- [ ] 多目标跟踪
21+
- [ ] ...
22+
23+
## 注意
24+
25+
`PPDetectionPytorch`是基于[PaddleDetection](https://github.com/PaddlePaddle/PaddleDetection)[PaddleYOLO](https://github.com/PaddlePaddle/PaddleYOLO) 的pytorch 实现。
26+
27+
**近期更新**
28+
29+
- 2022-12-21 迁移模型推理部分:picodet,ppyoloe,yolox,yolov5,yolov6,yolov7,rtmdet
30+
- 2022-12-19 基础代码迁移
31+
32+
## 使用说明
33+
34+
### 代码路径修改
35+
36+
[WORK_DIR](./ppdettorch/utils/constant.py) Constants.WORK_DIR 改为你自己的代码绝对路径
37+
38+
### 依赖
39+
- paddlepaddle-gpu 需要安装 ,这里用于自动将PPDetection提供的模型权重转换成pytorch权重
40+
- pytorch 需要安装
41+
42+
### 模型推理
43+
#### 模型权重
44+
> 首次推理时自动下载对应configs 中的模型权重到 ~/.cache/paddle/weights目录,这个目录是PPDetection推理模型的下载指定目录,
45+
> 模型权重会自动转换成pytoch 权重,同时保存到当前目录。
46+
[模型权重自动转换代码](./convert_paddle_detection_to_torch.py)
47+
#### 运行推理测试
48+
> 目前只转换了部分模型权重:
49+
[run_detection_infer.py](./tests/process/infer/run_detection_infer.py) 中 run_picodet_coco_batch函数 使用不同的model_class 进行推理测试
50+
>
51+
52+
#### 推理结果输出
53+
> 输出推理结果和对应网络的paddle和pytorch模型权重名称
54+
[推理输出目录](./outputs/models/detection)
55+
56+
57+
58+
## 参考
59+
60+
- [PaddleDetection](https://github.com/PaddlePaddle/PaddleDetection)
61+
- [PaddleYOLO](https://github.com/PaddlePaddle/PaddleYOLO)
62+
- [Paddle](https://github.com/PaddlePaddle)
63+
- [Pytorch](https://pytorch.org/)
64+
- [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR)
65+
- [PaddleOCR2Pytorch](https://github.com/frotms/PaddleOCR2Pytorch)

README_en.md

+123-186
Large diffs are not rendered by default.

demo/000000014439.jpg

191 KB
Loading

demo/000000014439_640x640.jpg

267 KB
Loading

demo/000000087038.jpg

179 KB
Loading

demo/000000570688.jpg

135 KB
Loading

demo/0000315_01601_d_0000509.jpg

191 KB
Loading

demo/39006.jpg

39.9 KB
Loading

demo/P0072__1.0__0___0.png

1.6 MB
Loading

demo/P0861__1.0__1154___824.png

1.2 MB
Loading

demo/car.jpg

2.18 MB
Loading

demo/hrnet_demo.jpg

42.1 KB
Loading

demo/orange_71.jpg

225 KB
Loading

demo/road554.png

189 KB
Loading

ppdettorch/utils/detection_infer_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def init_args():
107107
parser.add_argument(
108108
"--do_transform",
109109
type=bool,
110-
default=True,
110+
default=False,
111111
help="Whether to transform paddle model to pytorch .")
112112
parser.add_argument(
113113
"--predict_labels",

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ lap
1818
motmetrics
1919
sklearn
2020
filterpy
21+
paddlepaddle-gpu

tests/process/infer/run_detection_infer.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class DetectionRunInfer(object):
2525
def __init__(self):
2626
self.base_dir_image = f"{Constants.DATA_DIR}/ocr/imgs_words/ch"
2727
self.run_time = TimeUtils.now_str_short()
28-
self.base_dir = "/home/mqq/shenglei/ocr/PaddleDetection"
29-
self.detection_config_dir = f"/home/mqq/shenglei/ocr/PPDetectionPytorch"
28+
self.base_dir = Constants.WORK_DIR
29+
self.detection_config_dir = f"{Constants.WORK_DIR}/configs"
3030
self.checkpoint_base_url = "https://paddledet.bj.bcebos.com/models"
3131
self.checkpoint_base_url_ppstructure = "https://paddleocr.bj.bcebos.com/ppstructure/models/layout/"
3232
self.checkpoint_base_url_pedestrian = "https://bj.bcebos.com/v1/paddledet/models/keypoint/tinypose_enhance/"
@@ -89,7 +89,7 @@ def run_picodet_coco_model(self, config_file=None, do_transform=True):
8989
main_detection(run_arg)
9090

9191
def get_model_class(self, config_file):
92-
begin_index = len(f"{self.detection_config_dir}/configs/")
92+
begin_index = len(f"{self.detection_config_dir}/")
9393
config_name = config_file[begin_index:]
9494
end_index = config_name.find("/")
9595
model_class = config_name[:end_index]
@@ -173,7 +173,7 @@ def run_picodet_coco(self, config_name=None):
173173
config_name_end_index = FileUtils.get_file_name(config_name).find("_")
174174
model_class = config_name[:config_name_end_index]
175175

176-
config_file = f"{self.detection_config_dir}/configs/{model_class}/{config_name}.yml"
176+
config_file = f"{self.detection_config_dir}/{model_class}/{config_name}.yml"
177177

178178
self.run_picodet_coco_model(config_file=config_file)
179179

@@ -183,7 +183,7 @@ def run_picodet_coco_batch(self):
183183
picodet_l_320_coco_lcnet.yml
184184
:return:
185185
"""
186-
base_dir = f"{self.detection_config_dir}/configs/picodet"
186+
base_dir = f"{self.detection_config_dir}/picodet"
187187
file_name_list = FileUtils.list_dir_or_file(file_dir=base_dir,
188188
add_parent=True,
189189
sort=True,
@@ -219,7 +219,7 @@ def run_picodet_coco_batch():
219219
model_class = "yolox"
220220
model_class = "yolov3"
221221
model_class = "yolov5"
222-
model_class = "yolov6"
222+
# model_class = "yolov6"
223223
# model_class = "yolov7"
224224
# model_class = "rtmdet"
225225

0 commit comments

Comments
 (0)