AI-PaddleDetection
PaddleDetection是一个基于PaddlePaddle的目标检测端到端开发套件。
PP-Human 实时行人分析工具
安装使用步骤
在PyCharm欢迎页通过Get from VCS拉取github上PaddlePaddle/PaddleSeg项目。
拉取成功后,PyCharm会提示创建venv虚拟环境,点击确定即可,在PyCharm打开终端命令行前面有venv代表创建成功,如果没有,关闭终端点击
Add new Interpreter
(需要python3.10的环境),添加后,重新在PyCharm打开终端1
2例如:
(venv) ➜ PaddleSeg git:(release/2.9)安装paddle,在PyCharm中Terminal命令行中执行
pip install paddlepaddle
安装setuptools,在PyCharm中Terminal命令行中执行
pip install -U pip setuptools
安装依赖,在PyCharm中Terminal命令行中执行
pip install -r requirements.txt
使用步骤
1 | # 运行图片检测人,结果输出在output目录 |
检查人并输出视频
安装ffmpeg:
brew install ffmpeg
下载安装rtsp推流服务bluenviron/mediamtx,在release页面选择适合的版本,我的是inter的mac,选择mediamtx_v1.8.1_darwin_amd64.tar.gz即可
解压,然后运行
./mediamtx
运行视频流检测并推流
python deploy/pipeline/pipeline.py --config deploy/pipeline/config/examples/infer_cfg_human_attr.yml --rtsp rtsp://admin:123456@172.1.1.1:554/ch01.264?dev=1 --pushurl rtsp://127.0.0.1:8554
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69python deploy/pipeline/pipeline.py --config deploy/pipeline/config/examples/infer_cfg_human_attr.yml --rtsp rtsp://admin:123456@172.16.80.59:554/ch01.264?dev=1 --pushurl rtsp://127.0.0.1:8554
----------- Running Arguments -----------
ATTR:
batch_size: 8
enable: true
model_dir: https://bj.bcebos.com/v1/paddledet/models/pipeline/PPLCNet_x1_0_person_attribute_945_infer.zip
DET:
batch_size: 1
model_dir: https://bj.bcebos.com/v1/paddledet/models/pipeline/pphuman/ppyoloe_plus_crn_t_auxhead_320_60e_pphuman.tar.gz
MOT:
batch_size: 1
enable: true
model_dir: https://bj.bcebos.com/v1/paddledet/models/pipeline/pphuman/ppyoloe_plus_crn_t_auxhead_320_60e_pphuman.tar.gz
tracker_config: deploy/pipeline/config/tracker_config.yml
attr_thresh: 0.5
crop_thresh: 0.5
visual: true
warmup_frame: 50
------------------------------------------
Multi-Object Tracking enabled
Human Attribute Recognition enabled
100%|██████████| 15897/15897 [00:05<00:00, 2768.11KB/s]
DET model dir: /.cache/paddle/infer_weights/ppyoloe_plus_crn_t_auxhead_320_60e_pphuman
MOT model dir: /.cache/paddle/infer_weights/ppyoloe_plus_crn_t_auxhead_320_60e_pphuman
ATTR model dir: /.cache/paddle/infer_weights/PPLCNet_x1_0_person_attribute_945_infer
----------- Model Configuration -----------
Model Arch: StrongBaseline
Transform Order:
--transform op: Resize
--transform op: NormalizeImage
--transform op: Permute
--------------------------------------------
----------- Model Configuration -----------
Model Arch: PPYOLOE
Transform Order:
--transform op: Resize
--transform op: Permute
--------------------------------------------
video fps: 25, frame_count: -2562047788015215
the result will push stream to url:rtsp://127.0.0.1:8554/ch01
ffmpeg version 7.0 Copyright (c) 2000-2024 the FFmpeg developers
built with Apple clang version 15.0.0 (clang-1500.1.0.2.5)
configuration: --prefix=/usr/local/Cellar/ffmpeg/7.0_1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopenvino --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox
libavutil 59. 8.100 / 59. 8.100
libavcodec 61. 3.100 / 61. 3.100
libavformat 61. 1.100 / 61. 1.100
libavdevice 61. 1.100 / 61. 1.100
libavfilter 10. 1.100 / 10. 1.100
libswscale 8. 1.100 / 8. 1.100
libswresample 5. 1.100 / 5. 1.100
libpostproc 58. 1.100 / 58. 1.100
Thread: 0; frame id: 0
Thread: 0; trackid number: 2
Input #0, rawvideo, from 'fd:':
Duration: N/A, start: 0.000000, bitrate: 552960 kb/s
Stream #0:0: Video: rawvideo (BGR[24] / 0x18524742), bgr24, 1280x720, 552960 kb/s, 25 tbr, 25 tbn
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg4 (native))
Output #0, rtsp, to 'rtsp://127.0.0.1:8554/ch01':
Metadata:
encoder : Lavf61.1.100
Stream #0:0: Video: mpeg4, yuv420p(progressive), 1280x720, q=2-31, 200 kb/s, 25 fps, 90k tbn
Metadata:
encoder : Lavc61.3.100 mpeg4
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
Thread: 0; frame id: 10
Thread: 0; trackid number: 2然后使用vlc播放
rtsp://127.0.0.1:8554/ch01
流即可,流的地址在上一步日志里面可以看到the result will push stream to url:rtsp://127.0.0.1:8554/ch01
默认的模型,识别速度个人电脑会卡顿,可以替换为小模型,模型地址可以在PP-Human快速开始-模型下载里面进行找
1
2
3
4
5修改该deploy/pipeline/config/examples/infer_cfg_human_attr.yml文件
替换
model_dir: https://bj.bcebos.com/v1/paddledet/models/pipeline/mot_ppyoloe_l_36e_pipeline.zip
为
model_dir: https://bj.bcebos.com/v1/paddledet/models/pipeline/pphuman/ppyoloe_plus_crn_t_auxhead_320_60e_pphuman.tar.gz
常见错误
安装依赖,执行
pip install -r requirements.txt
时报AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
错误,详细信息如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54(.venv) ➜ PaddleDetection git:(release/2.7) pip install -r requirements.txt
Collecting numpy<1.24 (from -r requirements.txt (line 1))
Using cached numpy-1.23.5.tar.gz (10.7 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [33 lines of output]
Traceback (most recent call last):
File "workspace/PaddleDetection/.venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
main()
File "workspace/PaddleDetection/.venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "workspace/PaddleDetection/.venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 112, in get_requires_for_build_wheel
backend = _build_backend()
^^^^^^^^^^^^^^^^
File "workspace/PaddleDetection/.venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 77, in _build_backend
obj = import_module(mod_path)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/private/var/folders/jd/0572r10n2rbcwn4tf1w6sy500000gn/T/pip-build-env-r6d8n8j4/overlay/lib/python3.12/site-packages/setuptools/__init__.py", line 16, in <module>
import setuptools.version
File "/private/var/folders/jd/0572r10n2rbcwn4tf1w6sy500000gn/T/pip-build-env-r6d8n8j4/overlay/lib/python3.12/site-packages/setuptools/version.py", line 1, in <module>
import pkg_resources
File "/private/var/folders/jd/0572r10n2rbcwn4tf1w6sy500000gn/T/pip-build-env-r6d8n8j4/overlay/lib/python3.12/site-packages/pkg_resources/__init__.py", line 2172, in <module>
register_finder(pkgutil.ImpImporter, find_on_path)
^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.原因:在
docs/tutorials/INSTALL_cn.md
文档里面可以查看到只支持Python 3(3.5.1+/3.6/3.7/3.8/3.9/3.10),64位版本。解决:执行
brew install python@3.10
,然后在上面安装的第二个步骤里面,切换成3.10的python环境出现提示安装
pip install numba==0.56.4
的警告,安装即可运行视频流检测人时,报错
1
2
3
4
5
6
7
8
9
10
11
12
13python deploy/pipeline/pipeline.py --config deploy/pipeline/config/examples/infer_cfg_human_attr.yml -o visual=False --rtsp rtsp://admin:123456@172.16.1.1:554/ch01.264?dev=1
Traceback (most recent call last):
File "workspace/PaddleDetection/deploy/pipeline/pipeline.py", line 1321, in <module>
main()
File "workspace/PaddleDetection/deploy/pipeline/pipeline.py", line 1303, in main
cfg = merge_cfg(FLAGS) # use command params to update config
File "workspace/PaddleDetection/deploy/pipeline/cfg_utils.py", line 212, in merge_cfg
pred_config = merge_opt(pred_config, args_dict)
File "workspace/PaddleDetection/deploy/pipeline/cfg_utils.py", line 202, in merge_opt
for sub_k, sub_v in value.items():
AttributeError: 'bool' object has no attribute 'items'
Process finished with exit code 1解决:删除命令里面的
-o visual=False
,似乎是该参数有问题运行视频流检测加推流的时候,报错
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60python deploy/pipeline/pipeline.py --config deploy/pipeline/config/examples/infer_cfg_human_attr.yml --rtsp rtsp://admin:iexxk123456@172.16.80.229:554/ch01.264?dev=1 --pushurl rtsp://127.0.0.1:8554
----------- Running Arguments -----------
ATTR:
batch_size: 8
enable: true
model_dir: https://bj.bcebos.com/v1/paddledet/models/pipeline/PPLCNet_x1_0_person_attribute_945_infer.zip
DET:
batch_size: 1
model_dir: https://bj.bcebos.com/v1/paddledet/models/pipeline/mot_ppyoloe_l_36e_pipeline.zip
MOT:
batch_size: 1
enable: true
model_dir: https://bj.bcebos.com/v1/paddledet/models/pipeline/mot_ppyoloe_l_36e_pipeline.zip
tracker_config: deploy/pipeline/config/tracker_config.yml
attr_thresh: 0.5
crop_thresh: 0.5
visual: true
warmup_frame: 50
------------------------------------------
Multi-Object Tracking enabled
Human Attribute Recognition enabled
DET model dir: .cache/paddle/infer_weights/mot_ppyoloe_l_36e_pipeline
MOT model dir: .cache/paddle/infer_weights/mot_ppyoloe_l_36e_pipeline
ATTR model dir: .cache/paddle/infer_weights/PPLCNet_x1_0_person_attribute_945_infer
----------- Model Configuration -----------
Model Arch: StrongBaseline
Transform Order:
--transform op: Resize
--transform op: NormalizeImage
--transform op: Permute
--------------------------------------------
----------- Model Configuration -----------
Model Arch: YOLO
Transform Order:
--transform op: Resize
--transform op: Permute
--------------------------------------------
video fps: 25, frame_count: -2562047788015215
the result will push stream to url:rtsp://127.0.0.1:8554/ch01
Traceback (most recent call last):
File "workspace/PaddleDetection/deploy/pipeline/pipeline.py", line 1321, in <module>
main()
File "workspace/PaddleDetection/deploy/pipeline/pipeline.py", line 1308, in main
pipeline.run_multithreads()
File "workspace/PaddleDetection/deploy/pipeline/pipeline.py", line 179, in run_multithreads
self.predictor.run(self.input)
File "workspace/PaddleDetection/deploy/pipeline/pipeline.py", line 533, in run
self.predict_video(input, thread_idx=thread_idx)
File "workspace/PaddleDetection/deploy/pipeline/pipeline.py", line 670, in predict_video
pushstream.initcmd(fps, width, height)
File "workspace/PaddleDetection/deploy/pipeline/pipe_utils.py", line 142, in initcmd
self.pipe = sp.Popen(self.command, stdin=sp.PIPE)
File "/usr/local/Cellar/python@3.10/3.10.14/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 971, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/Cellar/python@3.10/3.10.14/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 1863, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg'
Process finished with exit code 1解决:安装ffmpeg,执行
brew install ffmpeg