YoloV5 + deepsort + Fast-ReID complete pedestrian re-identification system (3)

Fast-Reid series article directory


foreword

The previous fast-reid training used the Fast-Reid framework to train the model in its own application scenario. The training strategy was to integrate a large number of open source reid data sets and train a total of 30W+ data together with its own data.
The code is open source:
Yolov5-Deepsort-Fastreid
yolov5-deepsort-pedestrian-counting

1. yolov5 + deepsort

Using yolov5 to realize pedestrian detection and deepsort to track, it can better prevent the misidentification of the reid model in the case of occlusion.
I encapsulated yolov5 and deepsort into classes respectively, which are easy to embed into my own project, so as to facilitate the replacement of detection or tracking algorithms.
I replaced the representation extraction model of deepsor with the reid model trained by fastreid. Can improve tracking performance.
For details, please see the code of person_search_reid.py as follows (example):

class yolo_reid():
    def __init__(self, cfg, args, path):
        self.args = args
        self.video_path = path
        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!", UserWarning)
		# Person_detect行人检测类
        self.person_detect = Person_detect(self.args, self.video_path)
        # deepsort 类
        self.deepsort = build_tracker(cfg, args.sort, use_cuda=use_cuda)
        imgsz = check_img_size(args.img_size, s=32)  # self.model.stride.max())  # check img_size
        self.dataset = LoadImages(self.video_path, img_size=imgsz)
        self.query_feat = np.load(args.query)
        self.names = np.load(args.names)

    def deep_sort(self):
        idx_frame = 0
        results = []
        for video_path, img, ori_img, vid_cap in self.dataset:
            idx_frame += 1
            t1 = time_synchronized()

			# yolo detection
            bbox_xywh, cls_conf, cls_ids, xy = self.person_detect.detect(video_path, img, ori_img, vid_cap)
            
            # do tracking  # features:reid模型输出512dim特征
            outputs, features = self.deepsort.update(bbox_xywh, cls_conf, ori_img)
            print(len(outputs), len(bbox_xywh), features.shape)

2. Pedestrian Counting

By the way, yolov5 + deepsort realizes the pedestrian counting function, counts the total number of people who have appeared in the camera, and counts the pedestrians crossing the custom yellow line as follows:
insert image description here
Please refer to the person_count.py code for details

2. Reid Extraction Features

Pedestrian re-identification is similar to face recognition. The first contact can be considered as the recognition of replacing faces with pedestrians.

1. Intercept the bottom bank of pedestrians that need to be identified
insert image description here
. 2. Run person_bank.py to save pedestrian features and names, so as to facilitate feature comparison and identify corresponding names.
insert image description here

# features:reid模型输出512dim特征
person_cossim = cosine_similarity(features, self.query_feat)
max_idx = np.argmax(person_cossim, axis=1)
maximum = np.max(person_cossim, axis=1)
max_idx[maximum < 0.6] = -1
score = maximum
reid_results = max_idx
draw_person(ori_img, xy, reid_results, self.names)  # draw_person name

The figure below identifies the pedestrians a1111 and b22222 in the bottom library . Unrecognized is None
insert image description here

Summarize

When the scene is not complex and there is no occlusion, the recognition accuracy is still possible. It can also be run in real time using a graphics card. The next step is to optimize the combination of tracking and re-identification in terms of business logic, reduce the amount of calculation, and improve recognition performance. If interested students have a good way, welcome to communicate with me, thank you!

Guess you like

Origin blog.csdn.net/zengwubbb/article/details/113422048