Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Xander44-4/traffic_reducer/llms.txt

Use this file to discover all available pages before exploring further.

Traffic Reducer ships with support for multiple YOLOv8 weight files and automatically selects the best available one at startup — no manual configuration required for the common case. The selection logic in app.py checks for weight files in the project root directory and falls back gracefully if none are found locally.

Auto-selection logic

At startup, app.py resolves the project root and checks for weight files in the following priority order:
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
_yolov8m_local = os.path.join(PROJECT_ROOT, "yolov8m.pt")
_yolov8s_local = os.path.join(PROJECT_ROOT, "yolov8s.pt")
if os.path.exists(_yolov8m_local):
    YOLO_MODEL_PATH = _yolov8m_local
elif os.path.exists(_yolov8s_local):
    YOLO_MODEL_PATH = _yolov8s_local
else:
    YOLO_MODEL_PATH = "yolov8m.pt"  # auto-download fallback
The logic checks for yolov8m.pt first, then yolov8s.pt. If neither is found locally, Ultralytics will attempt to download yolov8m.pt from its model hub the first time the application starts. Ensure the machine has internet access on first run if no local weights are present.

Model comparison

Weight fileParametersBest for
yolov8s.pt~11MBalanced speed and accuracy
yolov8m.pt~26MBest accuracy; GPU recommended

Forcing a specific model

To pin the system to a particular weight file, use one of these approaches:
  • Remove unwanted files — delete or rename the .pt files you do not want in the project root. The auto-selection logic will fall through to the next available file.
  • Set YOLO_MODEL_PATH directly — edit app.py and hard-code the path before the TrafficCamera constructor is called:
# In app.py — bypass auto-selection entirely
YOLO_MODEL_PATH = "/opt/traffic_reducer/yolov8s.pt"

Inference parameters

TrafficCamera exposes four constructor parameters that control how YOLOv8 filters detections. These are set once at construction time and apply to every frame throughout the session.
ParameterDefaultDescription
conf0.25Minimum confidence score to accept a detection
iou0.5IoU threshold for non-maximum suppression
max_det300Maximum number of detections per frame
local_speed1.0Playback speed multiplier for local video mode
The inference image size is hardcoded to imgsz=640 inside _run_yolo() and is not a constructor parameter. It cannot be changed without editing video_processor.py directly. Non-maximum suppression is run class-agnostically (agnostic_nms=True) so that vehicles near zone boundaries are not double-counted across overlapping detections.
To override the default detection thresholds, pass them as keyword arguments when TrafficCamera is instantiated in app.py:
camera = TrafficCamera(
    YOUTUBE_URL,
    model_path=YOLO_MODEL_PATH,
    conf=0.35,   # stricter confidence — fewer false positives
    iou=0.45,
    max_det=200,
)

Build docs developers (and LLMs) love