# visionml/pytracking architecture

> Architecture diagram of the GitHub repository visionml/pytracking, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/visionml/pytracking
- Repository: https://github.com/visionml/pytracking

## Overview

1. **Overall shape**
   - This is a two-part PyTorch codebase:
     - **`ltr/`**: offline training framework for learning tracking/video segmentation models.
     - **`pytracking/`**: runtime trackers, evaluation, analysis, and demo entry points.
   - The repo is centered on visual object tracking, with some video object segmentation and multi-object tracking support.

2. **Main architectural boundary: training vs inference**
   - `ltr` builds and trains model components from datasets and losses.
   - `pytracking` consumes trained checkpoints and runs trackers on videos, benchmarks, webcams, or VOT-style protocols.
   - The README’s model zoo links these two halves: models are trained in `ltr` and then used by tracker implementations in `pytracking`.

3. **Training pipeline in `ltr/`**
   - `ltr/run_training.py` is the top-level training entry point.
   - The training flow is: dataset sampling/processing → model/actor forward pass → loss computation → trainer loop.
   - `ltr/trainers/` contains the generic training loop, while `ltr/actors/` wraps a model into a training objective for specific tasks such as tracking, segmentation, or bounding-box regression.

4. **Data layer in `ltr/`**
   - `ltr/dataset/` provides dataset adapters for common tracking and segmentation sources such as LaSOT, GOT-10k, TrackingNet, YouTube-VOS, COCO, DAVIS, LVIS, and synthetic video variants.
   - `ltr/data/` handles the input pipeline: loaders, samplers, transforms, processing, and bounding-box utilities.
   - `ltr/data_specs/` contains split files and class maps that define dataset partitions and benchmark-specific training/validation subsets.

5. **Model construction in `ltr/`**
   - `ltr/models/` is organized by reusable primitives and task families:
     - **Backbones**: ResNet, MobileNetV3, Swin Transformer, and variants.
     - **Layers**: normalization, activation, filter, transform, distance, and block utilities.
     - **Losses**: target classification, regression, Lovász, segmentation, KL regression, and candidate matching losses.
     - **Task-specific model families**: DiMP, KYS, LWL, RTS, ToMP, TaMOs, target classifier, target candidate matching, and bounding-box regression.
   - `ltr/admin/` provides experiment infrastructure such as environment setup, model loading, multi-GPU support, stats, tensorboard, and model construction.

6. **Training configurations**
   - `ltr/train_settings/` is where concrete experiment recipes live.
   - Each subfolder corresponds to a family such as `dimp`, `kys`, `lwl`, `rts`, `tamos`, `tomp`, `bbreg`, or `keep_track`.
   - These settings define the exact model, training schedule, and data mix used by the training scripts.

7. **Runtime tracking layer in `pytracking/`**
   - `pytracking/run_tracker.py`, `run_video.py`, `run_webcam.py`, and `run_vot.py` are the main execution entry points.
   - `pytracking/tracker/` contains stateful online tracker implementations, one package per tracker family: ATOM, DiMP, ECO, KeepTrack, KYS, LWL, RTS, TaMOs, and ToMP.
   - `pytracking/parameter/` mirrors the training settings and supplies tracker-specific runtime hyperparameters and model paths.

8. **Feature and math utilities in `pytracking/`**
   - `pytracking/features/` implements feature extraction, augmentation, preprocessing, and network wrappers around deep backbones.
   - `pytracking/libs/` contains low-level tracking math: complex-number ops, Fourier tools, optimization, tensor containers, and correlation-filter utilities.
   - This layer is what makes classical and hybrid trackers like ECO possible, and also supports newer deep trackers with shared feature code.

9. **Evaluation and analysis**
   - `pytracking/evaluation/` defines benchmark datasets, running logic, VOT integration, multi-object wrapping, and dataset environment handling.
   - `pytracking/analysis/` provides result extraction, plotting, playback, and VOS-specific analysis utilities.
   - The repository separates evaluation from tracking execution so the same tracker can be run under different benchmark protocols.

10. **External dependencies and special integration points**
   - The project depends on **PyTorch** and uses a conda-based installation flow.
   - `ltr/external/PreciseRoIPooling` is a bundled third-party module used by some model components.
   - VOT integration is explicitly supported via `pytracking/VOT/`, and the README mentions benchmark-specific result packaging and dataset attribute specs.

11. **How data flows end to end**
   - Training: benchmark datasets and split files feed samplers and processors; models are trained through actors and trainers; checkpoints are saved for later use.
   - Inference: a runtime script loads a tracker parameter set, instantiates the tracker, loads the trained network, and processes frames sequentially while maintaining tracker state.
   - Evaluation: the same tracker is run against benchmark dataset wrappers, and outputs are analyzed or packaged into benchmark-specific formats.

12. **What to diagram as the key subsystems**
   - At minimum, show these boundaries:
     - **Training framework (`ltr`)**
     - **Runtime/evaluation framework (`pytracking`)**
     - **Dataset/adaptation layer**
     - **Model family layer**
     - **Tracker runtime layer**
     - **Evaluation/analysis tooling**
   - The main dependency direction is from datasets/configs into training, then from trained checkpoints into runtime trackers and benchmark evaluation.

Main entry points: [`pytracking/tracker`](https://github.com/visionml/pytracking/tree/master/pytracking/tracker) (Trackers), [`ltr/models`](https://github.com/visionml/pytracking/tree/master/ltr/models) (Models), [`ltr/train_settings`](https://github.com/visionml/pytracking/tree/master/ltr/train_settings) (Recipes), [`pytracking/evaluation`](https://github.com/visionml/pytracking/tree/master/pytracking/evaluation) (Evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ltr["LTR training"]
  node_ltr_run_training["Train entry<br/>entrypoint<br/>[run_training.py]"]
  node_ltr_data["Data pipeline<br/>input pipeline"]
  node_ltr_dataset["Datasets<br/>dataset adapters"]
  node_ltr_data_specs["Split specs<br/>splits and maps"]
  node_ltr_actors["Actors<br/>training objectives"]
  node_ltr_trainers["Trainers<br/>loop engine"]
  node_ltr_admin["Admin<br/>infra"]
  node_ltr_models["Models<br/>model families"]
  node_ltr_train_settings["Recipes<br/>experiment configs"]
end

subgraph group_pytracking["PyTracking runtime"]
  node_py_run_tracker["Track entry<br/>entrypoint<br/>[run_tracker.py]"]
  node_py_run_video["Video entry<br/>entrypoint<br/>[run_video.py]"]
  node_py_run_webcam["Webcam entry<br/>entrypoint<br/>[run_webcam.py]"]
  node_py_run_vot["VOT entry<br/>entrypoint<br/>[run_vot.py]"]
  node_py_tracker["Trackers"]
  node_py_parameters["Parameters<br/>runtime config"]
  node_py_features["Features<br/>feature stack"]
  node_py_libs["Math libs<br/>tracking math"]
  node_py_evaluation["Evaluation<br/>benchmarks"]
  node_py_analysis["Analysis<br/>results tooling"]
end

subgraph group_integration["Cross-cutting"]
  node_py_vot["VOT bridge<br/>integration"]
  node_ltr_external["External ROI<br/>third-party module"]
end

node_ltr_data_specs -->|"partitions"| node_ltr_dataset
node_ltr_dataset -->|"samples"| node_ltr_data
node_ltr_data -->|"batches"| node_ltr_actors
node_ltr_models -->|"forward/loss"| node_ltr_actors
node_ltr_actors -->|"objective"| node_ltr_trainers
node_ltr_train_settings -->|"configure"| node_ltr_run_training
node_ltr_admin -->|"infra"| node_ltr_run_training
node_ltr_run_training -->|"launch"| node_ltr_trainers
node_ltr_models -->|"selects"| node_ltr_train_settings
node_ltr_external -.->|"kernel"| node_ltr_models
node_ltr_train_settings -.->|"mirrors"| node_py_parameters
node_ltr_models -->|"checkpoints"| node_py_tracker
node_py_parameters -->|"runtime config"| node_py_tracker
node_py_tracker -->|"extracts"| node_py_features
node_py_tracker -->|"math core"| node_py_libs
node_py_run_tracker -->|"launch"| node_py_tracker
node_py_run_video -->|"launch"| node_py_tracker
node_py_run_webcam -->|"launch"| node_py_tracker
node_py_run_vot -->|"launch"| node_py_tracker
node_py_tracker -->|"benchmark"| node_py_evaluation
node_py_evaluation -->|"results"| node_py_analysis
node_py_evaluation -.->|"protocol"| node_py_vot

click node_ltr_run_training "https://github.com/visionml/pytracking/blob/master/ltr/run_training.py"
click node_ltr_data "https://github.com/visionml/pytracking/tree/master/ltr/data"
click node_ltr_dataset "https://github.com/visionml/pytracking/tree/master/ltr/dataset"
click node_ltr_data_specs "https://github.com/visionml/pytracking/tree/master/ltr/data_specs"
click node_ltr_actors "https://github.com/visionml/pytracking/tree/master/ltr/actors"
click node_ltr_trainers "https://github.com/visionml/pytracking/tree/master/ltr/trainers"
click node_ltr_admin "https://github.com/visionml/pytracking/tree/master/ltr/admin"
click node_ltr_models "https://github.com/visionml/pytracking/tree/master/ltr/models"
click node_ltr_train_settings "https://github.com/visionml/pytracking/tree/master/ltr/train_settings"
click node_py_run_tracker "https://github.com/visionml/pytracking/blob/master/pytracking/run_tracker.py"
click node_py_run_video "https://github.com/visionml/pytracking/blob/master/pytracking/run_video.py"
click node_py_run_webcam "https://github.com/visionml/pytracking/blob/master/pytracking/run_webcam.py"
click node_py_run_vot "https://github.com/visionml/pytracking/blob/master/pytracking/run_vot.py"
click node_py_tracker "https://github.com/visionml/pytracking/tree/master/pytracking/tracker"
click node_py_parameters "https://github.com/visionml/pytracking/tree/master/pytracking/parameter"
click node_py_features "https://github.com/visionml/pytracking/tree/master/pytracking/features"
click node_py_libs "https://github.com/visionml/pytracking/tree/master/pytracking/libs"
click node_py_evaluation "https://github.com/visionml/pytracking/tree/master/pytracking/evaluation"
click node_py_analysis "https://github.com/visionml/pytracking/tree/master/pytracking/analysis"
click node_py_vot "https://github.com/visionml/pytracking/tree/master/pytracking/VOT"
click node_ltr_external "https://github.com/visionml/pytracking/tree/master/ltr/external/PreciseRoIPooling"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ltr_run_training,node_ltr_data,node_ltr_dataset,node_ltr_data_specs,node_ltr_actors,node_ltr_trainers,node_ltr_admin,node_ltr_models,node_ltr_train_settings toneBlue
class node_py_run_tracker,node_py_run_video,node_py_run_webcam,node_py_run_vot,node_py_tracker,node_py_parameters,node_py_features,node_py_libs,node_py_evaluation,node_py_analysis toneAmber
class node_py_vot,node_ltr_external toneMint
```

## Components

### LTR training

Offline model training, data, and experiment setup.

- [Train entry](https://github.com/visionml/pytracking/blob/master/ltr/run_training.py): entrypoint · Top-level training script. · `ltr/run_training.py`
- [Data pipeline](https://github.com/visionml/pytracking/tree/master/ltr/data): input pipeline · Sampling, transforms, processing, and loader utilities. · `ltr/data`
- [Datasets](https://github.com/visionml/pytracking/tree/master/ltr/dataset): dataset adapters · Adapters for tracking, segmentation, and synthetic video datasets. · `ltr/dataset`
- [Split specs](https://github.com/visionml/pytracking/tree/master/ltr/data_specs): splits and maps · Dataset split files and class maps used by training recipes. · `ltr/data_specs`
- [Actors](https://github.com/visionml/pytracking/tree/master/ltr/actors): training objectives · Wrap models into task-specific training objectives. · `ltr/actors`
- [Trainers](https://github.com/visionml/pytracking/tree/master/ltr/trainers): loop engine · Generic training loop and optimization orchestration. · `ltr/trainers`
- [Admin](https://github.com/visionml/pytracking/tree/master/ltr/admin): infra · Experiment setup, loading, stats, tensorboard, and multi-GPU support. · `ltr/admin`
- [Models](https://github.com/visionml/pytracking/tree/master/ltr/models): model families · Backbones, layers, losses, and tracking model families. · `ltr/models`
- [Recipes](https://github.com/visionml/pytracking/tree/master/ltr/train_settings): experiment configs · Concrete experiment definitions and schedules per tracker family. · `ltr/train_settings`

### PyTracking runtime

Tracker execution, evaluation, analysis, and runtime parameters.

- [Track entry](https://github.com/visionml/pytracking/blob/master/pytracking/run_tracker.py): entrypoint · Main tracker execution script. · `pytracking/run_tracker.py`
- [Video entry](https://github.com/visionml/pytracking/blob/master/pytracking/run_video.py): entrypoint · Video demo and offline playback runner. · `pytracking/run_video.py`
- [Webcam entry](https://github.com/visionml/pytracking/blob/master/pytracking/run_webcam.py): entrypoint · Live webcam tracking runner. · `pytracking/run_webcam.py`
- [VOT entry](https://github.com/visionml/pytracking/blob/master/pytracking/run_vot.py): entrypoint · VOT benchmark execution entry point. · `pytracking/run_vot.py`
- [Trackers](https://github.com/visionml/pytracking/tree/master/pytracking/tracker): online trackers · Stateful tracker implementations for major model families. · `pytracking/tracker`
- [Parameters](https://github.com/visionml/pytracking/tree/master/pytracking/parameter): runtime config · Tracker hyperparameters and model-path settings mirrored from training recipes. · `pytracking/parameter`
- [Features](https://github.com/visionml/pytracking/tree/master/pytracking/features): feature stack · Feature extraction, preprocessing, augmentation, and network wrappers. · `pytracking/features`
- [Math libs](https://github.com/visionml/pytracking/tree/master/pytracking/libs): tracking math · Fourier, optimization, tensor containers, and DCF utilities. · `pytracking/libs`
- [Evaluation](https://github.com/visionml/pytracking/tree/master/pytracking/evaluation): benchmarks · Dataset wrappers, running logic, multi-object support, and VOT integration. · `pytracking/evaluation`
- [Analysis](https://github.com/visionml/pytracking/tree/master/pytracking/analysis): results tooling · Result extraction, plotting, playback, and VOS analysis. · `pytracking/analysis`

### Cross-cutting

Shared training-to-inference integration points and bundled externals.

- [VOT bridge](https://github.com/visionml/pytracking/tree/master/pytracking/VOT): integration · Bundled VOT tracker integration scripts and config. · `pytracking/VOT`
- [External ROI](https://github.com/visionml/pytracking/tree/master/ltr/external/PreciseRoIPooling): third-party module · Bundled PreciseRoIPooling dependency used by model components. · `ltr/external/PreciseRoIPooling`

## Connections

- Split specs → Datasets: partitions · Split files and class maps guide dataset adapters.
- Datasets → Data pipeline: samples · Dataset adapters feed the data pipeline.
- Data pipeline → Actors: batches · Processed training batches are consumed by actors.
- Models → Actors: forward/loss · Models are wrapped by task-specific actors.
- Actors → Trainers: objective · Actors provide training objectives to the trainer loop.
- Recipes → Train entry: configure · Experiment recipes drive the training entry point.
- Admin → Train entry: infra · Training uses environment, loading, stats, and multi-GPU support.
- Train entry → Trainers: launch · The main script starts the training loop.
- Models → Recipes: selects · Recipes choose specific model families and variants.
- External ROI → Models: kernel · Bundled third-party ops support some model components.
- Recipes → Parameters: mirrors · Training recipes correspond to runtime parameter sets.
- Models → Trackers: checkpoints · Trained models are loaded by runtime trackers.
- Parameters → Trackers: runtime config · Tracker parameters define runtime behavior and model paths.
- Trackers → Features: extracts · Trackers use feature extraction and preprocessing stacks.
- Trackers → Math libs: math core · Classical and hybrid trackers rely on low-level tracking math.
- Track entry → Trackers: launch · Main tracker entry point instantiates trackers.
- Video entry → Trackers: launch · Video runner executes trackers on frame sequences.
- Webcam entry → Trackers: launch · Webcam runner executes trackers on live input.
- VOT entry → Trackers: launch · VOT entry point runs trackers under benchmark protocol.
- Trackers → Evaluation: benchmark · Trackers are evaluated through benchmark dataset wrappers.
- Evaluation → Analysis: results · Evaluation outputs feed result analysis and plotting.
- Evaluation → VOT bridge: protocol · Evaluation integrates VOT packaging and execution.
