FairMOT trains its own data sets and learning notes

https://codechina.csdn.net/mirrors/ifzhang/FairMOT

1, Reproduction of FairMOT

https://www.zhouchen1998.cn/2020/10/24/fairmot-realtime/

cannot import name 'amp'
reason:
1. Only PyTorch1.6 or above can import amp from torch.cuda;

Solution:
https://blog.csdn.net/lucifer479/article/details/111322564

2, FairMOT training custom dataset

You can train FairMOT on custom dataset by following several steps bellow:

  1. 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.
  2. Generate files containing image paths. The example files are in src/data/. Some similar code can be found in src/gen_labels_crowd.py
  3. 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/.
  4. Add --data_cfg '.../src/lib/cfg/your_dataset.json' when training.

(1) There are three things you need to know

1. The data format of your dataset gt

For example:

<frame>,<id>,<bb_left>,<bb_top>,<bb_width>,<bb_height>,<cos>,<cat>,<vis>

Where, < frame > indicates the frame in which the target appears, and < ID > indicates the tracklet ID to which the target belongs. The next four values represent the position of the target bounding box in the two-dimensional frame coordinates, which are represented by the upper left corner coordinates and the width and height of the bounding box< Cos > indicates whether the integrity of the target needs to be considered (1) or ignored (0). By default, all labeled targets in this dataset need to be considered, all of which are 1< Cat > indicates the category of the target, i.e. aircraft (1) or ship (2)< Vis > indicates the visualization degree of the target. The default target of this dataset is fully visible, which is 1.

2. Data format required for fairmot training

 <class> <id> <x_center/img_width> <y_center/img_height> <w/img_width> <h/img_height> 
class               : Target category
id                  : target id
x_center/img_width  : Normalized center column coordinates
y_center/img_height : Normalized central row coordinates
w/img_width         : Normalized width
h/img_height        : Normalized high

3. Data format of result generated by fairmot

(2) Train your own dataset to step on the pit record (blood and tears lesson)

1. Generation of. train file corresponding to dataset

import os
import os.path as osp
image_flder = "/home/lyp/FairMOT-master/data/trainData"   #Data set location
imgs = os.listdir(image_flder)
#print(imgs)
train_f = open("/home/lyp/FairMOT-master/src/data/trainData.train", "w")   #Generate. train file location

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"   #Modify imgae_path to control the displayed path
        print(save_str)
        train_f.write(save_str)

train_f.close()

2. The jde.py file needs to be modified


By modifying num_classes to specify the number of training categories, otherwise an error will be reported

[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)

The green arrow is open(path, 'r'). The source code I downloaded is open(path, 'rb'), which leads to constant error reporting

[1]TypeError: Can't mix strings and bytes in path components
[2]route/b'xxxxxx.txt' not found.

3. If a multi card GPU is used, modify the train.py file


Modify the default GPU here, otherwise an error will be reported

RuntimeError: module must have its parameters and buffers on device cuda:2 (device_ids[0]) but found

After seeing the successful start of training, I'm finally comfortable!

4. I trained two data sets with FairMOT, but the track reported an error after the training

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

It should be that the dimensions are not aligned. My dataset image is 19201080, and the FairMOT dataset format is 1088608. However, it seems that the network will be resize d uniformly during training
It is also said on the Internet that FairMOT only supports single category multi-target tracking
I haven't solved the problem of multi category error reporting yet
Training multiple data sets based on FairMOT can refer to this link
https://github.com/CaptainEven/MCMOT

Tags: Computer Vision Deep Learning

Posted on Fri, 08 Oct 2021 00:34:19 -0400 by genix2011