From c25c6b63a29e7c8f5655778b3bf73e0857eaa066 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sat, 14 Jan 2023 23:41:05 -0800 Subject: [PATCH 1/7] make matplotlib a late bind dependency --- libs/visualization.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/visualization.py b/libs/visualization.py index 3d7707f..bc5273e 100644 --- a/libs/visualization.py +++ b/libs/visualization.py @@ -1,6 +1,4 @@ import numpy as np -import matplotlib.pyplot as plt -import matplotlib.patches as patches import os.path import cv2 from PIL import Image @@ -50,6 +48,9 @@ class DisplayState: # display details such as bounding boxes in the image def dispaly_details(common_path, imgFolder, frame, dets, gts, trackers, unmatched_trckr, unmatched_gts, mot_trackers): + import matplotlib.pyplot as plt + import matplotlib.patches as patches + # display image if DisplayState.display: img = Image.open('%s/img1/%06d.jpg' % (common_path, frame)) From ac5584dff67c66ba34cf5a59f5dc3b362c7e9344 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sun, 15 Jan 2023 10:01:49 -0800 Subject: [PATCH 2/7] remove numba dependency --- libs/calculate_cost.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/calculate_cost.py b/libs/calculate_cost.py index 146956e..22c6099 100644 --- a/libs/calculate_cost.py +++ b/libs/calculate_cost.py @@ -1,4 +1,4 @@ -from numba import jit +# from numba import jit import numpy as np From 172e778eb6f01b8a0501a6c25bc63cbe9315ea52 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Thu, 19 Jan 2023 08:20:42 -0800 Subject: [PATCH 3/7] add more conf variables --- libs/tracker.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libs/tracker.py b/libs/tracker.py index c1ae341..355a209 100644 --- a/libs/tracker.py +++ b/libs/tracker.py @@ -69,7 +69,7 @@ def _update_matched_trackers(dets, kalman_trackers, unmatched_trks, occluded_trk return unmatched_trks_pos -def _build_new_targets(unmatched_before_before, unmatched_before, unmatched, area_avg, kalman_trackers): +def _build_new_targets(unmatched_before_before, unmatched_before, unmatched, area_avg, kalman_trackers, three_frame_certainty): if (len(unmatched_before_before) != 0) and (len(unmatched_before) != 0) and (len(unmatched) != 0): new_trackers, del_ind = association.find_new_trackers_2(unmatched, unmatched_before, unmatched_before_before, area_avg) @@ -82,7 +82,7 @@ def _build_new_targets(unmatched_before_before, unmatched_before, unmatched, are del_ind = np.flip(del_ind, axis=0) for i, new_tracker in enumerate(new_trackers): new_trk_certainty = unm[new_tracker[0], 4] + unmb[new_tracker[1], 4] + unmbb[new_tracker[2], 4] - if new_trk_certainty > 2: + if new_trk_certainty > three_frame_certainty: trk = kalman_tracker.KalmanBoxTracker(unm[new_tracker[0], :], 1, unmb[new_tracker[1], :]) kalman_trackers.append(trk) # remove matched detection from unmatched arrays @@ -124,6 +124,8 @@ def __init__(self, max_age=3, min_hits=3, scene=np.array([1920, 1080])): self.scene = scene self.conf_trgt = 0 self.conf_objt = 0 + self.conf_uncertainty = 0.6 + self.conf_three_frame_certainty = .4 def to_json(self): """ @@ -168,7 +170,7 @@ def update(self, dets, gts): if self.frame_count <= self.min_hits: for i in unmatched_dets: # Put condition on uncertainty - if dets[i, 4] > 0.6: + if dets[i, 4] > self.conf_uncertainty: # put dets[i, :] as dummy data for last argument trk = kalman_tracker.KalmanBoxTracker(dets[i, :], 0, dets[i, :]) self.trackers.append(trk) @@ -179,7 +181,7 @@ def update(self, dets, gts): # Build new targets _build_new_targets(self.unmatched_before_before, self.unmatched_before, self.unmatched, - self.area_avg_array[len(self.area_avg_array) - 1], self.trackers) + self.area_avg_array[len(self.area_avg_array) - 1], self.trackers, self.conf_three_frame_certainty) self.unmatched_before_before = self.unmatched_before self.unmatched_before = self.unmatched From a56c9d29e9185c0fee60e05b7303fb795ec737a9 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sat, 21 Jan 2023 17:47:59 -0800 Subject: [PATCH 4/7] add history filtering --- libs/association.py | 3 +-- libs/tracker.py | 36 ++++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/libs/association.py b/libs/association.py index 80c3464..77af071 100644 --- a/libs/association.py +++ b/libs/association.py @@ -155,8 +155,7 @@ def _filter_low_iou_low_area(matched_indices_ext, matched_indices, iou_matrix_ex return matches_ext_com, del_ind -def associate_detections_to_trackers(mot_tracker, detections, trackers, groundtruths, average_area, - iou_threshold=0.3, ): +def associate_detections_to_trackers(mot_tracker, detections, trackers, groundtruths, average_area, iou_threshold): """ Assigns detections to tracked object (both represented as bounding boxes) Returns 5 lists of matches, unmatched_detections, unmatched_trackers, occluded_trackers and unmatched ground truths diff --git a/libs/tracker.py b/libs/tracker.py index 355a209..a321007 100644 --- a/libs/tracker.py +++ b/libs/tracker.py @@ -118,14 +118,16 @@ def __init__(self, max_age=3, min_hits=3, scene=np.array([1920, 1080])): self.trackers = [] self.area_avg_array = [] self.frame_count = 0 - self.unmatched_before_before = [] - self.unmatched_before = [] + self.unmatched_history = [] self.unmatched = [] + self.unmatched_before = [] + self.unmatched_before_before = [] self.scene = scene self.conf_trgt = 0 self.conf_objt = 0 - self.conf_uncertainty = 0.6 self.conf_three_frame_certainty = .4 + self.conf_iou_threshold = .3 + self.conf_unmatched_history_size = 3 def to_json(self): """ @@ -135,14 +137,12 @@ def to_json(self): "area_avg_array": list(map(lambda x: x if np.isscalar(x) else x[0], self.area_avg_array)), "conf_objt": self.conf_objt, "conf_trgt": self.conf_trgt, + "conf_unmatched_history_size": self.conf_unmatched_history_size, "frame_count": self.frame_count, "max_age": self.max_age, "min_hits": self.min_hits, "scene": self.scene.tolist(), "trackers": list(map(lambda x: x.to_json(), self.trackers)), - "unmatched": list(map(lambda x: x.tolist(), self.unmatched)), - "unmatched_before": list(map(lambda x: x.tolist(), self.unmatched_before)), - "unmatched_before_before": list(map(lambda x: x.tolist(), self.unmatched_before_before)), } def update(self, dets, gts): @@ -161,7 +161,7 @@ def update(self, dets, gts): trks = _remove_outside_trackers(trks, self.trackers, self.scene) - matched, unmatched_dets, unmatched_trks, occluded_trks, unmatched_gts = association.associate_detections_to_trackers(self, dets, trks, gts, area_avg) + matched, unmatched_dets, unmatched_trks, occluded_trks, unmatched_gts = association.associate_detections_to_trackers(self, dets, trks, gts, area_avg, self.conf_iou_threshold) # update matched trackers with assigned detections unmatched_trks_pos = _update_matched_trackers(dets, self.trackers, unmatched_trks, occluded_trks, matched, trks) @@ -170,20 +170,36 @@ def update(self, dets, gts): if self.frame_count <= self.min_hits: for i in unmatched_dets: # Put condition on uncertainty - if dets[i, 4] > self.conf_uncertainty: + if dets[i, 4] > 0.6: # put dets[i, :] as dummy data for last argument trk = kalman_tracker.KalmanBoxTracker(dets[i, :], 0, dets[i, :]) self.trackers.append(trk) else: + # create current unmatched list self.unmatched = [] for i in unmatched_dets: self.unmatched.append(dets[i, :]) + # find previous unmatched in history + unmatched_available = list(filter(lambda check: len(check), self.unmatched_history)) + # take last two + unmatched_available = unmatched_available[-2:] + self.unmatched_before_before = [] + self.unmatched_before = [] + if len(unmatched_available) == 1: + self.unmatched_before = unmatched_available[0] + elif len(unmatched_available) == 2: + self.unmatched_before_before, self.unmatched_before = unmatched_available + + if len(unmatched_available) == 2 and ((self.unmatched_history[len(self.unmatched_history) - 1] is not self.unmatched_before) or (self.unmatched_history[len(self.unmatched_history) - 2] is not self.unmatched_before_before)): + print('recovered') + + self.unmatched_history.append(self.unmatched) + self.unmatched_history = self.unmatched_history[-self.conf_unmatched_history_size:] + # Build new targets _build_new_targets(self.unmatched_before_before, self.unmatched_before, self.unmatched, self.area_avg_array[len(self.area_avg_array) - 1], self.trackers, self.conf_three_frame_certainty) - self.unmatched_before_before = self.unmatched_before - self.unmatched_before = self.unmatched # get position of unmatched ground truths unmatched_gts_pos = [] From 16a46b77f7702f6837bd25ba1c18cd2b5e12a1f8 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sun, 22 Jan 2023 17:39:31 -0800 Subject: [PATCH 5/7] remove logging --- libs/tracker.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/libs/tracker.py b/libs/tracker.py index a321007..b192592 100644 --- a/libs/tracker.py +++ b/libs/tracker.py @@ -191,9 +191,6 @@ def update(self, dets, gts): elif len(unmatched_available) == 2: self.unmatched_before_before, self.unmatched_before = unmatched_available - if len(unmatched_available) == 2 and ((self.unmatched_history[len(self.unmatched_history) - 1] is not self.unmatched_before) or (self.unmatched_history[len(self.unmatched_history) - 2] is not self.unmatched_before_before)): - print('recovered') - self.unmatched_history.append(self.unmatched) self.unmatched_history = self.unmatched_history[-self.conf_unmatched_history_size:] From 3db0328cd34f1bc1070cc3ddf47060e476eff553 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 20 Mar 2023 16:14:44 -0700 Subject: [PATCH 6/7] move cv2 to late bind --- libs/visualization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/visualization.py b/libs/visualization.py index bc5273e..faa3251 100644 --- a/libs/visualization.py +++ b/libs/visualization.py @@ -1,6 +1,5 @@ import numpy as np import os.path -import cv2 from PIL import Image from . import convert @@ -129,6 +128,7 @@ def generate_video(image_folder, video_name, fps): if img.endswith(".jpg") or img.endswith(".jpeg") or img.endswith(".png")] + import cv2 frame = cv2.imread(os.path.join(image_folder, images[0])) # setting the frame width, height width according to the width & height of first image From 657e1e16dfdd5831823f19f280c0775cc626fe6f Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Fri, 14 Apr 2023 09:58:44 -0700 Subject: [PATCH 7/7] remove average area check --- libs/tracker.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libs/tracker.py b/libs/tracker.py index b192592..860866a 100644 --- a/libs/tracker.py +++ b/libs/tracker.py @@ -116,7 +116,6 @@ def __init__(self, max_age=3, min_hits=3, scene=np.array([1920, 1080])): self.max_age = max_age self.min_hits = min_hits self.trackers = [] - self.area_avg_array = [] self.frame_count = 0 self.unmatched_history = [] self.unmatched = [] @@ -134,7 +133,6 @@ def to_json(self): Returns a dict object that can be used to serialize this a JSON """ return { - "area_avg_array": list(map(lambda x: x if np.isscalar(x) else x[0], self.area_avg_array)), "conf_objt": self.conf_objt, "conf_trgt": self.conf_trgt, "conf_unmatched_history_size": self.conf_unmatched_history_size, @@ -157,7 +155,6 @@ def update(self, dets, gts): self.frame_count += 1 trks, area_avg = _init_area_and_trackers(self.trackers) - self.area_avg_array.append(area_avg) trks = _remove_outside_trackers(trks, self.trackers, self.scene) @@ -196,7 +193,7 @@ def update(self, dets, gts): # Build new targets _build_new_targets(self.unmatched_before_before, self.unmatched_before, self.unmatched, - self.area_avg_array[len(self.area_avg_array) - 1], self.trackers, self.conf_three_frame_certainty) + area_avg, self.trackers, self.conf_three_frame_certainty) # get position of unmatched ground truths unmatched_gts_pos = []