FairMOT训练kittitracking数据集的汽车类(参考FairVehicle)

更新时间:2023-07-14 02:46:16 阅读: 评论:0

FairMOT训练kittitracking数据集的汽车类(参考FairVehicle)
⼯作情况:
kitti数据集的标签(转换成FairMOT类似的gt)
以下是处理图⽚和gt⽂本的程序操作,仅做个⼈记录
1.将原先kitti tracking数据集的标签修改去掉type⽤⽂本来表⽰改成数字代表同时将空格改成逗号
效果图
kitti tracking 标签含义:
The label files contain the following information, which can be read and written using the matlab tools (readLabels.m) provided within this devkit. All values (numerical or strings) are parated via spaces, each row corresponds to one object. The 17 columns reprent:
#Values    Name      Description
----------------------------------------------------------------------------
1    frame        Frame within the quence where the object appearers 1    track id    Unique tracking id of this object within this quence
1    type        Describes the type of object:'Car','Van','Truck',
'Pedestrian','Person_sitting','Cyclist','Tram',
'Misc'or'DontCare'
1    truncated    Integer (0,1,2) indicating the level of truncation.
Note that this is in contrast to the object detection
benchmark where truncation is a float in [0,1].
1    occluded    Integer (0,1,2,3) indicating occlusion state:
0= fully visible,1= partly occluded
形容生气的句子
2= largely occluded,3= unknown
1    alpha        Obrvation angle of object, ranging [-pi..pi]
4    bbox        2D bounding box of object in the image (0-bad index):                    contains left, top, right, bottom pixel coordinates
3    dimensions  3D object dimensions: height, width, length (in meters) 3    location    3D object location x,y,z in camera coordinates (in meters) 1    rotation_y  Rotation ry around Y-axis in camera coordinates [-pi..pi] 1    score        Only for results: Float, indicating confidence in
detection, needed for p/r curves, higher is better.
附 转换代码:
import os
import numpy as np
import pandas as pd
import os.path as osp
def replace(file, old_content, new_content):
content =read_file(file)
content = place(old_content, new_content)
rewrite_file(file, content)
# 读⽂件内容
def read_file(file):
with open(file, encoding='UTF-8') as f:
read_all = f.read()
f.clo()
return read_all
# 写内容到⽂件
def rewrite_file(file, data):
with open(file,'w', encoding='UTF-8') as f:
f.write(data)
f.clo()
src_data='/media/ckq/data/kitti/MOT/images/train'
qs =[s for s in os.listdir(src_data)]
赚钱的方法
#print(qs)
for q in qs:有意义的图片
path=osp.join(src_data,q,'')
# q_gt_path = osp.join(src_data, q, '')
# print(q_gt_path)
# gt = np.loadtxt(q_gt_path, dtype=np.str, delimiter=',')  # 加载成np格式
# print(str(gt))
replace(path,' ',',')
replace(path,'DontCare','10')
replace(path,'Person','1')
replace(path,'Pedestrian','2')
replace(path,'Car','3')
爱给replace(path,'Person_sitting','4')
replace(path,'Cyclist','5')
replace(path,'Van','6')
replace(path,'Truck','7')
replace(path,'Tram','8')
replace(path,'Misc','9')
2.之后开始给每个数据及的每张图⽚进⾏标签:⾸先说⼀下我的需求是标注Car: kitti数据集标签⽣成 gen_lables_kitti_car.py:
附代码(对照FairMOT 和`FairVehicle的⽣成标签代码写):
import os.path as osp
import os
import shutil
import numpy as np
def mkdirs(d):
# if ists(d):
if not osp.isdir(d):
os.makedirs(d)
data_root ='/media/ckq/data/kitti/'
q_root = data_root +'MOT/images/train'
label_root = data_root +'MOT/labels_with_ids/train'
打女生屁屁作文label_root = data_root +'MOT/labels_with_ids/train'
if not os.path.isdir(label_root):
mkdirs(label_root)
el:  # 如果之前已经⽣成过:递归删除⽬录和⽂件,重新⽣成⽬录
<(label_root)
os.makedirs(label_root)
cls_map ={
'Person=1'
'Pedestrian=2'
'Car=3'
'Person_sitting=4'
'Cyclist=5'
'Van=6'
qq验证码'Truck=7'
'Tram=8'
'Misc=9'
'DontCare=10'
}
print("Dir %s made"% label_root)
#qs = [s for s in os.listdir(q_root)]
#qs=['0000']
qs=['0000','0001','0002','0003',
'0004','0005','0006','0007',
'0008','0009','0010','0011',
'0012','0014','0015','0018',
'0019','0020']
#打印序列
print(qs)
tid_curr =0
tid_last =-1
total_track_id_num =0
for q in qs:  # 每段视频都对应⼀个gt.txt
print("Process %s, "% q, end='')
q_info_path = osp.join(q_root, q,'qinfo.ini')  #提取每个数据的info信息/media/ckq/data/kitti/MOT/images/train #print(q_info_path)
with open(q_info_path) as q_info_h:  # 读取*.ini ⽂件
q_info = q_ad()
q_width =int(q_info[q_info.find('imWidth=')+8:q_info.find('\nimHeight')])  # 视频的宽
q_height =int(q_info[q_info.find('imHeight=')+9:q_info.find('\nimExt')])  # 视频的⾼#print('q_width:',q_width)
#print('q_height:', q_height)
gt_txt = osp.join(q_root, q,'gt','gt.txt')  # 读取GT⽂件
#print(gt_txt)  #打印路径
#gt = np.loadtxt(gt_txt, dtype=np.str, delimiter=',')  # 加载成np格式
gt = np.loadtxt(gt_txt, dtype=np.float64, delimiter=',')  # 加载成np格式
苤蓝的家常做法# print(gt)  #打印⽂本内容
# print('gt.T')
# print(gt.T) #也是打印⽂本内容
idx = np.lexsort(gt.T[:2,:])  # 优先按照track id排序(对视频帧进⾏排序,⽽后对轨迹ID进⾏排序)
# print(idx)
gt = gt[idx,:]油酥辣椒
tr_ids =t(gt[:,1])
print("%d track ids in q %s"%(len(tr_ids), q))
total_track_id_num +=len(tr_ids)  # track id统计数量如何正确计算?
q_label_root = osp.join(label_root, q,'img1')
mkdirs(q_label_root)
# 读取GT数据的每⼀⾏(⼀⾏即⼀条数据)
# for fid, tid, x, y, w, h, mark, cls, vis_ratio in gt:
for fid, tid, type, truncated, occluded, alpha, \
bbox_left, bbox_top, bbox_right ,bbox_bottom ,_,_,_,_,_,_,_ in gt: #height, width, length , location_x,location_y,location_z , rotation_y in gt: # frame_id, track_id, top, left, width, height, mark, class, visibility ratio
#if cls != 3:  # 我们需要Car的标注数据
if type !=3:  # 我们需要Car的标注数据
continue
# if mark == 0:  # mark为0时忽略(不在当前帧的考虑范围)
#    continue
# if vis_ratio <= 0.2:
#    continue
fid =int(fid)
tid =int(tid)
# 判断是否是同⼀个track,记录上⼀个track和当前track
if not tid == tid_last:  # not的优先级⽐==⾼
tid_curr +=1
tid_last = tid
#由于kitti标签与训练标签参数有点不同需要⾃⼰计算 x y w h
w=float(bbox_right-bbox_left)
h=float(bbox_bottom-bbox_top)
x=int(bbox_left+0.5)
y=int(bbox_top+0.5)
# bbox中⼼点坐标
x += w /2
y += h /2
# ⽹label中写⼊track id, bbox中⼼点坐标和宽⾼(归⼀化到0~1)
# 第⼀列的0是默认只对⼀种类别进⾏多⽬标检测跟踪(0是类别)
label_str ='0 {:d} {:.6f} {:.6f} {:.6f} {:.6f}\n'.format(
tid_curr,
x / q_width,  # center_x
y / q_height,  # center_y
w / q_width,  # bbox_w
h / q_height)  # bbox_h
# print(label_str.strip())
label_f_path = osp.join(q_label_root,'{:06d}.txt'.format(fid))
with open(label_f_path,'a') as f:  # 以追加的⽅式添加每⼀帧的label
f.write(label_str)
print("Total %d track ids in this datat"% total_track_id_num)
print('Done')
kitti数据集标签⽣成 gen_lables_kitti_car.py:(Car Van Truck)
import os.path as osp
import os
import shutil
import numpy as np
def mkdirs(d):
# if ists(d):
if not osp.isdir(d):

本文发布于:2023-07-14 02:46:16,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1095361.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:标签   数据   打印   需要   跟踪   视频   排序   改成
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图