From 83c67146e94c83604b66125b55a484ca5a51f931 Mon Sep 17 00:00:00 2001 From: Igor Ryabchikov Date: Sat, 4 Dec 2021 17:28:03 +0300 Subject: [PATCH] tracker - use original detections without filtering --- test/tracking_test/docker-compose.yml | 19 ++++++++++++++++++- test/tracking_test/tracking_general_test.py | 18 +++++++++++++++++- .../byte_track/yolox/tracker/byte_tracker.py | 10 ++++++++++ .../fairmot/src/lib/tracker/multitracker.py | 11 +++++++++++ tracking/run.py | 5 ++--- 5 files changed, 58 insertions(+), 5 deletions(-) diff --git a/test/tracking_test/docker-compose.yml b/test/tracking_test/docker-compose.yml index 97d0424..34e315e 100644 --- a/test/tracking_test/docker-compose.yml +++ b/test/tracking_test/docker-compose.yml @@ -38,6 +38,24 @@ services: command: 'python run.py detection_cbnet --log_dir /opt/detection_cbnet/logs --weights_url https://www.dropbox.com/s/0vsk5zld23tgrka/htc_cbv2_swin_large22k_patch4_window7_mstrain_400-1400_giou_4conv1f_adamw_1x_coco.pth?dl=1 --bootstrap_servers kafka:29097' +# detection: +# # Текущей директорией в путях является директория, в которой расположен данный docker-compose.yml файл +# build: ../../detection/docker-build-context +# image: devbeh/detection +# depends_on: +# - kafka +# volumes: +# - type: bind +# source: ../../ +# target: /opt/detection/src +# networks: +# - tracking_net +# runtime: nvidia +# environment: +# - NVIDIA_VISIBLE_DEVICES=${DEVBEH_DETECTION_NVIDIA_VISIBLE_DEVICES:-0} +# command: 'python3.6 run.py detection --log_dir /opt/detection/logs +# --weights_url https://www.dropbox.com/s/qx1tlfmpkacvmep/COCO-MaskRCNN-R101FPN9xGNCasAugScratch.npz?dl=1 +# --bootstrap_servers kafka:29097' tracking: build: ../../tracking/docker-build-context image: devbeh/tracking @@ -56,7 +74,6 @@ services: - NVIDIA_VISIBLE_DEVICES=${DEVBEH_TRACKING_NVIDIA_VISIBLE_DEVICES:-0} command: 'python run.py tracking --log_dir /opt/tracking/logs --fairmot_weights_url ${DEVBEH_FAIRMOT_WEIGHTS_URL:-https://drive.google.com/u/0/uc?export=download&confirm=VHcw&id=1iqRQjsG9BawIl8SlFomMg5iwkb6nqSpi} - --use_fairmot --bootstrap_servers kafka:29097' networks: tracking_net: diff --git a/test/tracking_test/tracking_general_test.py b/test/tracking_test/tracking_general_test.py index 9963648..c0f226d 100644 --- a/test/tracking_test/tracking_general_test.py +++ b/test/tracking_test/tracking_general_test.py @@ -122,12 +122,28 @@ class TrackingServiceTest(unittest.TestCase): self.assertEqual(expected_len, len(detection_results)) detection_batch = [] - for r in detection_results: + # for r in detection_results: + for frame, r in zip(frame_batch, detection_results): self.assertEqual(r.err.msg, "") if r.frame_id != -1: # self.assertGreater(len(r.detection.entries), 0) detection_batch.append(r.detection.entries) + # boxes = [] + # for detection_entry in r.detection.entries: + # boxes.append({'id': 0, + # 'class': detection_entry.class_id, + # 'score': detection_entry.score, + # 'box': [detection_entry.box_top_left_x, + # detection_entry.box_top_left_y, + # detection_entry.box_bottom_right_x, + # detection_entry.box_bottom_right_y]}) + # + # frame = np.fromstring(frame, np.uint8) + # frame = cv2.imdecode(frame, cv2.IMREAD_ANYCOLOR) + # frame = draw_boxes(frame, boxes) + # video_dst.write(frame) + print("Sending batch to tracker " + str(first_frame_id)) for i, (frame, detections) in enumerate(zip(frame_batch, detection_batch)): diff --git a/tracking/docker-build-context/byte_track/yolox/tracker/byte_tracker.py b/tracking/docker-build-context/byte_track/yolox/tracker/byte_tracker.py index d995082..c214618 100644 --- a/tracking/docker-build-context/byte_track/yolox/tracker/byte_tracker.py +++ b/tracking/docker-build-context/byte_track/yolox/tracker/byte_tracker.py @@ -17,6 +17,7 @@ class STrack(BaseTrack): def __init__(self, tlwh, score, class_id, next_id_supplier): # wait activate + self.last_tlwh = np.asarray(tlwh, dtype=np.float) self._tlwh = np.asarray(tlwh, dtype=np.float) self.kalman_filter = None self.mean, self.covariance = None, None @@ -71,6 +72,7 @@ class STrack(BaseTrack): if new_id: self.track_id = self.next_id_supplier() self.score = new_track.score + self.last_tlwh = new_track.last_tlwh.copy() def update(self, new_track, frame_id): """ @@ -90,6 +92,7 @@ class STrack(BaseTrack): self.is_activated = True self.score = new_track.score + self.last_tlwh = new_track.last_tlwh.copy() @property # @jit(nopython=True) @@ -104,6 +107,13 @@ class STrack(BaseTrack): ret[:2] -= ret[2:] / 2 return ret + @property + # @jit(nopython=True) + def last_tlbr(self): + ret = self.last_tlwh.copy() + ret[2:] += ret[:2] + return ret + @property # @jit(nopython=True) def tlbr(self): diff --git a/tracking/docker-build-context/fairmot/src/lib/tracker/multitracker.py b/tracking/docker-build-context/fairmot/src/lib/tracker/multitracker.py index c1e78de..6683edc 100644 --- a/tracking/docker-build-context/fairmot/src/lib/tracker/multitracker.py +++ b/tracking/docker-build-context/fairmot/src/lib/tracker/multitracker.py @@ -26,6 +26,7 @@ class STrack(BaseTrack): def __init__(self, tlwh, score, temp_feat, next_id_supplier, buffer_size=30): # wait activate + self.last_tlwh = np.asarray(tlwh, dtype=np.float) self._tlwh = np.asarray(tlwh, dtype=np.float) self.kalman_filter = None self.mean, self.covariance = None, None @@ -99,6 +100,7 @@ class STrack(BaseTrack): self.track_id = self.next_id_supplier() self.score = new_track.score self.score_list.append(self.score) + self.last_tlwh = new_track.last_tlwh.copy() def update(self, new_track, frame_id, update_feature=True): """ @@ -122,6 +124,8 @@ class STrack(BaseTrack): if update_feature: self.update_features(new_track.curr_feat) + self.last_tlwh = new_track.last_tlwh.copy() + @property # @jit(nopython=True) def tlwh(self): @@ -135,6 +139,13 @@ class STrack(BaseTrack): ret[:2] -= ret[2:] / 2 return ret + @property + # @jit(nopython=True) + def last_tlbr(self): + ret = self.last_tlwh.copy() + ret[2:] += ret[:2] + return ret + @property # @jit(nopython=True) def tlbr(self): diff --git a/tracking/run.py b/tracking/run.py index 2ecd4bb..d41b48d 100644 --- a/tracking/run.py +++ b/tracking/run.py @@ -94,7 +94,7 @@ def track(manager_id, video_id, tracker_factory, fairmot_tracker_factory, use_fa result = [] for t in tracks: - tlbr = t.tlbr + tlbr = t.last_tlbr entry = TrackingEntry(id=correct_track_id(t.track_id, use_fairmot)) entry.detection.CopyFrom(DetectionEntry(box_top_left_x=int(tlbr[0]), box_top_left_y=int(tlbr[1]), box_bottom_right_x=int(tlbr[2]), box_bottom_right_y=int(tlbr[3]), @@ -125,7 +125,7 @@ def track(manager_id, video_id, tracker_factory, fairmot_tracker_factory, use_fa use_detections) for t in fairmot_tracks: - tlbr = t.tlbr + tlbr = t.last_tlbr entry = TrackingEntry(id=t.track_id * 2) entry.detection.CopyFrom(DetectionEntry(box_top_left_x=int(tlbr[0]), box_top_left_y=int(tlbr[1]), box_bottom_right_x=int(tlbr[2]), box_bottom_right_y=int(tlbr[3]), @@ -196,7 +196,6 @@ def create_fairmot_tracker(model, max_frames_lost): opt.K = 500 # 0.4 - дефолт. Попробовать opt.conf_thres = 0.6 - # todo: попробовать другие параметры (30 - default) opt.track_buffer = max_frames_lost opt.reid_dim = 128 opt.num_classes = 1 -- GitLab