Skip to main content

A more realtime adaptation of Deep SORT

Project description

Deep SORT

Introduction

A more realtime adaptation of Deep SORT.

Adapted from the official repo of Simple Online and Realtime Tracking with a Deep Association Metric (Deep SORT): https://github.com/nwojke/deep_sort

See their paper for more technical information.

Dependencies

  • Python3
  • NumPy
  • Scipy
  • cv2
  • (optional) Embedder requires Pytorch & Torchvision or Tensorflow

Install

  • via PyPI through pip3 install deep-sort-realtime
  • or clone this repo, install deep_sort_realtime as a python package using pip or as an editable package if you like (-e flag)
cd deep_sort_realtime && pip3 install .
  • or, download .whl file in this repo's releases

Run

Example usage:

from deep_sort_realtime.deepsort_tracker import DeepSort
tracker = DeepSort(max_age=30, nn_budget=70, override_track_class=None)
bbs = object_detector.detect(frame)
tracks = trackers.update_tracks(bbs, frame=frame)
for track in tracks:
   track_id = track.track_id
   ltrb = track.to_ltrb()
  • To add project-specific logic into the Track class, you can make a subclass (of Track) and pass it in (override_track_class argument) when instantiating DeepSort.

Getting bounding box of original detection

The original Track.to_* methods for retrieving bounding box values returns only the Kalman predicted values. However, in some applications, it is better to return the bb values of the original detections the track was associated to at the current round.

Here we added an orig argument to all the Track.to_* methods. If orig is flagged as True and this track is associated to a detection this update round, then the bounding box values returned by the method will be that associated to the original detection. Otherwise, it will still return the Kalman predicted values.

Storing supplementary info of original detection

Supplementary info can be pass into the track from the detection. Detection class now has an others argument to store this and pass it to the associate track during update. Can be retrieved through Track.get_det_supplementary method.

Polygon support

Other than horizontal bounding boxes, detections can now be given as polygons. We do not track polygon points per se, but merely convert the polygon to its bounding rectangle for tracking. That said, if embedding is enabled, the embedder works on the crop around the bounding rectangle, with area not covered by the polygon masked away.

When instantiating a DeepSort object (as in deepsort_tracker.py), polygon argument should be flagged to True. See DeepSort.update_tracks docstring for details on the polygon format. In polygon mode, the original polygon coordinates are passed to the associated track through the supplementary info.

Differences from original repo

  • Remove "academic style" offline processing style and implemented it to take in real-time detections and output accordingly.
  • Provides both options of using an in-built appearance feature embedder or to provide embeddings during update
  • Added (pytorch) mobilenetv2 as embedder (torch ftw).
  • Due to special request, tensorflow embedder is available now too (very unwillingly included).
  • Skip nms completely in preprocessing detections if nms_max_overlap == 1.0 (which is the default), in the original repo, nms will still be done even if threshold is set to 1.0 (probably because it was not optimised for speed).
  • Now able to override the Track class with a custom Track class (that inherits from Track class) for custom track logic
  • Now takes in a "clock" object (see utils/clock.py for example), which provides date for track naming and facilities track id reset every day, preventing overflow and overly large track ids when system runs for a long time.
  • Now supports polygon detections. We do not track polygon points per se, but merely convert the polygon to its bounding rectangle for tracking. That said, if embedding is enabled, the embedder works on the crop around the bounding rectangle, with area not covered by the polygon masked away. Read more here.
  • The original Track.to_* methods for retrieving bounding box values returns only the Kalman predicted values. In some applications, it is better to return the bb values of the original detections the track was associated to at the current round. Added a orig argument which can be flagged True to get that. Read more here.
  • Added get_det_supplementary method to Track class, in order to pass detection related info through the track. Read more here.
  • Other minor adjustments.

[From original repo] Highlevel overview of source files in deep_sort

In package deep_sort is the main tracking code:

  • detection.py: Detection base class.
  • kalman_filter.py: A Kalman filter implementation and concrete parametrization for image space filtering.
  • linear_assignment.py: This module contains code for min cost matching and the matching cascade.
  • iou_matching.py: This module contains the IOU matching metric.
  • nn_matching.py: A module for a nearest neighbor matching metric.
  • track.py: The track class contains single-target track data such as Kalman state, number of hits, misses, hit streak, associated feature vectors, etc.
  • tracker.py: This is the multi-target tracker class.

Test

python3 -m unittest

Appearance Embedding Network

Pytorch Embedder (default)

Default embedder is a pytorch MobilenetV2 (trained on Imagenet).

For convenience (I know it's not exactly best practice) & since the weights file is quite small, it is pushed in this github repo and will be installed to your Python environment when you install deep_sort_realtime.

Tensorflow Embedder

Available now at deep_sort_realtime/embedder/embedder_tf.py, as alternative to (the default) pytorch embedder. Tested on Tensorflow 2.3.1. You need to make your own code change to use it.

The tf MobilenetV2 weights (pretrained on imagenet) are not available in this github repo (unlike the torch one). Download from this link or run download script. You may drop it into deep_sort_realtime/embedder/weights/ before pip installing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deep-sort-realtime-1.0.tar.gz (21.6 MB view details)

Uploaded Source

Built Distribution

deep_sort_realtime-1.0-py3-none-any.whl (21.6 MB view details)

Uploaded Python 3

File details

Details for the file deep-sort-realtime-1.0.tar.gz.

File metadata

  • Download URL: deep-sort-realtime-1.0.tar.gz
  • Upload date:
  • Size: 21.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.9

File hashes

Hashes for deep-sort-realtime-1.0.tar.gz
Algorithm Hash digest
SHA256 037c2409a4dbd9a34374a0c11d5ec6a846caad5f9b7064928f25ff4e4238ebdd
MD5 b9d9d70dcfede8524ff2c0993b8334ab
BLAKE2b-256 8985caa821d3ffe3dc01f37702bfdc04333da859c1d899f3af34f1a8b70fd76f

See more details on using hashes here.

File details

Details for the file deep_sort_realtime-1.0-py3-none-any.whl.

File metadata

  • Download URL: deep_sort_realtime-1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.9

File hashes

Hashes for deep_sort_realtime-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7969420135d70c100e72761827bedc2daefa9eb2a898e8e2c077262955e7a7e5
MD5 d7c8ac8e8576bf228ba25a5af557a279
BLAKE2b-256 9c4a136b980ec8e2dafcbf2f01cf03a7bb41aa5797597912b5614d44359f755d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page