How to implement target tracking based on your own trained Yolov5 weights and combined with DeepSort

There are many related and good operation demos on the Internet , but I still encounter a lot of doubts during the training process. Therefore, I will summarize the problems solved during the operation.

1. Does deepsort’s training set have to be based on frame-by-frame video?
After trying it, I found that non-continuous images can still be used as training sets. An instance (such as specifying a person, a certain car, etc.) can correspond to a train\test folder. Of course, frame-by-frame results are better.
Insert image description here

2. There is more than one type of yolo training, what should I do?
According to question 1, each type can make 1 or more instances (for example, type 0 represents a bicycle, there can be multiple instances of red bicycles, blue bicycles, etc., category 1 represents xxx, the same reason), all are concentrated Just store it in train\test.

Insert image description here

3. After deepsort training is completed, how to track the target in your own video?
Just modify the relevant parameters of track.py, as shown below. Note that if yolo recognizes multiple categories, you need to modify the parameters in '--classes' accordingly! ! !

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    # 表示yolo训练得到的权重
    parser.add_argument('--yolo_weights', type=str, default='yolov5/weights/best.pt', help='model.pt path')
    # 表示训练得到的权重
    parser.add_argument('--deep_sort_weights', type=str, default='deep_sort_pytorch/deep_sort/deep/checkpoint/ckpt.t7', help='ckpt.t7 path')
    # 测试视频
    parser.add_argument('--source', type=str, default='data/test.mp4', help='source')
    parser.add_argument('--output', type=str, default='inference/output', help='output folder')  # output folder
    parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
    parser.add_argument('--conf-thres', type=float, default=0.4, help='object confidence threshold')
    parser.add_argument('--iou-thres', type=float, default=0.5, help='IOU threshold for NMS')
    parser.add_argument('--fourcc', type=str, default='mp4v', help='output video codec (verify ffmpeg support)')
    parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
    # True表示显示、保存、存储结果
    parser.add_argument('--show-vid', action='store_true', default=True,help='display tracking video results')
    parser.add_argument('--save-vid', action='store_true',default=True, help='save video tracking results')
    parser.add_argument('--save-txt', action='store_true',default=True, help='save MOT compliant results to *.txt')
    # 表示跟踪所有类别,yolo训练类型共200种
    parser.add_argument('--classes', nargs='+', default=list(range(200)), type=int, help='filter by class')
    parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
    parser.add_argument('--augment', action='store_true', help='augmented inference')
    parser.add_argument('--evaluate', action='store_true', help='augmented inference')
    parser.add_argument("--config_deepsort", type=str, default="deep_sort_pytorch/configs/deep_sort.yaml")
    args = parser.parse_args()
    args.img_size = check_img_size(args.img_size)

    with torch.no_grad():
        detect(args)

Effect
Insert image description here

Guess you like

Origin blog.csdn.net/HeyLoong/article/details/132547570