目标检测 YOLOv5 CrowdHuman数据集格式转YOLOv5格式

本文指导如何将CrowdHuman的人体标注数据转换为YOLOv5所需的格式,重点在于处理0(head)到1(person)的标签,并仅保留person类别。使用Python脚本实现数据预处理,适用于608x608分辨率的训练。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目标检测 YOLOv5 CrowdHuman数据集格式转YOLOv5格式

flyfish

YOLOv5数据集转换工具下载地址

数据集官方网站: 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)
评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二分掌柜的

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值