FairMOT训练自己的数据集及学习笔记
FairMOT的复现cannot import name ‘amp‘原因:1.只有PyTorch1.6版本以上才可以从torch.cuda中import amp;解决措施:https://blog.csdn.net/lucifer479/article/details/111322564
https://codechina.csdn.net/mirrors/ifzhang/FairMOT
一、FairMOT的复现
https://www.zhouchen1998.cn/2020/10/24/fairmot-realtime/
cannot import name ‘amp‘
原因:
1.只有PyTorch1.6版本以上才可以从torch.cuda中import amp;
解决措施:
https://blog.csdn.net/lucifer479/article/details/111322564
二、FairMOT训练自定义数据集
You can train FairMOT on custom dataset by following several steps bellow:
- Generate one txt label file for one image. Each line of the txt label file represents one object. The format of the line is: “class id x_center/img_width y_center/img_height w/img_width h/img_height”. You can modify src/gen_labels_16.py to generate label files for your custom dataset.
- Generate files containing image paths. The example files are in src/data/. Some similar code can be found in src/gen_labels_crowd.py
- Create a json file for your custom dataset in src/lib/cfg/. You need to specify the “root” and “train” keys in the json file. You can find some examples in src/lib/cfg/.
- Add --data_cfg ‘…/src/lib/cfg/your_dataset.json’ when training.
(一)需要知道三个东西
1.你的数据集gt的数据格式
例如:
<frame>,<id>,<bb_left>,<bb_top>,<bb_width>,<bb_height>,<cos>,<cat>,<vis>
其中,<frame>
表示目标出现在哪一帧,<id>
表示目标所属的tracklet ID。接下来的四个值表示目标边界框在二维帧坐标中的位置,由左上角坐标及边界框的宽度和高度表示。<cos>
表示目标的完整性是否需要被考虑(1)或忽略(0),本数据集默认所有已标注目标均需考虑,均为1。<cat>
表示目标的类别,即飞机(1)或舰船(2)。<vis>
表示目标的可视化程度,本数据集默认目标完全可视,均为1。
2.FairMOT训练所需的数据格式
<class> <id> <x_center/img_width> <y_center/img_height> <w/img_width> <h/img_height>
class :目标类别
id :目标id
x_center/img_width :归一化中心列坐标
y_center/img_height :归一化中心行坐标
w/img_width :归一化宽
h/img_height :归一化高
3.FairMOT生成result的数据格式
(二)训练自己的数据集踩坑记录(血泪教训)
1. 数据集对应.train文件的生成
import os
import os.path as osp
image_flder = "/home/lyp/FairMOT-master/data/trainData" #数据集所在位置
imgs = os.listdir(image_flder)
#print(imgs)
train_f = open("/home/lyp/FairMOT-master/src/data/trainData.train", "w") #生成.train文件位置
for img_name in imgs:
image_path=osp.join(image_flder,img_name)
print(image_path[30:])
image_names=os.listdir(image_path)
image_names.sort()
print(image_names)
for image_name in image_names:
save_str = image_path[30:] + '/' + image_name +"\n" #修改imgae_path来控制显示的路径
print(save_str)
train_f.write(save_str)
train_f.close()
2. jde.py文件需要修改
通过修改num_classes来指定训练的类别个数,要不然会报错
[1]IndexError: index 1 is out of bounds for axis 0 with size 1
[2]ValueError: not enough values to unpack (expected 2, got 1)
绿色箭头处是open(path, ‘r’) 我下载下来源码的是open(path, ‘rb’)导致一直报错
[1]TypeError: Can't mix strings and bytes in path components
[2]路径/b'xxxxxx.txt' not found.
3.如果使用多卡GPU,修改train.py文件
在这里修改默认GPU,否则会报错
RuntimeError: module must have its parameters and buffers on device cuda:2 (device_ids[0]) but found
看到成功开始训练后,终于舒服了!
4.我用FairMOT训练了两个数据集,训练完成后track却报错
Traceback (most recent call last):
File "demo.py", line 44, in
demo(opt)
File "demo.py", line 33, in demo
use_cuda=opt.gpus!=[-1])
File "FairMOT-master/src/track.py", line 90, in eval_seq
online_targets = tracker.update(blob, img0)
File "FairMOT-master/src/lib/tracker/multitracker.py", line 264, in update
id_feature = id_feature[remain_inds]
IndexError: boolean index did not match indexed array along dimension 0; dimension is 500 but corresponding boolean dimension is 420
应该是维度没有对上,我的数据集图片是19201080的,FairMOT数据集格式是1088608为输入的,但是训练时进入网络好像是会统一resize的
网上也有人说说FairMOT只支持单类别的多目标追踪
我目前还未解决这个多类别报错的问题
基于FairMOT训练多个数据集可以参考这个链接
https://github.com/CaptainEven/MCMOT
更多推荐
所有评论(0)