一、项目介绍:
二、环境安装
- 平台:windows 10
- 编译器:pycharm
- cuda 11.3
- cudnn 8.2.0.53
conda create -n yolov5bytetrack python=3.7
conda activate yolov5bytetrack
pip install prettytable -i https://mirror.baidu.com/pypi/simple
pip install ujson -i https://mirror.baidu.com/pypi/simple
pip install opencv-python==4.6.0.66 -i https://mirror.baidu.com/pypi/simple
pip install pillow -i https://mirror.baidu.com/pypi/simple
pip install tqdm -i https://mirror.baidu.com/pypi/simple
pip install PyYAML==5.1 -i https://mirror.baidu.com/pypi/simple
pip install visualdl==2.2.0 -i https://mirror.baidu.com/pypi/simple
pip install scipy==1.0.0 -i https://mirror.baidu.com/pypi/simple
pip install scikit-learn==0.21.0 -i https://mirror.baidu.com/pypi/simple
pip install gast==0.3.3 -i https://mirror.baidu.com/pypi/simple
pip install faiss-cpu -i https://mirror.baidu.com/pypi/simple
pip install easydict -i https://mirror.baidu.com/pypi/simple
pip install paddlepaddle-gpu==2.4.2.post117 -f https://www.paddlepaddle.org.cn/whl/windows/mkl/avx/stable.html
pip install psutil
pip install seaborn
pip install paddleclas -i https://mirror.baidu.com/pypi/simple
pip install loguru
pip install thop
conda install -c conda-forge lap
pip install mediapipe
三、执行代码
1、训练模型
下载数据集,文章百度云盘有提供
用的是PaddleCls
进行训练,下载PaddleClas
git clone https://github.com/PaddlePaddle/PaddleClas
将下载的数据集解压,放到PaddleClas
的dataset
目录。
找到ppcls/configs/PULC/person_attribute/PPLCNet_x1_0.yaml
配置文件,配置图片和label
路径。
DataLoader:
Train:
dataset:
name: MultiLabelDataset
image_root: "dataset/pa100k/" #指定训练图片所在根路径
cls_label_path: "dataset/pa100k/train_list.txt" #指定训练列表文件位置
label_ratio: True
transform_ops:
Eval:
dataset:
name: MultiLabelDataset
image_root: "dataset/pa100k/" #指定评估图片所在根路径
cls_label_path: "dataset/pa100k/val_list.txt" #指定评估列表文件位置
label_ratio: True
transform_ops:
检测数据集格式是否正确,train_list.txt
的格式为
00001.jpg 0,0,1,0,....
配置好后,就可以直接训练了
python tools/train.py -c ./ppcls/configs/PULC/person_attribute/PPLCNet_x1_0.yaml
![](http://43.138.69.59/wp-content/uploads/2023/04/微信截图_20230428154837-1024x198.png)
训练完后,导出模型
python3 tools/export_model.py -c ./ppcls/configs/PULC/person_attribute/PPLCNet_x1_0.yaml -o Global.pretrained_model=output/PPLCNet_x1_0/best_model -o Global.save_inference_dir=deploy/models/PPLCNet_x1_0_person_attribute_infer
将导出的结果放在deploy/models/PPLCNet_x1_0_person_attribute_infer
/目录下
![](http://43.138.69.59/wp-content/uploads/2023/04/2023-04-28_151221.png)
便可以使用PaddleCls
提供的函数直接调用模型,测试模型效果
import paddleclas
model = paddleclas.PaddleClas(model_name="person_attribute")
result = model.predict(input_data="./test_imgs/000001.jpg")
print(result)
python tools/infer.py
-c ./ppcls/configs/PULC/person_attribute/PPLCNet_x1_0.yaml
-o Infer.infer_imgs=../Butterfly20/001.Atrophaneura_horishanus/084.jpg
-o Global.pretrained_model=./output/PPLCNet_x1_0/latest
输出结果如下:
[{'attributes': ['Female', 'Age18-60', 'Front', 'Glasses: False', 'Hat: False', 'HoldObjectsInFront: True', 'ShoulderBag', 'Upper: ShortSleeve', 'Lower: Trousers', 'No boots'], 'output': [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0], 'filename': './test_imgs/000001.jpg'}]
2、运行yolov5
conda activate yolov5bytetrack
pip install lap
3、ByteTrack
![](http://43.138.69.59/wp-content/uploads/2023/04/2023-04-28_182848.png)
cython_bbox库就该这么安装
pip install -e git+https://github.com/samson-wang/cython_bbox.git#egg=cython-bbox