The modified version of sort tracking (https://github.com/abewley/sort) compatible with the Yolo Series
- sort_cls.py: The main file of the sort tracking with modification. sort will will be initialized with
max_age
,min_hits
,iou_threshold
based on arguments.update
method will with the detections parameters and return the tracking results.- arguments:
- dets - a numpy array of detections in the format [[x1,y1,x2,y2,score, cls],[x1,y1,x2,y2,score, cls],...]
- returns:
- Requires: this method must be called once for each frame even with empty detections (use np.empty((0, 7)) for frames without detections).
- Returns the a similar array, where the last column is the object ID. [[x1,y1,x2,y2,score, cls, ID],[x1,y1,x2,y2,score, cls, ID],...]
- arguments:
- utils.py: conatins the functions
check_file()
: for checking file existence andcheck_suffix()
: suffix of the file - loadyaml.py: contains the function
loadyaml()
: for loading the yaml file - tracker.py: main tracking file. It will load the sort_cls.py and use the update method to get the tracking results. please check class
Tracker
andMuliCameraTracker
for more details.
Install
Clone repo and install [requirements.txt](requirements.txt)git clone https://github.com/amish0/Sort_tracking
cd Sort_tracking
pip install -r requirements.txt
Example
Sort tracking can be used as a standalone tracker.
Please check the [Sort_cls.py](Sort_cls.py) for more details.# import Sort
from Sort_cls import Sort
# Create an instance of the tracker
obj_tracker = Sort(max_age=1, min_hits=3, iou_threshold=0.3)
# get detections
dets = np.array([[0,0,10,10,0.9,1],[0,0,10,10,0.8,1],[0,0,10,10,0.7,1], ....])
# update tracker
tracking_results = obj_tracker.update(dets)
# print tracking results
print(tracking_results)
Tracker class can be used to track the objects in a video.
Please check the [tracker.py](tracker.py) for more details.# import tracker
from tracker import Tracker
# Create an instance of tracker
tracker = Tracker(tracker_type = 'sort')
# detections result from object detector
dets = np.array([[0,0,10,10,0.9,1],[0,0,10,10,0.8,1],[0,0,10,10,0.7,1], ....])
# update tracker
tracking_results = tracker(dets)
# print tracking results
print(tracking_results)
MuliCameraTracker class can be used to track the objects in a video.
Please check the [tracker.py](tracker.py) for more details.# import multi camera tracker
from tracker import MuliCameraTracker
# set of tracker id
track_id = {0, 1} # set of camera ids
# Create an instance of tracker
tracker = MuliCameraTracker(tracker_type = 'sort', track_id = track_id )
# detections result from each camera by a object detector
dets = {0: np.array([[0,0,10,10,0.9,1],[0,0,10,10,0.8,1],[0,0,10,10,0.7,1], ....]),
1: np.array([[0,0,10,10,0.9,1],[0,0,10,10,0.8,1],[0,0,10,10,0.7,1], ....])}
# update tracker
tracking_results = tracker(dets)
# print tracking results of camera id 0
print(tracking_results[0]) # tracking results of camera id 0
Class Explanation
-
sort
: The class of the sort tracking. It will be initialized withmax_age
,min_hits
,iou_threshold
based on arguments.update
method will with the detections parameters and return the tracking results. Please check the sort_cls.py for more details.- arguments:
- dets - a numpy array of detections in the format
[[x1,y1,x2,y2,score, cls],[x1,y1,x2,y2,score, cls],...]
- dets - a numpy array of detections in the format
- returns:
- Requires: this method must be called once for each frame even with empty detections (use np.
empty((0, 7))
for frames without detections). - Returns the a similar array, where the last column is the object ID.
[[x1,y1,x2,y2,score, cls, ID],[x1,y1,x2,y2,score, cls, ID],...]
- Requires: this method must be called once for each frame even with empty detections (use np.
- arguments:
-
Tracker
: This class will initialize the tracker with the given tracker_type and tracker parameters from corresponding yaml file. call will take the detections and return the tracking results. Please check the tracker.py for more details.- arguments:
- dets - a numpy array of detections in the format
[[x1,y1,x2,y2,score, cls],[x1,y1,x2,y2,score, cls],...]
- dets - a numpy array of detections in the format
- returns:
- Requires: this method must be called once for each frame even with empty detections (use np.
empty((0, 7))
for frames without detections). - Returns the a similar array, where the last column is the object ID.
[[x1,y1,x2,y2,score, cls, ID],[x1,y1,x2,y2,score, cls, ID],...]
- Requires: this method must be called once for each frame even with empty detections (use np.
- arguments:
-
MuliCameraTracker
: This class will initialize the tracker with the given tracker_type, and a set of tracker id (each tracker id will be associated with each camera) and tracker parameters from corresponding yaml file. call will take the detections and return the tracking results. Please check the tracker.py for more details.- arguments:
- dets - a dictionary of camera id and detections in the format
{camera\_id\_1: [[x1,y1,x2,y2,score, cls],[x1,y1,x2,y2,score, cls],...], camera_id_2: [[x1,y1,x2,y2,score, cls],[x1,y1,x2,y2,score, cls],...],...}
- track_id - a set of camera ids/tracker_id to be tracked
{camera\_id\_1, camera\_id\_2, ...}
- dets - a dictionary of camera id and detections in the format
- returns:
- Requires: this method must be called once for each frame even with empty detections (use np.
empty((0, 7))
for frames without detections). - Returns the a dictionary of camera id and tracking results.
{camera\_id\_1: [[x1,y1,x2,y2,score, cls, ID],[x1,y1,x2,y2,score, cls, ID],...], camera\_id\_2: [[x1,y1,x2,y2,score, cls, ID],[x1,y1,x2,y2,score, cls, ID],...],...}$
- Requires: this method must be called once for each frame even with empty detections (use np.
- arguments:
Below is the gist of how to instantiate and update the tracker. Please check the tracker.py for more details.
from tracker import Tracker
# Create an instance of tracker
tracker = Tracker(tracker_type = 'sort')
# get detections
...
# update SORT
track_bbs_conf_cls_ids = tracker(detections)
# track_bbs_conf_cls_ids is a np array where each row contains a valid bounding box, score, class and track_id (last column)
...