无人机行人检测数据集整理(转voc训练yolo)

Visdrone2019DET数据集介绍

配备摄像机的无人机或通用无人机已经快速部署到广泛的应用中,包括农业,航空摄影,快速交付和监视。因此,对从这些平台收集的视觉数据的自动理解的要求越来越高,这使计算机视觉越来越紧密地应用于无人机。我们很高兴为大规模的基准测试提供详细说明的真实性,以完成各种重要的计算机视觉任务,称为VisDrone,以使视觉满足无人机的要求。

下载地址

在这里插入图片描述

标签类型
在这里插入图片描述
注:两种有用的注释:truncation截断率,occlusion遮挡率。
被遮挡的对象比例来定义遮挡率。
截断率用于指示对象部分出现在框架外部的程度。
值得一提的是,如果目标的截断率大于50%,则会在评估过程中将其跳过。
在这里插入图片描述
txt2voc.py(只提取行人)

import os
from pathlib import Path
from PIL import Image
import csv

def convert(size, box):
    dw = 1. / size[0]
    dh = 1. / size[1]
    x = (box[0] + box[2] / 2) * dw
    y = (box[1] + box[3] / 2) * dh
    w = box[2] * dw
    h = box[3] * dh
    return (x, y, w, h)


wd = os.getcwd()

if not os.path.exists('labels'):
    os.makedirs('labels')

train_file = 'images.txt'
train_file_txt = ''

anns = os.listdir('annotations')
for ann in anns:
    person_number = 0
    ans = ''
    outpath = wd + '/labels/' + ann
    if ann[-3:] != 'txt':
        continue
    with Image.open(wd + '/JPEGImages/' + ann[:-3] + 'jpg') as Img:
        img_size = Img.size
    with open(wd + '/annotations/' + ann, newline='') as csvfile:
        spamreader = csv.reader(csvfile)
        for row in spamreader:
            if (int(row[5]) - 1)<2:
                person_number+=1
                if row[4] == '0':
                    continue
                bb = convert(img_size, tuple(map(int, row[:4])))
                #bb = convert(img_size, list(map(int,row[:4])))
                ans = ans + str(0) + ' ' + ' '.join(str(a) for a in bb) + '\n'
                with open(outpath, 'w') as outfile:
                    outfile.write(ans)
    if person_number>0:
        train_file_txt = train_file_txt + wd + '/JPEGImages/' + ann[:-3] + 'jpg\n'

with open(train_file, 'w') as outfile:
    outfile.write(train_file_txt)

Visdrone2019MOT数据集介绍

在这里插入图片描述
标签类型
在这里插入图片描述

在这里插入图片描述
mot2voc.py(只提取行人)

import os
import shutil
from PIL import Image
import csv
import progressbar

def save_voc(image_voc,save_voc_path):
    save_voc_path = './labels/'+save_voc_path+'.txt'
    with open(save_voc_path, 'w') as outfile:
        outfile.write(image_voc)
    return

def convert(size, box):
    dw = 1. / size[0]
    dh = 1. / size[1]
    x = (box[0] + box[2] / 2) * dw
    y = (box[1] + box[3] / 2) * dh
    w = box[2] * dw
    h = box[3] * dh
    return (x, y, w, h)

def main():
    if not os.path.exists('./labels'):
        os.makedirs("./labels")
    if not os.path.exists('./JPEGImages'):
        os.makedirs("./JPEGImages")
    image_dir_list = os.listdir('./sequences')
    dir_number = 0
    for image_dir in image_dir_list:
        count = 0
        txt_name = './annotations/'+image_dir+'.txt'
        image_list = os.listdir('./sequences/'+image_dir)
        bar = progressbar.ProgressBar(maxval=len(image_list)).start()
        with Image.open('./sequences/' + image_dir + '/' + image_list[1]) as Img:
            img_size = Img.size
        for image in image_list:
            count += 1
            bar.update(count)
            voc_contain = ''
            image_voc = []
            image_number = int(image[:-4])
            txt_list = csv.reader(open(txt_name))
            for line in txt_list:
                fram_id = int(line[0])
                if fram_id == image_number:
                    visible = float(line[-1])
                    label_class = line[-3]
                    if (label_class == '1' or label_class == '2') and visible < 2:
                        box = convert(img_size,tuple(map(int,line[2:6])))
                        voc_contain = voc_contain+str(0) + ' ' + ' '.join(str(a) for a in box) + '\n'
            if voc_contain != None:
                save_voc(voc_contain,str(dir_number)+str(dir_number)+image[:-4])
                shutil.copy('./sequences/' + image_dir + '/'+image, './JPEGImages' + '/' + str(dir_number)+str(dir_number)+image[:-4]+'.jpg')  # 将文件移动到指定文件夹并重新命名
        bar.finish()
        dir_number+=1
    train_txt = './train.txt'
    image_train_list = os.listdir('./JPEGImages')
    pwd = os.getcwd()
    path = ''
    for i in image_train_list:
        path =  path+pwd +'/'+i+'\n'
    out = open(train_txt, 'w')
    out.write(path)

if __name__ == '__main__':
    main()

MOT20-Det数据集

mot转voc.py
使用 python3 name.py 20
脚本出处

import cv2
import os
import numpy as np
import time
import argparse
import shutil
import codecs
import progressbar

train_17 = ['MOT17-Det/train/MOT17-02/',
                'MOT17-Det/train/MOT17-04/',
                'MOT17-Det/train/MOT17-05/',
                'MOT17-Det/train/MOT17-09/',
                'MOT17-Det/train/MOT17-10/',
                'MOT17-Det/train/MOT17-11/',
                'MOT17-Det/train/MOT17-13/']

test_17 = ['MOT17-Det/test/MOT17-01/',
               'MOT17-Det/test/MOT17-03/',
               'MOT17-Det/test/MOT17-06/',
               'MOT17-Det/test/MOT17-07/',
               'MOT17-Det/test/MOT17-08/',
               'MOT17-Det/test/MOT17-12/',
               'MOT17-Det/test/MOT17-14/']

train_20 = ['MOT20Det/train/MOT20-01/',
                'MOT20Det/train/MOT20-02/']
               # 'MOT20Det/train/MOT20-03/',
              #  'MOT20Det/train/MOT20-05/'

test_20 = []

# test_20 = ['MOT20Det/test/MOT20-04/','MOT20Det/test/MOT20-06/','MOT20Det/test/MOT20-07/','MOT20Det/test/MOT20-08/']


def parse_args():
    parser = argparse.ArgumentParser(description='Convert MOT2VOC format')
    parser.add_argument(
        'year',
        choices=['17', '20'],
        default='none',
        help='year of MOT dataset')
    args = parser.parse_args()
    return args

def parse_ini(dir):
    ini_fp = open(dir + 'seqinfo.ini','r')
    seq_info = ini_fp.readlines()
    seqLenth = int(seq_info[4][10:])
    imWidth = int(seq_info[5][8:])
    imHeight = int(seq_info[6][9:])
    return seqLenth,imWidth,imHeight

def gennerate_gt(gt,Annotation,frame,filename,width,height):
    fp_gt = open(gt)
    gt_lines = fp_gt.readlines()

    gt_fram = []
    for line in gt_lines:
        fram_id = int(line.split(',')[0])
        if fram_id == frame:
            visible = float(line.split(',')[8])
            label_class = line.split(',')[7]
            if (label_class == '1' or label_class == '2' or label_class == '7') and visible > 0.3:
                gt_fram.append(line)


    with codecs.open(Annotation + filename + '.xml', 'w') as xml:
        xml.write('<?xml version="1.0" encoding="UTF-8"?>\n')
        xml.write('<annotation>\n')
        xml.write('\t<folder>' + 'voc' + '</folder>\n')
        xml.write('\t<filename>' + filename + '.jpg' + '</filename>\n')
        # xml.write('\t<path>' + path + "/" + info1 + '</path>\n')
        xml.write('\t<source>\n')
        xml.write('\t\t<database> The MOT-Det </database>\n')
        xml.write('\t</source>\n')
        xml.write('\t<size>\n')
        xml.write('\t\t<width>' + str(width) + '</width>\n')
        xml.write('\t\t<height>' + str(height) + '</height>\n')
        xml.write('\t\t<depth>' + '3' + '</depth>\n')
        xml.write('\t</size>\n')
        xml.write('\t\t<segmented>0</segmented>\n')
        for bbox in gt_fram:
            x1 = int(bbox.split(',')[2])
            y1 = int(bbox.split(',')[3])
            x2 = int(bbox.split(',')[4])
            y2 = int(bbox.split(',')[5])

            xml.write('\t<object>\n')
            xml.write('\t\t<name>person</name>\n')
            xml.write('\t\t<pose>Unspecified</pose>\n')
            xml.write('\t\t<truncated>0</truncated>\n')
            xml.write('\t\t<difficult>0</difficult>\n')
            xml.write('\t\t<bndbox>\n')
            xml.write('\t\t\t<xmin>' + str(x1) + '</xmin>\n')
            xml.write('\t\t\t<ymin>' + str(y1) + '</ymin>\n')
            xml.write('\t\t\t<xmax>' + str(x1 + x2) + '</xmax>\n')
            xml.write('\t\t\t<ymax>' + str(y1 + y2) + '</ymax>\n')
            xml.write('\t\t</bndbox>\n')
            xml.write('\t</object>\n')
        xml.write('</annotation>')

#用于校验图片数量和标注数量是否一致
def check_num(data_dir, JPEGImage_dir,Annotations_dir=None,ori_num = 0):
    num = 0
    for folder in data_dir:
        folder_len,_,_ = parse_ini(folder)
        num += folder_len
    img_list = os.listdir(JPEGImage_dir)
    if ori_num==0:
        img_num = len(img_list)
    else:
        img_num = len(img_list)-ori_num
    # print('img_num:',img_num)
    if Annotations_dir:
        ann_list = os.listdir(Annotations_dir)
        ann_num = len(ann_list)
        assert ann_num == num
    assert img_num == num,'if it is the second time run this demo, please delete the JPEGImages folder and retry'
    # print('num:', num)
    print('folders {} have been succeed checked'.format(data_dir))
    return num

def segment_dataset(ImageSets,Main,thr1 = 0.8,thr2 = 0.9):
    fp_all = open(ImageSets + 'train_all.txt', 'r')
    fp_train = open(Main + 'train.txt', 'w')
    fp_test = open(Main + 'test.txt', 'w')
    fp_val = open(Main + 'val.txt', 'w')
    train_list = fp_all.readlines()
    print(len(train_list))


    for line in train_list:
        rand_a = np.random.rand(1)
        if rand_a <= thr1:
            fp_train.writelines(line)
        if rand_a > thr1 and rand_a <= thr2:
            fp_val.writelines(line)
        if rand_a > thr2 and rand_a <= 1:
            fp_test.writelines(line)
    fp_train.close()
    fp_val.close()
    fp_test.close()

    print('segment the MOT dataset into train,val,test subsets')


def main():

    train_dirs = train_20
    test_dirs = test_20
    motyear = 20

    folder = 'data/'+'MOT' + str(motyear) + 'Det'+'/VOC2007/'
    Annotations = folder+'Annotations/'
    ImageSets = folder + 'ImageSets/'
    JPEGImages = folder + 'JPEGImages/'
    Main = ImageSets + 'Main/'
    if not os.path.exists(Annotations):
        os.makedirs(Annotations)
    if not os.path.exists(ImageSets):
        os.makedirs(ImageSets)
    if not os.path.exists(JPEGImages):
        os.makedirs(JPEGImages)
    if not os.path.exists(Main):
        os.makedirs(Main)


    fp_txt = open(ImageSets + 'train_all.txt', 'w')
    fp_test = open(ImageSets + 'test_all.txt', 'w')

    for train_ in train_dirs:
        seqLenth, imWidth, imHeight = parse_ini(train_)
        img1 = train_ + 'img1/'
        gt = train_ + 'gt/gt.txt'
        folder_id = train_[-3:-1]
        img_list = os.listdir(img1)

        count = 0
        assert len(img_list) == seqLenth
        bar = progressbar.ProgressBar(maxval=len(img_list)).start()
        for img in img_list:
            count += 1
            bar.update(count)
            format_name = folder_id + img
            fp_txt.writelines(format_name[:-4] + '\n')  # 将生成的新的文件名写入train_all.txt,用于后续数据集拆分
            shutil.copy(img1 + img, JPEGImages + '/' + format_name)  # 将文件移动到指定文件夹并重新命名
            frame = int(img[:-4])
            gennerate_gt(gt, Annotation=Annotations, frame=frame, filename=format_name[:-4], width=imWidth,
                      height=imHeight)   #生成标注文件
        bar.finish()
    fp_txt.close()
    
    train_num = check_num(train_dirs,JPEGImages,Annotations)

    for test_ in test_dirs:
        img2 = test_ + 'img1/'
        folder_id = test_[-3:-1]
        test_list = os.listdir(img2)
        test_seqLen,_,_ = parse_ini(test_)

        assert test_seqLen==len(test_list)

        bar = progressbar.ProgressBar(maxval=len(test_list)).start()
        count = 0

        for img in test_list:
            count += 1
            bar.update(count)
            format_name = folder_id + img
            fp_test.writelines(format_name[:-4] + '\n')  # 将生成的新的文件名写入train_all.txt,用于后续数据集拆分
            shutil.copy(img2 + img, JPEGImages + '/' + format_name)  # 将文件移动到指定文件夹并重新命名
        bar.finish()

    fp_test.close()

    check_num(test_dirs, JPEGImages, Annotations_dir=None,ori_num=train_num)    # 校验核对处理后的数据集的数据是否正确

    segment_dataset(ImageSets,Main)


if __name__ == '__main__':
    main()

再转一次voc.py

import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join

sets=[('2007', 'train'), ('2007', 'val'), ('2007', 'test')]

classes = ["person"]


def convert(size, box):
    dw = 1./(size[0])
    dh = 1./(size[1])
    x = (box[0] + box[1])/2.0 - 1
    y = (box[2] + box[3])/2.0 - 1
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x*dw
    w = w*dw
    y = y*dh
    h = h*dh
    return (x,y,w,h)

def convert_annotation(year, image_id):
    in_file = open('VOCdevkit/VOC%s/Annotations/%s.xml'%(year, image_id))
    out_file = open('VOCdevkit/VOC%s/labels/%s.txt'%(year, image_id), 'w')
    tree=ET.parse(in_file)
    root = tree.getroot()
    size = root.find('size')
    w = int(size.find('width').text)
    h = int(size.find('height').text)

    for obj in root.iter('object'):
        difficult = obj.find('difficult').text
        cls = obj.find('name').text
        if cls not in classes or int(difficult)==1:
            continue
        cls_id = classes.index(cls)
        xmlbox = obj.find('bndbox')
        b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))
        bb = convert((w,h), b)
        out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')

wd = getcwd()

for year, image_set in sets:
    if not os.path.exists('VOCdevkit/VOC%s/labels/'%(year)):
        os.makedirs('VOCdevkit/VOC%s/labels/'%(year))
    image_ids = open('VOCdevkit/VOC%s/ImageSets/Main/%s.txt'%(year, image_set)).read().strip().split()
    list_file = open('%s_%s.txt'%(year, image_set), 'w')
    for image_id in image_ids:
        list_file.write('%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg\n'%(wd, year, image_id))
        convert_annotation(year, image_id)
    list_file.close()

os.system("cat 2007_train.txt 2007_val.txt > train.txt")
os.system("cat 2007_test.txt> test.txt")


  • 3
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
行人检测数据集 YOLO 是一种用于行人检测的图像数据集。它是基于 YOLO (You Only Look Once) 算法构建的,用于训练和评估计算机视觉模型以检测图像中的行人。 YOLO 是一种实时目标检测算法,它将图像划分为网格,并在每个网格中预测对象边界框和类别概率。因此,YOLO 可以在单个前向传递中检测和定位图像中的多个对象,包括行人。 行人检测数据集 YOLO 包含了大量带有标注的图像,这些图像中标注了行人的位置和边界框。这些标注信息是由人工标注员进行手动标注的,确保了数据集的准确性和可靠性。 使用行人检测数据集 YOLO,我们可以训练计算机视觉模型来自动检测图像中的行人。通过将这些图像输入到模型中进行训练,模型将学习到行人的特征和位置,并能够在新的未见图像中准确地检测和定位行人。 行人检测数据集 YOLO 对于行人检测算法的研究和开发非常有价值。准确的行人检测在许多应用中都非常重要,比如自动驾驶、视频监控和智能交通系统等。通过使用行人检测数据集 YOLO,我们可以改进和优化行人检测算法,提高其在实际场景中的性能和鲁棒性。 总之,行人检测数据集 YOLO 是一种用于训练和评估行人检测算法的图像数据集,可以帮助我们研究和开发准确、高效的行人检测算法,以应用于各种计算机视觉应用中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值