visdrone数据集转化为MOT数据集(用作MOTR模型训练)

visdrone数据集转化为MOT数据集

MOT17 数据集格式

├── MOT17
│   ├── images
│   ├── labels_with_ids

train

det.txt

10个参数 或者 8个参数

<frame>, <id>, <bb_left>, <bb_top>, <bb_width>, <bb_height>, <conf>, <x>, <y>, <z> 
  • 第1个代表第几帧
  • 第2个代表轨迹编号(在这个文件里总是为-1)
  • bb开头的4个数代表物体框的左上角坐标及长宽
  • conf代表置信度
  • 最后3个是MOT3D用到的内容,2D检测总是为-1.

在这里插入图片描述

gt.txt

9个参数

  • 第1个代表第几帧
  • 第2个值为目标运动轨迹的ID号
  • 第3个到第6个数代表物体框的左上角坐标及长宽
  • 第7个值为目标轨迹是否进入考虑范围内的标志,0表示忽略,1表示active
  • 第8个值为该轨迹对应的目标种类(种类见下面的表格中的label-ID对应情况)
  • 第9个值为box的visibility ratio,表示目标运动时被其他目标box包含/覆盖或者目标之间box边缘裁剪情况。

在这里插入图片描述

seqinfo.ini

主要介绍视频的帧率、分辨率等基本信息。

在这里插入图片描述

test

det.txt

数据标签含义与train相同。

在这里插入图片描述

visdrone——Task 4_ Multi-Object Tracking

    <frame_index>,<target_id>,<bbox_left>,<bbox_top>,<bbox_width>,<bbox_height>,<score>,<object_category>,<truncation>,<occlusion>

 -----------------------------------------------------------------------------------------------------------------------------------
       Name	                                      Description
 -----------------------------------------------------------------------------------------------------------------------------------
   <frame_index>	  The frame index of the video frame
   
    <target_id>	          In the DETECTION result file, the identity of the target should be set to the constant -1.
		          In the GROUNDTRUTH file, the identity of the target is used to provide the temporal corresponding 
		          relation of the bounding boxes in different frames.
			  
    <bbox_left>	          The x coordinate of the top-left corner of the predicted bounding box

    <bbox_top>	          The y coordinate of the top-left corner of the predicted object bounding box

    <bbox_width>	  The width in pixels of the predicted object bounding box

    <bbox_height>	  The height in pixels of the predicted object bounding box

      <score>	          The score in the DETECTION file indicates the confidence of the predicted bounding box enclosing 
                          an object instance.
                          The score in GROUNDTRUTH file is set to 1 or 0. 1 indicates the bounding box is considered in evaluation, 
		          while 0 indicates the bounding box will be ignored.
			  
  <object_category>	  The object category indicates the type of annotated object, (i.e., ignored regions(0), pedestrian(1), 
                          people(2), bicycle(3), car(4), van(5), truck(6), tricycle(7), awning-tricycle(8), bus(9), motor(10), 
                          others(11))
		      
    <truncation>	  The score in the DETECTION file should be set to the constant -1.
                          The score in the GROUNDTRUTH file indicates the degree of object parts appears outside a frame 
		          (i.e., no truncation = 0 (truncation ratio 0%), and partial truncation = 1 (truncation ratio 1% ~ 50%)).
		      
     <occlusion>	  The score in the DETECTION file should be set to the constant -1.
                          The score in the GROUNDTRUTH file indicates the fraction of objects being occluded 
		          (i.e., no occlusion = 0 (occlusion ratio 0%), partial occlusion = 1 (occlusion ratio 1% ~ 50%), 
		          and heavy occlusion = 2 (occlusion ratio 50% ~ 100%)).
├── visdrone
│   ├── images
│   │   ├── train
│   │   │   ├── 视频目录
│   │   │   │   ├── gt
│   │   │   │   ├── img1
│   │   │   │   ├── seqinfo.ini
│   │   ├── test
│   ├── labels_with_ids
│   

配置seqinfo.ini文件

[Sequence]
name=MOT17-02-DPM
imDir=img1
frameRate=30
seqLength=600
imWidth=1920
imHeight=1080
imExt=.jpg

其中,imWidth、imHeight、imExt分别为图片的宽、高、格式;seqLength表示此视频被抽成了多少帧。frameRate为画面更新率。

代码如下

import os
import shutil
from tqdm import tqdm
from PIL import Image


def copyfile(old_folder_path,new_folder_path):
    print('---------------------')
    for file in os.listdir(old_folder_path):
        old_file_path=os.path.join(old_folder_path,file)
        # print(file)
        # print(new_folder_path)
        shutil.copy(old_file_path, new_folder_path)

def makedir(filepath):
    if not os.path.exists(filepath):
        os.mkdir(filepath)

def process(path):
    annotations_path = os.path.join(path, "annotations")
    ann_set = os.listdir(annotations_path)
    # print(ann_set)
    file_path=os.path.join(path,'sequences')
    file_set=os.listdir(file_path)
    # print(file_set)
    for i in tqdm(ann_set):
        f = open(annotations_path + "/" + i, "r")
        print(i)
        name = i.replace(".txt", "")
        print(name)
        img_path=os.path.join(file_path,name)
        img_set=os.listdir(img_path)
        img=Image.open(os.path.join(img_path,img_set[0]))
        for line in f.readlines():
            line = line.replace("\n", "")
            if line.endswith(","):  # filter data
                line = line.rstrip(",")
            line_list = [int(i) for i in line.split(",")]
            new_line_list=[line_list[i] for i in range(0,8)]
            print(line_list)
            # print(new_line_list)
            if(line_list[8]==0 and line_list[9]==0):
                new_line_list.append(1)
            if (line_list[8] == 0 and line_list[9] == 1):
                new_line_list.append(0.9)
            if (line_list[8] == 1 and line_list[9] == 0):
                new_line_list.append(0.8)
            if (line_list[8] == 0 and line_list[9] == 2):
                new_line_list.append(0.7)
            if (line_list[8] == 1 and line_list[9] == 1):
                new_line_list.append(0.5)
            if (line_list[8] == 1 and line_list[9] == 2):
                new_line_list.append(0.3)
            # print(new_line_list)
            url1 = os.path.join(path,name)
            makedir(url1)
            url2=os.path.join(name,'gt')
            makedir(url2)
            file_url=url2+'\\gt.txt'
            print(url2)
            print(file_url)
            if not os.path.isfile(file_url):
                fd = open(file_url, mode="w", encoding="utf-8")
            makedir(file_url)
            with open(file_url, 'a') as file_name:
                str_text = str(new_line_list[0]) + ',' + str(new_line_list[1]) + ',' + str(new_line_list[2]) + ',' + str(
                    new_line_list[3]) + ',' + str(new_line_list[4]) + ',' + str(new_line_list[5]) + ',' + str(
                    new_line_list[6]) + ',' + str(new_line_list[7])+ ',' + str(new_line_list[8])
                print(str_text)
                file_name.write(str_text + '\n')

        ini_path = os.path.join(path, name)
        ini_file=ini_path+'\\seqinfo.ini'
        print('***********************************')
        if not os.path.isfile(ini_file):
            fd = open(ini_file, mode="w", encoding="utf-8")
        with open(ini_file, 'a') as ini_name:
            ini_text ='[Sequence]\n'+'name='+name+'\n'+'imDir=img1\n'+'frameRate=30\n'+'seqLength='+str(len(img_set))+'\n'+'imWidth = '+str(img.size[0])+'\n'+'imHeight = '+str(img.size[1])+'\n'+'imExt =.jpg\n'
            print(ini_text)
            ini_name.write(ini_text + '\n')
        break
    old_path=os.path.join(file_path,name)
    new_path=os.path.join(path,name,'img1')
    print(old_path)
    print(new_path)
    move(old_path,new_path)

def move(old_path,new_path):
    makedir(new_path)
    copyfile(old_path,new_path)

if __name__ == '__main__':
    path1=r'D:\pythonProjects\Test\visdrone2mot\annotations'
    path2=r'D:\pythonProjects\Test\visdrone2mot\sequences'
    path=r'D:\pythonProjects\Test\visdrone2mot'
    process(path)

Linux

import os
import shutil
from tqdm import tqdm
from PIL import Image


def copyfile(old_folder_path,new_folder_path):
    print('---------------------')
    for file in os.listdir(old_folder_path):
        old_file_path=os.path.join(old_folder_path,file)
        # print(file)
        # print(new_folder_path)
        shutil.copy(old_file_path, new_folder_path)

def makedir(filepath):
    if not os.path.exists(filepath):
        os.mkdir(filepath)

def process(path):
    annotations_path = os.path.join(path, "annotations")
    ann_set = os.listdir(annotations_path)
    # print(ann_set)
    file_path=os.path.join(path,'sequences')
    file_set=os.listdir(file_path)
    # print(file_set)
    for i in tqdm(ann_set):
        f = open(annotations_path + "/" + i, "r")
        print(i)
        name = i.replace(".txt", "")
        print(name)
        img_path=os.path.join(file_path,name)
        img_set=os.listdir(img_path)
        img=Image.open(os.path.join(img_path,img_set[0]))
        old_path = os.path.join(file_path, name)
        new_path = os.path.join(path, name, 'img1')
        print(old_path)
        print(new_path)
        move(old_path, new_path)
        for line in f.readlines():
            line = line.replace("\n", "")
            if line.endswith(","):  # filter data
                line = line.rstrip(",")
            line_list = [int(i) for i in line.split(",")]
            new_line_list=[line_list[i] for i in range(0,8)]
            print(line_list)
            # print(new_line_list)
            if(line_list[8]==0 and line_list[9]==0):
                new_line_list.append(1)
            if (line_list[8] == 0 and line_list[9] == 1):
                new_line_list.append(0.9)
            if (line_list[8] == 1 and line_list[9] == 0):
                new_line_list.append(0.8)
            if (line_list[8] == 0 and line_list[9] == 2):
                new_line_list.append(0.7)
            if (line_list[8] == 1 and line_list[9] == 1):
                new_line_list.append(0.5)
            if (line_list[8] == 1 and line_list[9] == 2):
                new_line_list.append(0.3)
            # print(new_line_list)
            url1 = os.path.join(path,name)
            makedir(url1)
            print('url1:',url1)
            url2=os.path.join(url1,'gt')
            print('url2:',url2)
            makedir(url2)
            file_url=url2+'/gt.txt'
            print(url2)
            print(file_url)
            if not os.path.isfile(file_url):
                fd = open(file_url, mode="w", encoding="utf-8")
            makedir(file_url)
            with open(file_url, 'a') as file_name:
                str_text = str(new_line_list[0]) + ',' + str(new_line_list[1]) + ',' + str(new_line_list[2]) + ',' + str(
                    new_line_list[3]) + ',' + str(new_line_list[4]) + ',' + str(new_line_list[5]) + ',' + str(
                    new_line_list[6]) + ',' + str(new_line_list[7])+ ',' + str(new_line_list[8])
                print(str_text)
                file_name.write(str_text + '\n')

        ini_path = os.path.join(path, name)
        ini_file=ini_path+'/seqinfo.ini'
        print('***********************************')
        if not os.path.isfile(ini_file):
            fd = open(ini_file, mode="w", encoding="utf-8")
        with open(ini_file, 'a') as ini_name:
            ini_text ='[Sequence]\n'+'name='+name+'\n'+'imDir=img1\n'+'frameRate=30\n'+'seqLength='+str(len(img_set))+'\n'+'imWidth = '+str(img.size[0])+'\n'+'imHeight = '+str(img.size[1])+'\n'+'imExt =.jpg\n'
            print(ini_text)
            ini_name.write(ini_text + '\n')
        # break
      

def move(old_path,new_path):
    makedir(new_path)
    copyfile(old_path,new_path)

if __name__ == '__main__':
    path='/home/course/ldw/dataset/VisDrone2019-MOT-val/'
    process(path)
  • 3
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
对于MOT(多目标跟踪)任务,训练自己的数据集可以提高模型在特定场景下的性能和适应性。下面是一个简单的步骤来训练自己的MOT数据集: 1. 数据采集:收集与你感兴趣的场景相关的视频或图像序列,确保包含多个目标,并且目标在场景中移动。 2. 数据标注:使用标注工具(如LabelImg、VGG Image Annotator等)对数据集中的每个帧进行目标标注。通常,目标标注应包括边界框和目标类别信息,以便模型能够识别和跟踪不同类型的目标。 3. 数据预处理:根据你选择的深度学习框架和模型要求,对数据进行预处理。通常需要将图像调整为相同的大小,并且可能需要进行归一化等操作。 4. 构建训练集和验证集:将数据集划分为训练集和验证集。通常,将大部分数据用于训练,少部分用于验证和评估模型性能。 5. 模型选择和配置:选择适合MOT任务的深度学习模型,如YOLO、Faster R-CNN、DeepSORT等,并根据数据集的特点进行相应的配置。 6. 模型训练:使用选择的深度学习框架,将数据集输入模型,进行训练训练过程中,可以调整模型的超参数、学习率等以提高模型性能。 7. 模型评估和调优:使用验证集对训练好的模型进行评估和调优。可以根据评估结果对模型进行改进,如调整阈值、优化损失函数等。 8. 模型测试和应用:在真实场景中测试模型的性能,并根据需求对模型进行部署和应用。 需要注意的是,MOT任务相对复杂且资源密集,需要一定的计算资源和时间来完成训练过程。同时,数据集的质量和数量也会直接影响模型的性能和泛化能力。因此,在训练自己的MOT数据集时,需要谨慎处理数据和选择合适的模型来达到最佳的结果。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

莫余

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

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

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

打赏作者

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

抵扣说明:

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

余额充值