UrbanFlow / backend /tracker_config.py
Subh775's picture
heavy add-ons: 13+ features implemented
d9ebe88
"""
Custom ByteTrack configuration optimized for Indian traffic conditions.
Tuning rationale (vs Ultralytics defaults):
- Lower thresholds: Indian roads have heavy occlusion (autos behind buses)
- Higher track_buffer: Vehicles disappear behind large vehicles for longer
- Looser match_thresh: Apparent shape changes during partial occlusion
Reference: https://docs.ultralytics.com/modes/track/
"""
import os
import tempfile
_YAML_CONTENT = """# UrbanFlow — ByteTrack config for Indian heterogeneous traffic
# Base: https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/trackers/bytetrack.yaml
tracker_type: bytetrack
track_high_thresh: 0.20
track_low_thresh: 0.08
new_track_thresh: 0.20
track_buffer: 45
match_thresh: 0.75
fuse_score: true
"""
_CONFIG_PATH = os.path.join(tempfile.gettempdir(), "urbanflow_bytetrack.yaml")
def get_tracker_path():
"""Write custom YAML once and return its path."""
if not os.path.exists(_CONFIG_PATH):
with open(_CONFIG_PATH, "w") as f:
f.write(_YAML_CONTENT)
print(f"[tracker] Custom ByteTrack config written: {_CONFIG_PATH}")
return _CONFIG_PATH