PP-Vehicle-属性识别
windows11环境,conda虚拟环境中运行。
官网地址:PP-Vehicle
-
首先安装环境->
conda create -n paddle python=3.7
conda activate paddle
两种方式,一种是缺啥装即:pip install paddlepaddle-gpu
pip install pyyaml
pip install opencv-python
pip install scipy
pip install matplotlib
pip install scikit-learn
pip install pandas
pip install tqdm
pip install shapely
pip install requests
pip install lab
另外一种是:
pip install -r requirements.txt
-
下载PaddleDetection代码,网址为PaddleDetection
-
进入到文件夹内,准备测试的视频
cd C:\Users\10106\Desktop\PaddleDetection-release-2.6
,随便下载一个汽车的视频,放到了demo/test.mp4 -
下载模型,放到
pretrained/vehicle_attribute_model
下,predtrain是自己创建的。其他模型最好也都下载好,解压一下 -
编辑配置文件
deploy/pipeline/config/infer_cfg_ppvehicle.yml
中VEHICLE_ATTR是用于属性识别的,将其中的model_dir
替换为下载的模型。 -
修改配置文件中
deploy/pipeline/config/infer_cfg_ppvehicle.yml
的VEHICLE_ATTR项的enable: True,以启用该功能。 -
运行代码
python deploy/pipeline/pipeline.py --config deploy/pipeline/config/infer_cfg_ppvehicle.yml --video_file=demo/test.mp4 --device=gpu
,出现了个以下的问题。 -
测试单张图片
python deploy/pipeline/pipeline.py --config deploy/pipeline/config/infer_cfg_ppvehicle.yml --device=gpu --image_file=demo/car.jpg
-
测试文件夹中的图片
python deploy/pipeline/pipeline.py --config deploy/pipeline/config/infer_cfg_ppvehicle.yml --device=gpu --image_dir=demo
问题解决
- 第一次检测视频运行卡在了这里,单张图片可以。将paddle换成gpu版本后,提示Unable to use JDE/FairMOT/ByteTrace提示要安装lab。主要原因为环境安装时出现问题。最好使用
pip install -r requirements.txt
进行安装,要不然会缺包。
PP-Human-行人属性识别
1.使用与上面相同的环境
2.下载对应的模型
3.运行单张图片python deploy/pipeline/pipeline.py --config deploy/pipeline/config/examples/infer_cfg_human_attr.yml --device=gpu --image_file=demo/hrnet_demo.jpg
4. 属性介绍
- 性别:男、女
- 年龄:小于18、18-60、大于60
- 朝向:朝前、朝后、侧面
- 配饰:眼镜、帽子、无
- 正面持物:是、否
- 包:双肩包、单肩包、手提包
- 上衣风格:带条纹、带logo、带格子、拼接风格
- 下装风格:带条纹、带图案
- 短袖上衣:是、否
- 长袖上衣:是、否
- 长外套:是、否
- 长裤:是、否
- 短裤:是、否
- 短裙&裙子:是、否
- 穿靴:是、否
可在该路径下查看标签内容PaddleDetection-release-2.6\deploy\pipeline\pphuman\attr_infer.py
5.写了个函数把里面部分转化为中文,并且保存为txt
def save_txt(self,result,files):
# - Gender
# - Age: Less than 18; 18-60; Over 60
# - Orientation: Front; Back; Side
# - Accessories: Glasses; Hat; None
# - HoldObjectsInFront: Yes; No
# - Bag: BackPack; ShoulderBag; HandBag
# - TopStyle: UpperStride; UpperLogo; UpperPlaid; UpperSplice
# - BottomStyle: LowerStripe; LowerPattern
# - ShortSleeve: Yes; No
# - LongSleeve: Yes; No
# - LongCoat: Yes; No
# - Trousers: Yes; No
# - Shorts: Yes; No
# - Skirt&Dress: Yes; No
# - Boots: Yes; No
txt = []
attr_map = {'Male':'男','Female':'女',"Glasses: True":"眼镜","AgeLess18":"小于18岁","Age18-60":"18到60岁之间","AgeOver60":"大于60岁",
"Hat: True":"帽子","Backpack":"背包","ShoulderBag":"肩包","HandBag":"手提包","Upper: LongSleeve":"长袖上衣","Upper: ShortSleeve":"短袖上衣",
"LongCoat":"长外套","Trousers":"长裤","Shorts":"短裤","Skirt&Dress":"短裙","Boots":"靴子"}
human_attr_res = result.get('attr')
print(human_attr_res['output'])
for human_attr in human_attr_res['output']:
for i in range(len(human_attr)):
if human_attr[i] in attr_map.keys():
# human_attr[i] = attr_map[human_attr[i]]
txt.append(attr_map[human_attr[i]])
elif "Upper:" in human_attr[i] or "Lower:" in human_attr[i]:
temps = human_attr[i].split(" ")
for temp in temps:
if temp in attr_map.keys():
txt.append(attr_map[temp])
files[0] = files[0].replace("\\","/")
txt_name = (files[0].split("/")[-1].split(".")[-2] + '.txt') if "." in files[0] else (files[0] + '.txt')
with open(txt_name,"w") as file:
# 将字典转换为字符串,以空格隔开键和值
dict_str = ' '.join(set(txt))
file.write(dict_str)