Skip to content

Commit

Permalink
Robust association, optimization, and API restructure (#175)
Browse files Browse the repository at this point in the history
* Add robust feature

* Speed up cdist with Numba

* Handle occluded tracks

* Remove clipping in detector

* Fix smooth dist

* Fix cluster distance

* Add assertion for public detector

* Account for negative width or height for area

* Add confirm_hits parameter

* Speed up numpy concat

* Fix ReID

* Normalize cluster feature

* Speed up clustering using cosine dist

* clean up

* Refactor config parameter parsing

* Fix letterbox and add parameter doc

* Use greedy match for ReID and improve remove dup

* Split into multiple lines

* Experiment with match rectification

* Speed up rect and bbox distance helper functions

* Speed up ios and iom

* Deprecate cython-bbox

* Speed up matching and gating

* Speed up rect and fix cdist

* Threshold aspect ratio and more optimizations

* Allow defining model class outside the API

* Add comments

* Speed up matching cascade and sync with tensorrt_demos

* Add doc

* Add visualizer parameters

* Lower fill_val and clean up

* Clean up
  • Loading branch information
GeekAlexis authored Aug 11, 2021
1 parent 9585c70 commit ffc637f
Show file tree
Hide file tree
Showing 25 changed files with 1,718 additions and 799 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ ARG CUPY_NVCC_GENERATE_CODE
RUN if [[ -z ${CUPY_NVCC_GENERATE_CODE} ]]; then \
echo "CUPY_NVCC_GENERATE_CODE not set, building CuPy for all architectures (slower)"; \
fi && \
pip install --no-cache-dir cython && \
if [[ ${TRT_IMAGE_VERSION} == 21.05 ]]; then \
CUPY_NUM_BUILD_JOBS=$(nproc) pip install --no-cache-dir -r <(grep -ivE "tensorflow" requirements.txt); \
else \
Expand Down
19 changes: 10 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

from pathlib import Path
from types import SimpleNamespace
import argparse
import logging
import json
Expand Down Expand Up @@ -39,37 +40,37 @@ def main():

# load config file
with open(args.config) as cfg_file:
config = json.load(cfg_file, cls=ConfigDecoder)
config = json.load(cfg_file, cls=ConfigDecoder, object_hook=lambda d: SimpleNamespace(**d))

stream = fastmot.VideoIO(config.resize_to, args.input_uri, args.output_uri, **vars(config.stream_cfg))

mot = None
log = None
stream = fastmot.VideoIO(config['resize_to'], config['video_io'], args.input_uri, args.output_uri)

if args.mot:
draw = args.gui or args.output_uri is not None
mot = fastmot.MOT(config['resize_to'], config['mot'], draw=draw, verbose=args.verbose)
mot = fastmot.MOT(config.resize_to, **vars(config.mot_cfg), draw=draw)
mot.reset(stream.cap_dt)
if args.log is not None:
Path(args.log).parent.mkdir(parents=True, exist_ok=True)
log = open(args.log, 'w')
if args.gui:
cv2.namedWindow("Video", cv2.WINDOW_AUTOSIZE)
cv2.namedWindow('Video', cv2.WINDOW_AUTOSIZE)

logger.info('Starting video capture...')
stream.start_capture()
try:
with Profiler('app') as prof:
while not args.gui or cv2.getWindowProperty("Video", 0) >= 0:
while not args.gui or cv2.getWindowProperty('Video', 0) >= 0:
frame = stream.read()
if frame is None:
break

if args.mot:
mot.step(frame)
if log is not None:
for track in mot.visible_tracks:
tl = track.tlbr[:2] / config['resize_to'] * stream.resolution
br = track.tlbr[2:] / config['resize_to'] * stream.resolution
for track in mot.visible_tracks():
tl = track.tlbr[:2] / config.resize_to * stream.resolution
br = track.tlbr[2:] / config.resize_to * stream.resolution
w, h = br - tl + 1
log.write(f'{mot.frame_count},{track.trk_id},{tl[0]:.6f},{tl[1]:.6f},'
f'{w:.6f},{h:.6f},-1,-1,-1\n')
Expand Down
57 changes: 34 additions & 23 deletions cfg/mot.json
Original file line number Diff line number Diff line change
@@ -1,78 +1,80 @@
{
"resize_to": [1280, 720],

"video_io": {
"stream_cfg": {
"resolution": [1920, 1080],
"frame_rate": 30,
"buffer_size": 10
},

"mot": {
"mot_cfg": {
"detector_type": "YOLO",
"detector_frame_skip": 5,

"ssd_detector": {
"ssd_detector_cfg": {
"model": "SSDInceptionV2",
"class_ids": [1],
"tile_overlap": 0.25,
"tiling_grid": [4, 2],
"conf_thresh": 0.5,
"max_area": 130000,
"merge_thresh": 0.6
"merge_thresh": 0.6,
"max_area": 120000
},
"yolo_detector": {
"yolo_detector_cfg": {
"model": "YOLOv4",
"class_ids": [1],
"conf_thresh": 0.25,
"nms_thresh": 0.5,
"max_area": 800000,
"nms_thresh": 0.5
"min_aspect_ratio": 1.2
},
"public_detector": {
"sequence": "eval/data/MOT20-03",
"public_detector_cfg": {
"sequence_path": "MOT20/train/MOT20-01",
"conf_thresh": 0.5,
"max_area": 800000
},
"feature_extractor": {
"feature_extractor_cfg": {
"model": "OSNet025",
"batch_size": 16
},

"multi_tracker": {
"tracker_cfg": {
"max_age": 6,
"age_penalty": 2,
"age_weight": 0.1,
"motion_weight": 0.02,
"max_feat_cost": 0.9,
"motion_weight": 0.2,
"max_assoc_cost": 0.8,
"max_reid_cost": 0.6,
"iou_thresh": 0.4,
"duplicate_iou": 0.8,
"duplicate_thresh": 0.8,
"occlusion_thresh": 0.7,
"conf_thresh": 0.5,
"lost_buf_size": 50,
"confirm_hits": 1,
"history_size": 50,

"kalman_filter": {
"kalman_filter_cfg": {
"std_factor_acc": 2.25,
"std_offset_acc": 78.5,
"std_factor_det": [0.08, 0.08],
"std_factor_flow": [0.14, 0.14],
"std_factor_klt": [0.14, 0.14],
"min_std_det": [4.0, 4.0],
"min_std_flow": [5.0, 5.0],
"min_std_klt": [5.0, 5.0],
"init_pos_weight": 5,
"init_vel_weight": 15,
"init_vel_weight": 12,
"vel_coupling": 0.6,
"vel_half_life": 2
},

"flow": {
"flow_cfg": {
"bg_feat_scale_factor": [0.1, 0.1],
"opt_flow_scale_factor": [0.5, 0.5],
"feature_density": 0.005,
"feat_density": 0.005,
"feat_dist_factor": 0.06,
"ransac_max_iter": 500,
"ransac_conf": 0.99,
"max_error": 100,
"inlier_thresh": 4,
"bg_feat_thresh": 10,
"target_feat_params": {
"obj_feat_params": {
"maxCorners": 1000,
"qualityLevel": 0.06,
"blockSize": 3
Expand All @@ -83,6 +85,15 @@
"criteria": [3, 10, 0.03]
}
}
},

"visualizer_cfg": {
"draw_detections": false,
"draw_confidence": false,
"draw_covariance": false,
"draw_klt": false,
"draw_obj_flow": false,
"draw_bg_flow": false
}
}
}
Loading

0 comments on commit ffc637f

Please sign in to comment.