目标检测 YOLOv5 CrowdHuman数据集格式转YOLOv5格式
flyfish
数据集官方网站: https://www.crowdhuman.org/
参考:
CrowdHuman: A Benchmark for Detecting Human in a Crowd
标注结果是 0 是 “head”, 1是 “person”.
CrowdHuman2YOLO项目结构如下
data
├── crowdhuman.names
├── crowdhuman-template.data
├── gen_txts.py
├── prepare_data.sh
├── raw
└── verify_txts.py
下载的文件包括
CrowdHuman_train01.zip
CrowdHuman_train02.zip
CrowdHuman_train03.zip
CrowdHuman_val.zip
annotation_train.odgt
annotation_val.odgt
全部放到上述的data/raw文件夹中
执行命令
./prepare_data.sh 608x608
结果
(pytorch1.7) /pytorch1.7/yolov4_crowdhuman/data$ ./prepare_data.sh 608x608
** Install requirements
** Download dataset files
** Unzip dataset files
Archive: CrowdHuman_train01.zip
inflating: Images/273271,1017c000ac1360b7.jpg
inflating: Images/273271,10355000e3a458a6.jpg
inflating: Images/273271,1039400091556057.jpg
......
Processing ID: 273275,10b78d0006d7d7b9c
Processing ID: 284193,2e02d0003abd1bb1
** for yolov5-608x608, resized bbox width/height clusters are: (11.77, 22.62) (24.71, 61.38) (37.78, 117.48) (54.99, 187.92) (70.04, 270.74) (90.15, 371.35) (126.91, 492.11) (195.65, 316.45) (279.13, 521.00)
按照文中所说的图像文件和标注文本文件所在路径放置。
只留一个类别
下面的代码示例留一个人体类别
因为0 表示head,1表示person,所以还需要更改下标签,只有一类,类别就是0
import pandas as pd
import os
path_source = "/crowdhuman/labels/train2017/"
path_target = "/crowdhuman/labels/only_person/"
def convert_crowd_human(path,filename):
if os.path.getsize(path):
df = pd.read_csv(path, sep='\s+', header=None) # delim_whiteshape=True)
print(df.shape[0])
#取出所有第0列为1的数据
d_1 = df[df[0] == 1]
#第一列更改为0
d_1.iloc[:,0]=0
#print(d_1) 保留6位小数
tmp=path_target+filename
d_1.to_csv(tmp, sep=' ',float_format='%.6f', index=False,header=None)
filenames=os.listdir(path_source)
for i in filenames:
current_path = path_source+i
print(current_path)
convert_crowd_human(current_path,i)