From c947b9ae3bd771c87864111f203c056701ae4b3e Mon Sep 17 00:00:00 2001 From: Alex Bodner Date: Fri, 27 Mar 2026 11:04:30 -0300 Subject: [PATCH 1/2] first version of the notebook --- notebooks/how-to-tune-your-tracker.ipynb | 811 +++++++++++++++++++++++ 1 file changed, 811 insertions(+) create mode 100644 notebooks/how-to-tune-your-tracker.ipynb diff --git a/notebooks/how-to-tune-your-tracker.ipynb b/notebooks/how-to-tune-your-tracker.ipynb new file mode 100644 index 00000000..b98c3227 --- /dev/null +++ b/notebooks/how-to-tune-your-tracker.ipynb @@ -0,0 +1,811 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "ypLoi8Dw-Ya5" + }, + "source": [ + "[![Roboflow Notebooks](https://media.roboflow.com/notebooks/template/bannertest2-2.png?ik-sdk-version=javascript-1.4.3&updatedAt=1672932710194)](https://github.com/roboflow/notebooks)\n", + "\n", + "# How to Tune Parameters to your Tracker\n", + "In this notebook you will download MOT17 dataset, format it for using the Tuner class, and tune the hiperparameters of the tracker.\n", + "Finally evaluate the best parameters found over the evaluation set. " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_2K7Nk_A6nJD" + }, + "source": [ + "## Install Trackers\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "RUaR55za27nz", + "outputId": "a4aea53b-2b96-4b4a-a6b5-5f7f0d6b33bd" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting trackers\n", + " Downloading trackers-2.3.0-py3-none-any.whl.metadata (8.0 kB)\n", + "Requirement already satisfied: numpy>=2.0.2 in /usr/local/lib/python3.12/dist-packages (from trackers) (2.0.2)\n", + "Requirement already satisfied: opencv-python>=4.8.0 in /usr/local/lib/python3.12/dist-packages (from trackers) (4.13.0.92)\n", + "Requirement already satisfied: requests>=2.28.0 in /usr/local/lib/python3.12/dist-packages (from trackers) (2.32.4)\n", + "Requirement already satisfied: rich>=13.0.0 in /usr/local/lib/python3.12/dist-packages (from trackers) (13.9.4)\n", + "Requirement already satisfied: scipy>=1.13.1 in /usr/local/lib/python3.12/dist-packages (from trackers) (1.16.3)\n", + "Collecting supervision>=0.26.1 (from trackers)\n", + " Downloading supervision-0.27.0.post2-py3-none-any.whl.metadata (13 kB)\n", + "Requirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers) (3.4.6)\n", + "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers) (3.11)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers) (2.5.0)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers) (2026.2.25)\n", + "Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.12/dist-packages (from rich>=13.0.0->trackers) (4.0.0)\n", + "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.12/dist-packages (from rich>=13.0.0->trackers) (2.19.2)\n", + "Requirement already satisfied: matplotlib>=3.6.0 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers) (3.10.0)\n", + "Requirement already satisfied: pyyaml>=5.3 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers) (6.0.3)\n", + "Requirement already satisfied: defusedxml>=0.7.1 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers) (0.7.1)\n", + "Requirement already satisfied: pillow>=9.4 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers) (11.3.0)\n", + "Requirement already satisfied: tqdm>=4.62.3 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers) (4.67.3)\n", + "Collecting pyDeprecate<0.6.0,>=0.4.0 (from supervision>=0.26.1->trackers)\n", + " Downloading pydeprecate-0.5.0-py3-none-any.whl.metadata (41 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m41.9/41.9 kB\u001b[0m \u001b[31m2.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.12/dist-packages (from markdown-it-py>=2.2.0->rich>=13.0.0->trackers) (0.1.2)\n", + "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (1.3.3)\n", + "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (0.12.1)\n", + "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (4.62.1)\n", + "Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (1.5.0)\n", + "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (26.0)\n", + "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (3.3.2)\n", + "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (2.9.0.post0)\n", + "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.7->matplotlib>=3.6.0->supervision>=0.26.1->trackers) (1.17.0)\n", + "Downloading trackers-2.3.0-py3-none-any.whl (96 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m96.5/96.5 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading supervision-0.27.0.post2-py3-none-any.whl (217 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m217.4/217.4 kB\u001b[0m \u001b[31m9.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading pydeprecate-0.5.0-py3-none-any.whl (38 kB)\n", + "Installing collected packages: pyDeprecate, supervision, trackers\n", + "Successfully installed pyDeprecate-0.5.0 supervision-0.27.0.post2 trackers-2.3.0\n", + "Requirement already satisfied: trackers[tune] in /usr/local/lib/python3.12/dist-packages (2.3.0)\n", + "\u001b[33mWARNING: trackers 2.3.0 does not provide the extra 'tune'\u001b[0m\u001b[33m\n", + "\u001b[0mRequirement already satisfied: numpy>=2.0.2 in /usr/local/lib/python3.12/dist-packages (from trackers[tune]) (2.0.2)\n", + "Requirement already satisfied: opencv-python>=4.8.0 in /usr/local/lib/python3.12/dist-packages (from trackers[tune]) (4.13.0.92)\n", + "Requirement already satisfied: requests>=2.28.0 in /usr/local/lib/python3.12/dist-packages (from trackers[tune]) (2.32.4)\n", + "Requirement already satisfied: rich>=13.0.0 in /usr/local/lib/python3.12/dist-packages (from trackers[tune]) (13.9.4)\n", + "Requirement already satisfied: scipy>=1.13.1 in /usr/local/lib/python3.12/dist-packages (from trackers[tune]) (1.16.3)\n", + "Requirement already satisfied: supervision>=0.26.1 in /usr/local/lib/python3.12/dist-packages (from trackers[tune]) (0.27.0.post2)\n", + "Requirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers[tune]) (3.4.6)\n", + "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers[tune]) (3.11)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers[tune]) (2.5.0)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers[tune]) (2026.2.25)\n", + "Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.12/dist-packages (from rich>=13.0.0->trackers[tune]) (4.0.0)\n", + "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.12/dist-packages (from rich>=13.0.0->trackers[tune]) (2.19.2)\n", + "Requirement already satisfied: matplotlib>=3.6.0 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers[tune]) (3.10.0)\n", + "Requirement already satisfied: pyyaml>=5.3 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers[tune]) (6.0.3)\n", + "Requirement already satisfied: defusedxml>=0.7.1 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers[tune]) (0.7.1)\n", + "Requirement already satisfied: pillow>=9.4 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers[tune]) (11.3.0)\n", + "Requirement already satisfied: tqdm>=4.62.3 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers[tune]) (4.67.3)\n", + "Requirement already satisfied: pyDeprecate<0.6.0,>=0.4.0 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers[tune]) (0.5.0)\n", + "Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.12/dist-packages (from markdown-it-py>=2.2.0->rich>=13.0.0->trackers[tune]) (0.1.2)\n", + "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (1.3.3)\n", + "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (0.12.1)\n", + "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (4.62.1)\n", + "Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (1.5.0)\n", + "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (26.0)\n", + "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (3.3.2)\n", + "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (2.9.0.post0)\n", + "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.7->matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (1.17.0)\n" + ] + } + ], + "source": [ + "!pip install trackers\n", + "!pip install trackers[tune]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "1rGxvZgN6qSd" + }, + "source": [ + "## Download the dataset\n", + "`Trackers` library provides us with CLI and python code to download the main datasets used in Multi-Object Tracking" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "JxFkLNP06jYy", + "outputId": "2e4f6df1-45c6-4192-b3d9-83e30d036f77" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "UserWarning: The trackers CLI is in beta. APIs may change in future releases.\n", + "usage: trackers download [-h] [--list] [--split SPLIT] [--asset ASSET]\n", + " [-o OUTPUT] [--cache-dir CACHE_DIR]\n", + " [dataset]\n", + "\n", + "Download tracking datasets from the official trackers bucket.\n", + "\n", + "positional arguments:\n", + " dataset Dataset name (e.g. mot17, sportsmot).\n", + "\n", + "options:\n", + " -h, --help show this help message and exit\n", + " --list List available datasets, splits, and asset types.\n", + " --split SPLIT Comma-separated splits to download (e.g.\n", + " train,val,test). If omitted, all available splits are\n", + " downloaded.\n", + " --asset ASSET Comma-separated assets to download:\n", + " annotations,frames,detections. If omitted, all\n", + " available assets are downloaded.\n", + " -o OUTPUT, --output OUTPUT\n", + " Output directory (default: current directory).\n", + " --cache-dir CACHE_DIR\n", + " Cache directory for downloaded ZIPs (default:\n", + " ~/.cache/trackers).\n" + ] + } + ], + "source": [ + "!trackers download --help" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "3P0izUIz6t6b", + "outputId": "68b6ef22-1b23-4122-dca8-ea0829c60cd3" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "UserWarning: The trackers CLI is in beta. APIs may change in future releases.\n", + "[download] mot17:train:detections\n", + "\u001b[2K\u001b[1mmot17-train-public-detections.zip\u001b[0m \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.2/1.2 MB\u001b[0m \u001b[31m31.5 MB/s\u001b[0m\n", + "\u001b[?25h[extract] mot17:train:detections\n", + "[done] mot17:train:detections\n", + "[download] mot17:train:annotations\n", + "\u001b[2K\u001b[1mmot17-train-annotations.zip\u001b[0m \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m694.6/694.6 kB\u001b[0m \u001b[31m33.7 MB/s\u001b[0m\n", + "\u001b[?25h[extract] mot17:train:annotations\n", + "[done] mot17:train:annotations\n", + "[download] mot17:val:detections\n", + "\u001b[2K\u001b[1mmot17-val-public-detections.zip\u001b[0m \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m59.9 MB/s\u001b[0m\n", + "\u001b[?25h[extract] mot17:val:detections\n", + "[done] mot17:val:detections\n", + "[download] mot17:val:annotations\n", + "\u001b[2K\u001b[1mmot17-val-annotations.zip\u001b[0m \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m615.2/615.2 kB\u001b[0m \u001b[31m63.5 MB/s\u001b[0m\n", + "\u001b[?25h[extract] mot17:val:annotations\n", + "[done] mot17:val:annotations\n" + ] + } + ], + "source": [ + "!trackers download mot17 --split train,val --asset detections,annotations" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3P4fq-ZcMVEC" + }, + "source": [ + "## Format dataset for tuning\n", + "\n", + "Tuner class expects a directory for track sand a directory for detections like:\n", + "```text\n", + "data/\n", + "├── gt/\n", + "│ ├── MOT17-02-FRCNN\n", + "│ │ └── gt\n", + "│ │ └── gt.txt\n", + "│ │\n", + "│ ├── MOT17-04-FRCNN\n", + "│ └── ...\n", + "└── detections/\n", + " ├── MOT17-02-FRCNN.txt\n", + " ├── MOT17-04-FRCNN.txt\n", + " └── ...\n", + "```\n", + "So lets format the downloaded dataset to fit this requirement" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "S5Y-6tHn08ZA", + "outputId": "6efe3b52-05f4-47b2-cd9c-c5101a9e5f07" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Copied Det /content/mot17/train/MOT17-02-DPM/det/det.txt to /content/mot17/train/det_flattened/MOT17-02-DPM.txt\n", + "Copied Det /content/mot17/train/MOT17-02-FRCNN/det/det.txt to /content/mot17/train/det_flattened/MOT17-02-FRCNN.txt\n", + "Copied Det /content/mot17/train/MOT17-02-SDP/det/det.txt to /content/mot17/train/det_flattened/MOT17-02-SDP.txt\n", + "Copied Det /content/mot17/train/MOT17-04-DPM/det/det.txt to /content/mot17/train/det_flattened/MOT17-04-DPM.txt\n", + "Copied Det /content/mot17/train/MOT17-04-FRCNN/det/det.txt to /content/mot17/train/det_flattened/MOT17-04-FRCNN.txt\n", + "Copied Det /content/mot17/train/MOT17-04-SDP/det/det.txt to /content/mot17/train/det_flattened/MOT17-04-SDP.txt\n", + "Copied Det /content/mot17/train/MOT17-05-DPM/det/det.txt to /content/mot17/train/det_flattened/MOT17-05-DPM.txt\n", + "Copied Det /content/mot17/train/MOT17-05-FRCNN/det/det.txt to /content/mot17/train/det_flattened/MOT17-05-FRCNN.txt\n", + "Copied Det /content/mot17/train/MOT17-05-SDP/det/det.txt to /content/mot17/train/det_flattened/MOT17-05-SDP.txt\n", + "Copied Det /content/mot17/train/MOT17-09-DPM/det/det.txt to /content/mot17/train/det_flattened/MOT17-09-DPM.txt\n", + "Copied Det /content/mot17/train/MOT17-09-FRCNN/det/det.txt to /content/mot17/train/det_flattened/MOT17-09-FRCNN.txt\n", + "Copied Det /content/mot17/train/MOT17-09-SDP/det/det.txt to /content/mot17/train/det_flattened/MOT17-09-SDP.txt\n", + "Copied Det /content/mot17/train/MOT17-10-DPM/det/det.txt to /content/mot17/train/det_flattened/MOT17-10-DPM.txt\n", + "Copied Det /content/mot17/train/MOT17-10-FRCNN/det/det.txt to /content/mot17/train/det_flattened/MOT17-10-FRCNN.txt\n", + "Copied Det /content/mot17/train/MOT17-10-SDP/det/det.txt to /content/mot17/train/det_flattened/MOT17-10-SDP.txt\n", + "Copied Det /content/mot17/train/MOT17-11-DPM/det/det.txt to /content/mot17/train/det_flattened/MOT17-11-DPM.txt\n", + "Copied Det /content/mot17/train/MOT17-11-FRCNN/det/det.txt to /content/mot17/train/det_flattened/MOT17-11-FRCNN.txt\n", + "Copied Det /content/mot17/train/MOT17-11-SDP/det/det.txt to /content/mot17/train/det_flattened/MOT17-11-SDP.txt\n", + "Copied Det /content/mot17/train/MOT17-13-DPM/det/det.txt to /content/mot17/train/det_flattened/MOT17-13-DPM.txt\n", + "Copied Det /content/mot17/train/MOT17-13-FRCNN/det/det.txt to /content/mot17/train/det_flattened/MOT17-13-FRCNN.txt\n", + "Copied Det /content/mot17/train/MOT17-13-SDP/det/det.txt to /content/mot17/train/det_flattened/MOT17-13-SDP.txt\n", + "Detection files flattening complete.\n", + "det_dir set to: /content/mot17/train/det_flattened\n" + ] + } + ], + "source": [ + "import os\n", + "import shutil\n", + "\n", + "gt_base_dir = \"mot17/\"\n", + "train_split_gt_base = os.path.join(gt_base_dir, \"train\")\n", + "\n", + "# Flatten detection files for 'train' split\n", + "formatted_det_output_dir = os.path.join(train_split_gt_base, \"det_flattened\")\n", + "os.makedirs(formatted_det_output_dir, exist_ok=True)\n", + "\n", + "for seq_folder in sorted(os.listdir(train_split_gt_base)):\n", + " full_seq_path = os.path.join(train_split_gt_base, seq_folder)\n", + " if os.path.isdir(full_seq_path):\n", + " source_det_path = os.path.join(full_seq_path, \"det\", \"det.txt\")\n", + " destination_det_path = os.path.join(formatted_det_output_dir, f\"{seq_folder}.txt\")\n", + " if os.path.exists(source_det_path):\n", + " shutil.copy(source_det_path, destination_det_path)\n", + " print(f\"Copied Det {source_det_path} to {destination_det_path}\")\n", + "\n", + "print(\"Detection files flattening complete.\")\n", + "\n", + "# Define variables for the tuner\n", + "det_dir = formatted_det_output_dir\n", + "print(f\"det_dir set to: {det_dir}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Y_0S2-eRTUvR" + }, + "source": [ + "!! This next cells will be removed once everything is merged" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "lPU3gQojTYx0", + "outputId": "aecf4b00-62ec-46a0-8fb0-735384cc48bd" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found existing installation: trackers 2.3.0\n", + "Uninstalling trackers-2.3.0:\n", + " Would remove:\n", + " /usr/local/bin/trackers\n", + " /usr/local/lib/python3.12/dist-packages/trackers-2.3.0.dist-info/*\n", + " /usr/local/lib/python3.12/dist-packages/trackers/*\n", + "Proceed (Y/n)? y\n", + " Successfully uninstalled trackers-2.3.0\n" + ] + } + ], + "source": [ + "!pip uninstall trackers" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "cDXpIlvn0Ndd", + "outputId": "63d0bc4f-5151-4a5b-dbcd-7f31b687f30d" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", + " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", + " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", + " Building wheel for trackers (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n" + ] + } + ], + "source": [ + "!pip install -q git+https://github.com/omkar-334/trackers.git@feat/cli/tune-stage2 --no-cache" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "bbyoah5BEhM_", + "outputId": "805ddfd9-dedd-4804-a64b-221b246619c9" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting optuna\n", + " Downloading optuna-4.8.0-py3-none-any.whl.metadata (17 kB)\n", + "Requirement already satisfied: alembic>=1.5.0 in /usr/local/lib/python3.12/dist-packages (from optuna) (1.18.4)\n", + "Collecting colorlog (from optuna)\n", + " Downloading colorlog-6.10.1-py3-none-any.whl.metadata (11 kB)\n", + "Requirement already satisfied: numpy in /usr/local/lib/python3.12/dist-packages (from optuna) (2.0.2)\n", + "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.12/dist-packages (from optuna) (26.0)\n", + "Requirement already satisfied: sqlalchemy>=1.4.2 in /usr/local/lib/python3.12/dist-packages (from optuna) (2.0.48)\n", + "Requirement already satisfied: tqdm in /usr/local/lib/python3.12/dist-packages (from optuna) (4.67.3)\n", + "Requirement already satisfied: PyYAML in /usr/local/lib/python3.12/dist-packages (from optuna) (6.0.3)\n", + "Requirement already satisfied: Mako in /usr/local/lib/python3.12/dist-packages (from alembic>=1.5.0->optuna) (1.3.10)\n", + "Requirement already satisfied: typing-extensions>=4.12 in /usr/local/lib/python3.12/dist-packages (from alembic>=1.5.0->optuna) (4.15.0)\n", + "Requirement already satisfied: greenlet>=1 in /usr/local/lib/python3.12/dist-packages (from sqlalchemy>=1.4.2->optuna) (3.3.2)\n", + "Requirement already satisfied: MarkupSafe>=0.9.2 in /usr/local/lib/python3.12/dist-packages (from Mako->alembic>=1.5.0->optuna) (3.0.3)\n", + "Downloading optuna-4.8.0-py3-none-any.whl (419 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m419.5/419.5 kB\u001b[0m \u001b[31m6.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading colorlog-6.10.1-py3-none-any.whl (11 kB)\n", + "Installing collected packages: colorlog, optuna\n", + "Successfully installed colorlog-6.10.1 optuna-4.8.0\n" + ] + } + ], + "source": [ + "!pip install optuna" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "spGTJnJSMZTa" + }, + "source": [ + "## Tune your favorite tracker" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "o5CcrFiM3Rwo" + }, + "outputs": [], + "source": [ + "from trackers.tune import Tuner" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "L9tJrZNpWKoE" + }, + "source": [ + "Here we define the tuner, we select:\n", + " - The `SORT` tracker.\n", + " - `gt_dir`: path to ground truth tracks.\n", + " - `det_dir`: path to detections over which the tracker will act.\n", + " - `objective`: objective metric to maximize.\n", + " - `metrics`: list of all the metrics we want to keep a track of.\n", + " - `n_trials`: number of combinations of hyperparameters to try. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "dWU-NCiC3aEm" + }, + "outputs": [], + "source": [ + "gt_dir = 'mot17/train'\n", + "\n", + "tuner = Tuner(\"sort\", gt_dir, det_dir,\n", + " objective = \"HOTA\",\n", + " metrics=[\"HOTA\"],\n", + " n_trials = 15)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "N0BEROuxGWTS" + }, + "source": [ + "### Run the parameter tuning\n", + "This will take a while: the tuner is trying 15 different combinations of parameters, finding by itself which changes to make to the parameters in order to maximize our objetive metric" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "2D-bmVbK3hTE", + "outputId": "a242dc5d-9351-44ce-fb04-ef7b83931f90" + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "[I 2026-03-27 13:37:17,698] A new study created in memory with name: trackers-tune-sort\n", + "[I 2026-03-27 13:37:28,929] Trial 0 finished with value: 0.13256008568177796 and parameters: {'lost_track_buffer': 39, 'track_activation_threshold': 0.2377381638424672, 'minimum_consecutive_frames': 3, 'minimum_iou_threshold': 0.2845933698271799}. Best is trial 0 with value: 0.13256008568177796.\n", + "[I 2026-03-27 13:37:40,198] Trial 1 finished with value: 0.13523735123132224 and parameters: {'lost_track_buffer': 56, 'track_activation_threshold': 0.6296591435085503, 'minimum_consecutive_frames': 2, 'minimum_iou_threshold': 0.0548526844745505}. Best is trial 1 with value: 0.13523735123132224.\n", + "[I 2026-03-27 13:37:52,544] Trial 2 finished with value: 0.13291667591600373 and parameters: {'lost_track_buffer': 80, 'track_activation_threshold': 0.8083421544621436, 'minimum_consecutive_frames': 2, 'minimum_iou_threshold': 0.4882273002180623}. Best is trial 1 with value: 0.13523735123132224.\n", + "[I 2026-03-27 13:38:04,336] Trial 3 finished with value: 0.13272899554683423 and parameters: {'lost_track_buffer': 46, 'track_activation_threshold': 0.8774424270625114, 'minimum_consecutive_frames': 1, 'minimum_iou_threshold': 0.15974850961089335}. Best is trial 1 with value: 0.13523735123132224.\n", + "[I 2026-03-27 13:38:15,805] Trial 4 finished with value: 0.13262955883945873 and parameters: {'lost_track_buffer': 51, 'track_activation_threshold': 0.6341772853153977, 'minimum_consecutive_frames': 3, 'minimum_iou_threshold': 0.5131879737664423}. Best is trial 1 with value: 0.13523735123132224.\n", + "[I 2026-03-27 13:38:26,807] Trial 5 finished with value: 0.1325532818864949 and parameters: {'lost_track_buffer': 59, 'track_activation_threshold': 0.4675618830556336, 'minimum_consecutive_frames': 3, 'minimum_iou_threshold': 0.40079834943408765}. Best is trial 1 with value: 0.13523735123132224.\n", + "[I 2026-03-27 13:38:38,569] Trial 6 finished with value: 0.1330599138257475 and parameters: {'lost_track_buffer': 37, 'track_activation_threshold': 0.6627787421466715, 'minimum_consecutive_frames': 1, 'minimum_iou_threshold': 0.15394319802475565}. Best is trial 1 with value: 0.13523735123132224.\n", + "[I 2026-03-27 13:38:49,176] Trial 7 finished with value: 0.13294477555127504 and parameters: {'lost_track_buffer': 24, 'track_activation_threshold': 0.87607447815685, 'minimum_consecutive_frames': 3, 'minimum_iou_threshold': 0.5984455460515848}. Best is trial 1 with value: 0.13523735123132224.\n", + "[I 2026-03-27 13:39:00,035] Trial 8 finished with value: 0.13269523841102507 and parameters: {'lost_track_buffer': 28, 'track_activation_threshold': 0.577308324930741, 'minimum_consecutive_frames': 1, 'minimum_iou_threshold': 0.4196943720248147}. Best is trial 1 with value: 0.13523735123132224.\n", + "[I 2026-03-27 13:39:11,350] Trial 9 finished with value: 0.13298506636090984 and parameters: {'lost_track_buffer': 34, 'track_activation_threshold': 0.8247335575354222, 'minimum_consecutive_frames': 1, 'minimum_iou_threshold': 0.6117129046986972}. Best is trial 1 with value: 0.13523735123132224.\n", + "[I 2026-03-27 13:39:22,449] Trial 10 finished with value: 0.13527991637020112 and parameters: {'lost_track_buffer': 69, 'track_activation_threshold': 0.3485735415165917, 'minimum_consecutive_frames': 4, 'minimum_iou_threshold': 0.06322898044739839}. Best is trial 10 with value: 0.13527991637020112.\n", + "[I 2026-03-27 13:39:33,398] Trial 11 finished with value: 0.13516002378562741 and parameters: {'lost_track_buffer': 71, 'track_activation_threshold': 0.33745248273351086, 'minimum_consecutive_frames': 4, 'minimum_iou_threshold': 0.05030950534487981}. Best is trial 10 with value: 0.13527991637020112.\n", + "[I 2026-03-27 13:39:43,670] Trial 12 finished with value: 0.1350849259561734 and parameters: {'lost_track_buffer': 89, 'track_activation_threshold': 0.40714848540002124, 'minimum_consecutive_frames': 4, 'minimum_iou_threshold': 0.05793678852593959}. Best is trial 10 with value: 0.13527991637020112.\n", + "[I 2026-03-27 13:39:55,265] Trial 13 finished with value: 0.1326734600356485 and parameters: {'lost_track_buffer': 65, 'track_activation_threshold': 0.1719562980770182, 'minimum_consecutive_frames': 2, 'minimum_iou_threshold': 0.25038235146905297}. Best is trial 10 with value: 0.13527991637020112.\n", + "[I 2026-03-27 13:40:06,991] Trial 14 finished with value: 0.13275106387541644 and parameters: {'lost_track_buffer': 75, 'track_activation_threshold': 0.3047900177047508, 'minimum_consecutive_frames': 2, 'minimum_iou_threshold': 0.1504008582619463}. Best is trial 10 with value: 0.13527991637020112.\n" + ] + } + ], + "source": [ + "best_params = tuner.run()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DW-tGL-rGssv" + }, + "source": [ + "and the best parameters are ..." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "T1XEWLa8GyUU", + "outputId": "ef5a91ad-bb0f-4a35-a63e-4c542098c89a" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'lost_track_buffer': 69, 'track_activation_threshold': 0.3485735415165917, 'minimum_consecutive_frames': 4, 'minimum_iou_threshold': 0.06322898044739839}\n" + ] + } + ], + "source": [ + "print(best_params)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "eLtPSxZPGw4a" + }, + "source": [ + "## Evaluate over the other set" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "1zU8X864f_6s" + }, + "source": [ + "First we will import some utilities to evaluate." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "id": "GTqhCAb2fpKw" + }, + "outputs": [], + "source": [ + "from trackers.tune.tuner import _run_tracker_on_detections\n", + "from trackers.eval.evaluate import evaluate_mot_sequences\n", + "from trackers import SORTTracker\n", + "from pathlib import Path\n", + "import tempfile" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "tkhQMHa9d2UO" + }, + "source": [ + "We will now flatten the validation detections to: `/content/mot17/val/det_flattened`\n" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "cDDK2VMcXCW4", + "outputId": "952c77f9-f213-4349-dc75-bf1a63199014" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Copied Det /content/mot17/val/MOT17-02-DPM/det/det.txt to /content/mot17/val/det_flattened/MOT17-02-DPM.txt\n", + "Copied Det /content/mot17/val/MOT17-02-FRCNN/det/det.txt to /content/mot17/val/det_flattened/MOT17-02-FRCNN.txt\n", + "Copied Det /content/mot17/val/MOT17-02-SDP/det/det.txt to /content/mot17/val/det_flattened/MOT17-02-SDP.txt\n", + "Copied Det /content/mot17/val/MOT17-04-DPM/det/det.txt to /content/mot17/val/det_flattened/MOT17-04-DPM.txt\n", + "Copied Det /content/mot17/val/MOT17-04-FRCNN/det/det.txt to /content/mot17/val/det_flattened/MOT17-04-FRCNN.txt\n", + "Copied Det /content/mot17/val/MOT17-04-SDP/det/det.txt to /content/mot17/val/det_flattened/MOT17-04-SDP.txt\n", + "Copied Det /content/mot17/val/MOT17-05-DPM/det/det.txt to /content/mot17/val/det_flattened/MOT17-05-DPM.txt\n", + "Copied Det /content/mot17/val/MOT17-05-FRCNN/det/det.txt to /content/mot17/val/det_flattened/MOT17-05-FRCNN.txt\n", + "Copied Det /content/mot17/val/MOT17-05-SDP/det/det.txt to /content/mot17/val/det_flattened/MOT17-05-SDP.txt\n", + "Copied Det /content/mot17/val/MOT17-09-DPM/det/det.txt to /content/mot17/val/det_flattened/MOT17-09-DPM.txt\n", + "Copied Det /content/mot17/val/MOT17-09-FRCNN/det/det.txt to /content/mot17/val/det_flattened/MOT17-09-FRCNN.txt\n", + "Copied Det /content/mot17/val/MOT17-09-SDP/det/det.txt to /content/mot17/val/det_flattened/MOT17-09-SDP.txt\n", + "Copied Det /content/mot17/val/MOT17-10-DPM/det/det.txt to /content/mot17/val/det_flattened/MOT17-10-DPM.txt\n", + "Copied Det /content/mot17/val/MOT17-10-FRCNN/det/det.txt to /content/mot17/val/det_flattened/MOT17-10-FRCNN.txt\n", + "Copied Det /content/mot17/val/MOT17-10-SDP/det/det.txt to /content/mot17/val/det_flattened/MOT17-10-SDP.txt\n", + "Copied Det /content/mot17/val/MOT17-11-DPM/det/det.txt to /content/mot17/val/det_flattened/MOT17-11-DPM.txt\n", + "Copied Det /content/mot17/val/MOT17-11-FRCNN/det/det.txt to /content/mot17/val/det_flattened/MOT17-11-FRCNN.txt\n", + "Copied Det /content/mot17/val/MOT17-11-SDP/det/det.txt to /content/mot17/val/det_flattened/MOT17-11-SDP.txt\n", + "Copied Det /content/mot17/val/MOT17-13-DPM/det/det.txt to /content/mot17/val/det_flattened/MOT17-13-DPM.txt\n", + "Copied Det /content/mot17/val/MOT17-13-FRCNN/det/det.txt to /content/mot17/val/det_flattened/MOT17-13-FRCNN.txt\n", + "Copied Det /content/mot17/val/MOT17-13-SDP/det/det.txt to /content/mot17/val/det_flattened/MOT17-13-SDP.txt\n", + "Warning: Det /content/mot17/val/det_flattened/det/det.txt not found.\n", + "Detection files flattening complete.\n" + ] + } + ], + "source": [ + "val_split_gt_base = os.path.join(gt_base_dir, \"val\")\n", + "\n", + "formatted_det_output_dir = os.path.join(val_split_gt_base, \"det_flattened\")\n", + "os.makedirs(formatted_det_output_dir, exist_ok=True)\n", + "\n", + "for seq_folder in sorted(os.listdir(val_split_gt_base)):\n", + " full_seq_path = os.path.join(val_split_gt_base, seq_folder)\n", + " if os.path.isdir(full_seq_path):\n", + " source_det_path = os.path.join(full_seq_path, \"det\", \"det.txt\")\n", + " destination_det_path = os.path.join(formatted_det_output_dir, f\"{seq_folder}.txt\")\n", + " if os.path.exists(source_det_path):\n", + " shutil.copy(source_det_path, destination_det_path)\n", + " print(f\"Copied Det {source_det_path} to {destination_det_path}\")\n", + " else:\n", + " print(f\"Warning: Det {source_det_path} not found.\")\n", + "\n", + "print(\"Detection files flattening complete.\")\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3i3xzZ-4gKLk" + }, + "source": [ + "And now we can run the tracking over the validation set and then see the metrics" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "5PSWB_00gr8c" + }, + "outputs": [], + "source": [ + "gt_dir = Path(\"mot17/val/\")\n", + "det_dir = Path(\"mot17/val/det_flattened/\")\n", + "sequences = sorted(p.stem for p in det_dir.glob(\"*.txt\"))\n", + "eval_kwargs = dict(\n", + " gt_dir=gt_dir,\n", + " metrics=[\"CLEAR\", \"HOTA\", \"Identity\"],\n", + ")\n", + "\n", + "def run_eval(tracker):\n", + " with tempfile.TemporaryDirectory() as tmp:\n", + " pred_dir = Path(tmp)\n", + " for seq in sequences:\n", + " tracker.reset()\n", + " _run_tracker_on_detections(tracker, det_dir / f\"{seq}.txt\", pred_dir / f\"{seq}.txt\")\n", + " return evaluate_mot_sequences(tracker_dir=pred_dir, **eval_kwargs)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "n25vvIUEgwFP" + }, + "source": [ + "First we will evaluate with default parameters" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "fefweChygly1", + "outputId": "55974974-d815-4f83-947d-9ed5203a5b2b" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Sequence HOTA MOTA IDF1\n", + "----------------------------------------------------\n", + "MOT17-02-FRCNN 33.742 30.030 36.215\n", + "MOT17-04-FRCNN 55.348 48.813 62.383\n", + "MOT17-05-FRCNN 46.600 50.640 58.909\n", + "MOT17-09-FRCNN 49.461 50.747 56.474\n", + "MOT17-10-FRCNN 49.367 51.528 54.207\n", + "MOT17-11-FRCNN 48.992 54.572 54.689\n", + "MOT17-13-FRCNN 54.663 55.672 65.016\n", + "----------------------------------------------------\n", + "COMBINED 49.950 46.769 56.088\n" + ] + } + ], + "source": [ + "result_tuned = run_eval(SORTTracker())\n", + "print(result_tuned.table(columns=[\"HOTA\", \"MOTA\" , \"IDF1\"]))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "hk0xTGZTg7nB" + }, + "source": [ + "and now lets see how tuning parameters worked out" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "47FeX086c6Sc", + "outputId": "7fbc7746-2e3e-4b7b-c740-d4860ec1ac44" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Sequence HOTA MOTA IDF1\n", + "----------------------------------------------------\n", + "MOT17-02-FRCNN 34.437 29.646 36.246\n", + "MOT17-04-FRCNN 55.560 48.805 62.519\n", + "MOT17-05-FRCNN 45.407 50.164 56.731\n", + "MOT17-09-FRCNN 49.259 50.226 56.254\n", + "MOT17-10-FRCNN 49.032 50.650 54.657\n", + "MOT17-11-FRCNN 48.085 54.240 54.501\n", + "MOT17-13-FRCNN 57.243 58.460 69.077\n", + "----------------------------------------------------\n", + "COMBINED 50.124 46.677 56.316\n" + ] + } + ], + "source": [ + "result_tuned = run_eval(SORTTracker(**best_params))\n", + "\n", + "print(result_tuned.table(columns=[\"HOTA\", \"MOTA\", \"IDF1\"]))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "OOdMqk3ChBTO" + }, + "source": [ + "As you can see, we maximized for HOTA and got +0.2% HOTA, -0.1% MOTA and +0.2% IDF1. And by increasing the number of trials we can have even bigger improvements!\n", + "\n", + "Try it out and get your Tracker to the best performance!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Note**: MOT17 provides detections coming from different object detectors, we evaluate our trackers using the ones from FRCNN." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "snny6KuzgnrH" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "collapsed_sections": [ + "_2K7Nk_A6nJD" + ], + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} From 08caad69cd47a99eeb00fd4f73c3a5ff529c00e5 Mon Sep 17 00:00:00 2001 From: Alex Bodner Date: Wed, 6 May 2026 11:31:30 -0300 Subject: [PATCH 2/2] updated tuner usage as input seems to have changed since PR was opened --- notebooks/how-to-tune-your-tracker.ipynb | 542 ++++++++++------------- 1 file changed, 237 insertions(+), 305 deletions(-) diff --git a/notebooks/how-to-tune-your-tracker.ipynb b/notebooks/how-to-tune-your-tracker.ipynb index b98c3227..e5aa6c9a 100644 --- a/notebooks/how-to-tune-your-tracker.ipynb +++ b/notebooks/how-to-tune-your-tracker.ipynb @@ -37,74 +37,34 @@ "name": "stdout", "output_type": "stream", "text": [ - "Collecting trackers\n", - " Downloading trackers-2.3.0-py3-none-any.whl.metadata (8.0 kB)\n", - "Requirement already satisfied: numpy>=2.0.2 in /usr/local/lib/python3.12/dist-packages (from trackers) (2.0.2)\n", - "Requirement already satisfied: opencv-python>=4.8.0 in /usr/local/lib/python3.12/dist-packages (from trackers) (4.13.0.92)\n", - "Requirement already satisfied: requests>=2.28.0 in /usr/local/lib/python3.12/dist-packages (from trackers) (2.32.4)\n", - "Requirement already satisfied: rich>=13.0.0 in /usr/local/lib/python3.12/dist-packages (from trackers) (13.9.4)\n", - "Requirement already satisfied: scipy>=1.13.1 in /usr/local/lib/python3.12/dist-packages (from trackers) (1.16.3)\n", - "Collecting supervision>=0.26.1 (from trackers)\n", - " Downloading supervision-0.27.0.post2-py3-none-any.whl.metadata (13 kB)\n", - "Requirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers) (3.4.6)\n", - "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers) (3.11)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers) (2.5.0)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers) (2026.2.25)\n", - "Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.12/dist-packages (from rich>=13.0.0->trackers) (4.0.0)\n", - "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.12/dist-packages (from rich>=13.0.0->trackers) (2.19.2)\n", - "Requirement already satisfied: matplotlib>=3.6.0 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers) (3.10.0)\n", - "Requirement already satisfied: pyyaml>=5.3 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers) (6.0.3)\n", - "Requirement already satisfied: defusedxml>=0.7.1 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers) (0.7.1)\n", - "Requirement already satisfied: pillow>=9.4 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers) (11.3.0)\n", - "Requirement already satisfied: tqdm>=4.62.3 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers) (4.67.3)\n", - "Collecting pyDeprecate<0.6.0,>=0.4.0 (from supervision>=0.26.1->trackers)\n", - " Downloading pydeprecate-0.5.0-py3-none-any.whl.metadata (41 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m41.9/41.9 kB\u001b[0m \u001b[31m2.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.12/dist-packages (from markdown-it-py>=2.2.0->rich>=13.0.0->trackers) (0.1.2)\n", - "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (1.3.3)\n", - "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (0.12.1)\n", - "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (4.62.1)\n", - "Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (1.5.0)\n", - "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (26.0)\n", - "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (3.3.2)\n", - "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (2.9.0.post0)\n", - "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.7->matplotlib>=3.6.0->supervision>=0.26.1->trackers) (1.17.0)\n", - "Downloading trackers-2.3.0-py3-none-any.whl (96 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m96.5/96.5 kB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading supervision-0.27.0.post2-py3-none-any.whl (217 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m217.4/217.4 kB\u001b[0m \u001b[31m9.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading pydeprecate-0.5.0-py3-none-any.whl (38 kB)\n", - "Installing collected packages: pyDeprecate, supervision, trackers\n", - "Successfully installed pyDeprecate-0.5.0 supervision-0.27.0.post2 trackers-2.3.0\n", - "Requirement already satisfied: trackers[tune] in /usr/local/lib/python3.12/dist-packages (2.3.0)\n", - "\u001b[33mWARNING: trackers 2.3.0 does not provide the extra 'tune'\u001b[0m\u001b[33m\n", - "\u001b[0mRequirement already satisfied: numpy>=2.0.2 in /usr/local/lib/python3.12/dist-packages (from trackers[tune]) (2.0.2)\n", - "Requirement already satisfied: opencv-python>=4.8.0 in /usr/local/lib/python3.12/dist-packages (from trackers[tune]) (4.13.0.92)\n", - "Requirement already satisfied: requests>=2.28.0 in /usr/local/lib/python3.12/dist-packages (from trackers[tune]) (2.32.4)\n", - "Requirement already satisfied: rich>=13.0.0 in /usr/local/lib/python3.12/dist-packages (from trackers[tune]) (13.9.4)\n", - "Requirement already satisfied: scipy>=1.13.1 in /usr/local/lib/python3.12/dist-packages (from trackers[tune]) (1.16.3)\n", - "Requirement already satisfied: supervision>=0.26.1 in /usr/local/lib/python3.12/dist-packages (from trackers[tune]) (0.27.0.post2)\n", - "Requirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers[tune]) (3.4.6)\n", - "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers[tune]) (3.11)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers[tune]) (2.5.0)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.12/dist-packages (from requests>=2.28.0->trackers[tune]) (2026.2.25)\n", - "Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.12/dist-packages (from rich>=13.0.0->trackers[tune]) (4.0.0)\n", - "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.12/dist-packages (from rich>=13.0.0->trackers[tune]) (2.19.2)\n", - "Requirement already satisfied: matplotlib>=3.6.0 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers[tune]) (3.10.0)\n", - "Requirement already satisfied: pyyaml>=5.3 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers[tune]) (6.0.3)\n", - "Requirement already satisfied: defusedxml>=0.7.1 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers[tune]) (0.7.1)\n", - "Requirement already satisfied: pillow>=9.4 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers[tune]) (11.3.0)\n", - "Requirement already satisfied: tqdm>=4.62.3 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers[tune]) (4.67.3)\n", - "Requirement already satisfied: pyDeprecate<0.6.0,>=0.4.0 in /usr/local/lib/python3.12/dist-packages (from supervision>=0.26.1->trackers[tune]) (0.5.0)\n", - "Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.12/dist-packages (from markdown-it-py>=2.2.0->rich>=13.0.0->trackers[tune]) (0.1.2)\n", - "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (1.3.3)\n", - "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (0.12.1)\n", - "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (4.62.1)\n", - "Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (1.5.0)\n", - "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (26.0)\n", - "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (3.3.2)\n", - "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.12/dist-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (2.9.0.post0)\n", - "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/dist-packages (from python-dateutil>=2.7->matplotlib>=3.6.0->supervision>=0.26.1->trackers[tune]) (1.17.0)\n" + "Requirement already satisfied: trackers in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (2.4.0rc0)\n", + "Requirement already satisfied: numpy>=2.0.2 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from trackers) (2.2.6)\n", + "Requirement already satisfied: opencv-python>=4.8.0 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from trackers) (4.10.0.84)\n", + "Requirement already satisfied: requests>=2.28.0 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from trackers) (2.32.5)\n", + "Requirement already satisfied: rich>=13.0.0 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from trackers) (14.2.0)\n", + "Requirement already satisfied: scipy>=1.13.1 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from trackers) (1.15.3)\n", + "Requirement already satisfied: supervision>=0.26.1 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from trackers) (0.27.0)\n", + "Requirement already satisfied: charset_normalizer<4,>=2 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from requests>=2.28.0->trackers) (3.4.4)\n", + "Requirement already satisfied: idna<4,>=2.5 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from requests>=2.28.0->trackers) (3.7)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from requests>=2.28.0->trackers) (2.6.2)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from requests>=2.28.0->trackers) (2026.1.4)\n", + "Requirement already satisfied: markdown-it-py>=2.2.0 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from rich>=13.0.0->trackers) (4.0.0)\n", + "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from rich>=13.0.0->trackers) (2.19.2)\n", + "Requirement already satisfied: mdurl~=0.1 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from markdown-it-py>=2.2.0->rich>=13.0.0->trackers) (0.1.2)\n", + "Requirement already satisfied: matplotlib>=3.6.0 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from supervision>=0.26.1->trackers) (3.10.8)\n", + "Requirement already satisfied: pyyaml>=5.3 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from supervision>=0.26.1->trackers) (6.0.3)\n", + "Requirement already satisfied: defusedxml>=0.7.1 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from supervision>=0.26.1->trackers) (0.7.1)\n", + "Requirement already satisfied: pillow>=9.4 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from supervision>=0.26.1->trackers) (11.3.0)\n", + "Requirement already satisfied: tqdm>=4.62.3 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from supervision>=0.26.1->trackers) (4.67.1)\n", + "Requirement already satisfied: contourpy>=1.0.1 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (1.3.2)\n", + "Requirement already satisfied: cycler>=0.10 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (0.12.1)\n", + "Requirement already satisfied: fonttools>=4.22.0 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (4.61.1)\n", + "Requirement already satisfied: kiwisolver>=1.3.1 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (1.4.9)\n", + "Requirement already satisfied: packaging>=20.0 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (24.2)\n", + "Requirement already satisfied: pyparsing>=3 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (3.3.1)\n", + "Requirement already satisfied: python-dateutil>=2.7 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from matplotlib>=3.6.0->supervision>=0.26.1->trackers) (2.9.0.post0)\n", + "Requirement already satisfied: six>=1.5 in /opt/anaconda3/envs/trackers_env/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib>=3.6.0->supervision>=0.26.1->trackers) (1.17.0)\n", + "zsh:1: no matches found: trackers[tune]\n" ] } ], @@ -113,6 +73,21 @@ "!pip install trackers[tune]" ] }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import random\n", + "import shutil\n", + "import tempfile\n", + "from pathlib import Path\n", + "\n", + "import numpy as np" + ] + }, { "cell_type": "markdown", "metadata": { @@ -125,7 +100,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 16, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -171,7 +146,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 17, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -186,20 +161,20 @@ "text": [ "UserWarning: The trackers CLI is in beta. APIs may change in future releases.\n", "[download] mot17:train:detections\n", - "\u001b[2K\u001b[1mmot17-train-public-detections.zip\u001b[0m \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.2/1.2 MB\u001b[0m \u001b[31m31.5 MB/s\u001b[0m\n", - "\u001b[?25h[extract] mot17:train:detections\n", + " using cached mot17-train-public-detections.zip\n", + "[extract] mot17:train:detections\n", "[done] mot17:train:detections\n", "[download] mot17:train:annotations\n", - "\u001b[2K\u001b[1mmot17-train-annotations.zip\u001b[0m \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m694.6/694.6 kB\u001b[0m \u001b[31m33.7 MB/s\u001b[0m\n", - "\u001b[?25h[extract] mot17:train:annotations\n", + " using cached mot17-train-annotations.zip\n", + "[extract] mot17:train:annotations\n", "[done] mot17:train:annotations\n", "[download] mot17:val:detections\n", - "\u001b[2K\u001b[1mmot17-val-public-detections.zip\u001b[0m \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m59.9 MB/s\u001b[0m\n", - "\u001b[?25h[extract] mot17:val:detections\n", + " using cached mot17-val-public-detections.zip\n", + "[extract] mot17:val:detections\n", "[done] mot17:val:detections\n", "[download] mot17:val:annotations\n", - "\u001b[2K\u001b[1mmot17-val-annotations.zip\u001b[0m \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m615.2/615.2 kB\u001b[0m \u001b[31m63.5 MB/s\u001b[0m\n", - "\u001b[?25h[extract] mot17:val:annotations\n", + " using cached mot17-val-annotations.zip\n", + "[extract] mot17:val:annotations\n", "[done] mot17:val:annotations\n" ] } @@ -216,7 +191,7 @@ "source": [ "## Format dataset for tuning\n", "\n", - "Tuner class expects a directory for track sand a directory for detections like:\n", + "Tuner class expects a directory for tracks and a directory for detections like:\n", "```text\n", "data/\n", "├── gt/\n", @@ -249,163 +224,121 @@ "name": "stdout", "output_type": "stream", "text": [ - "Copied Det /content/mot17/train/MOT17-02-DPM/det/det.txt to /content/mot17/train/det_flattened/MOT17-02-DPM.txt\n", - "Copied Det /content/mot17/train/MOT17-02-FRCNN/det/det.txt to /content/mot17/train/det_flattened/MOT17-02-FRCNN.txt\n", - "Copied Det /content/mot17/train/MOT17-02-SDP/det/det.txt to /content/mot17/train/det_flattened/MOT17-02-SDP.txt\n", - "Copied Det /content/mot17/train/MOT17-04-DPM/det/det.txt to /content/mot17/train/det_flattened/MOT17-04-DPM.txt\n", - "Copied Det /content/mot17/train/MOT17-04-FRCNN/det/det.txt to /content/mot17/train/det_flattened/MOT17-04-FRCNN.txt\n", - "Copied Det /content/mot17/train/MOT17-04-SDP/det/det.txt to /content/mot17/train/det_flattened/MOT17-04-SDP.txt\n", - "Copied Det /content/mot17/train/MOT17-05-DPM/det/det.txt to /content/mot17/train/det_flattened/MOT17-05-DPM.txt\n", - "Copied Det /content/mot17/train/MOT17-05-FRCNN/det/det.txt to /content/mot17/train/det_flattened/MOT17-05-FRCNN.txt\n", - "Copied Det /content/mot17/train/MOT17-05-SDP/det/det.txt to /content/mot17/train/det_flattened/MOT17-05-SDP.txt\n", - "Copied Det /content/mot17/train/MOT17-09-DPM/det/det.txt to /content/mot17/train/det_flattened/MOT17-09-DPM.txt\n", - "Copied Det /content/mot17/train/MOT17-09-FRCNN/det/det.txt to /content/mot17/train/det_flattened/MOT17-09-FRCNN.txt\n", - "Copied Det /content/mot17/train/MOT17-09-SDP/det/det.txt to /content/mot17/train/det_flattened/MOT17-09-SDP.txt\n", - "Copied Det /content/mot17/train/MOT17-10-DPM/det/det.txt to /content/mot17/train/det_flattened/MOT17-10-DPM.txt\n", - "Copied Det /content/mot17/train/MOT17-10-FRCNN/det/det.txt to /content/mot17/train/det_flattened/MOT17-10-FRCNN.txt\n", - "Copied Det /content/mot17/train/MOT17-10-SDP/det/det.txt to /content/mot17/train/det_flattened/MOT17-10-SDP.txt\n", - "Copied Det /content/mot17/train/MOT17-11-DPM/det/det.txt to /content/mot17/train/det_flattened/MOT17-11-DPM.txt\n", - "Copied Det /content/mot17/train/MOT17-11-FRCNN/det/det.txt to /content/mot17/train/det_flattened/MOT17-11-FRCNN.txt\n", - "Copied Det /content/mot17/train/MOT17-11-SDP/det/det.txt to /content/mot17/train/det_flattened/MOT17-11-SDP.txt\n", - "Copied Det /content/mot17/train/MOT17-13-DPM/det/det.txt to /content/mot17/train/det_flattened/MOT17-13-DPM.txt\n", - "Copied Det /content/mot17/train/MOT17-13-FRCNN/det/det.txt to /content/mot17/train/det_flattened/MOT17-13-FRCNN.txt\n", - "Copied Det /content/mot17/train/MOT17-13-SDP/det/det.txt to /content/mot17/train/det_flattened/MOT17-13-SDP.txt\n", - "Detection files flattening complete.\n", - "det_dir set to: /content/mot17/train/det_flattened\n" + "Copied DET mot17/train/MOT17-02-DPM/det/det.txt -> mot17/train/det_flattened/MOT17-02-DPM.txt\n", + "Copied DET mot17/train/MOT17-02-FRCNN/det/det.txt -> mot17/train/det_flattened/MOT17-02-FRCNN.txt\n", + "Copied DET mot17/train/MOT17-02-SDP/det/det.txt -> mot17/train/det_flattened/MOT17-02-SDP.txt\n", + "Copied DET mot17/train/MOT17-04-DPM/det/det.txt -> mot17/train/det_flattened/MOT17-04-DPM.txt\n", + "Copied DET mot17/train/MOT17-04-FRCNN/det/det.txt -> mot17/train/det_flattened/MOT17-04-FRCNN.txt\n", + "Copied DET mot17/train/MOT17-04-SDP/det/det.txt -> mot17/train/det_flattened/MOT17-04-SDP.txt\n", + "Copied DET mot17/train/MOT17-05-DPM/det/det.txt -> mot17/train/det_flattened/MOT17-05-DPM.txt\n", + "Copied DET mot17/train/MOT17-05-FRCNN/det/det.txt -> mot17/train/det_flattened/MOT17-05-FRCNN.txt\n", + "Copied DET mot17/train/MOT17-05-SDP/det/det.txt -> mot17/train/det_flattened/MOT17-05-SDP.txt\n", + "Copied DET mot17/train/MOT17-09-DPM/det/det.txt -> mot17/train/det_flattened/MOT17-09-DPM.txt\n", + "Copied DET mot17/train/MOT17-09-FRCNN/det/det.txt -> mot17/train/det_flattened/MOT17-09-FRCNN.txt\n", + "Copied DET mot17/train/MOT17-09-SDP/det/det.txt -> mot17/train/det_flattened/MOT17-09-SDP.txt\n", + "Copied DET mot17/train/MOT17-10-DPM/det/det.txt -> mot17/train/det_flattened/MOT17-10-DPM.txt\n", + "Copied DET mot17/train/MOT17-10-FRCNN/det/det.txt -> mot17/train/det_flattened/MOT17-10-FRCNN.txt\n", + "Copied DET mot17/train/MOT17-10-SDP/det/det.txt -> mot17/train/det_flattened/MOT17-10-SDP.txt\n", + "Copied DET mot17/train/MOT17-11-DPM/det/det.txt -> mot17/train/det_flattened/MOT17-11-DPM.txt\n", + "Copied DET mot17/train/MOT17-11-FRCNN/det/det.txt -> mot17/train/det_flattened/MOT17-11-FRCNN.txt\n", + "Copied DET mot17/train/MOT17-11-SDP/det/det.txt -> mot17/train/det_flattened/MOT17-11-SDP.txt\n", + "Copied DET mot17/train/MOT17-13-DPM/det/det.txt -> mot17/train/det_flattened/MOT17-13-DPM.txt\n", + "Copied DET mot17/train/MOT17-13-FRCNN/det/det.txt -> mot17/train/det_flattened/MOT17-13-FRCNN.txt\n", + "Copied DET mot17/train/MOT17-13-SDP/det/det.txt -> mot17/train/det_flattened/MOT17-13-SDP.txt\n", + "DET files flattening complete.\n", + "Warning: GT source not found: mot17/train/MOT17-02-DPM/gt/gt.txt\n", + "Copied GT mot17/train/MOT17-02-FRCNN/gt/gt.txt -> mot17/train/gt_flattened/MOT17-02-FRCNN.txt\n", + "Warning: GT source not found: mot17/train/MOT17-02-SDP/gt/gt.txt\n", + "Warning: GT source not found: mot17/train/MOT17-04-DPM/gt/gt.txt\n", + "Copied GT mot17/train/MOT17-04-FRCNN/gt/gt.txt -> mot17/train/gt_flattened/MOT17-04-FRCNN.txt\n", + "Warning: GT source not found: mot17/train/MOT17-04-SDP/gt/gt.txt\n", + "Warning: GT source not found: mot17/train/MOT17-05-DPM/gt/gt.txt\n", + "Copied GT mot17/train/MOT17-05-FRCNN/gt/gt.txt -> mot17/train/gt_flattened/MOT17-05-FRCNN.txt\n", + "Warning: GT source not found: mot17/train/MOT17-05-SDP/gt/gt.txt\n", + "Warning: GT source not found: mot17/train/MOT17-09-DPM/gt/gt.txt\n", + "Copied GT mot17/train/MOT17-09-FRCNN/gt/gt.txt -> mot17/train/gt_flattened/MOT17-09-FRCNN.txt\n", + "Warning: GT source not found: mot17/train/MOT17-09-SDP/gt/gt.txt\n", + "Warning: GT source not found: mot17/train/MOT17-10-DPM/gt/gt.txt\n", + "Copied GT mot17/train/MOT17-10-FRCNN/gt/gt.txt -> mot17/train/gt_flattened/MOT17-10-FRCNN.txt\n", + "Warning: GT source not found: mot17/train/MOT17-10-SDP/gt/gt.txt\n", + "Warning: GT source not found: mot17/train/MOT17-11-DPM/gt/gt.txt\n", + "Copied GT mot17/train/MOT17-11-FRCNN/gt/gt.txt -> mot17/train/gt_flattened/MOT17-11-FRCNN.txt\n", + "Warning: GT source not found: mot17/train/MOT17-11-SDP/gt/gt.txt\n", + "Warning: GT source not found: mot17/train/MOT17-13-DPM/gt/gt.txt\n", + "Copied GT mot17/train/MOT17-13-FRCNN/gt/gt.txt -> mot17/train/gt_flattened/MOT17-13-FRCNN.txt\n", + "Warning: GT source not found: mot17/train/MOT17-13-SDP/gt/gt.txt\n", + "GT files flattening complete.\n", + "det_dir set to: mot17/train/det_flattened\n", + "gt_dir_for_tuner set to: mot17/train/gt_flattened\n" ] } ], "source": [ - "import os\n", - "import shutil\n", + "def flatten_asset(split_dir: Path, asset: str, output_dir_name: str) -> Path:\n", + " out_dir = split_dir / output_dir_name\n", + " out_dir.mkdir(parents=True, exist_ok=True)\n", + "\n", + " for seq_dir in sorted(p for p in split_dir.iterdir() if p.is_dir()):\n", + " # Skip generated flattened directories when re-running cells.\n", + " if seq_dir.name.endswith(\"_flattened\"):\n", + " continue\n", + "\n", + " src = seq_dir / asset / f\"{asset}.txt\"\n", + " dst = out_dir / f\"{seq_dir.name}.txt\"\n", + " if src.exists():\n", + " shutil.copy(src, dst)\n", + " print(f\"Copied {asset.upper()} {src} -> {dst}\")\n", + " else:\n", + " print(f\"Warning: {asset.upper()} source not found: {src}\")\n", + "\n", + " print(f\"{asset.upper()} files flattening complete.\")\n", + " return out_dir\n", + "\n", "\n", - "gt_base_dir = \"mot17/\"\n", - "train_split_gt_base = os.path.join(gt_base_dir, \"train\")\n", + "def build_seqmap(det_dir: Path, gt_dir: Path) -> tuple[Path, list[str]]:\n", + " det_sequences = {p.stem for p in det_dir.glob(\"*.txt\")}\n", + " gt_sequences = {p.stem for p in gt_dir.glob(\"*.txt\")}\n", + " common_sequences = sorted(det_sequences & gt_sequences)\n", "\n", - "# Flatten detection files for 'train' split\n", - "formatted_det_output_dir = os.path.join(train_split_gt_base, \"det_flattened\")\n", - "os.makedirs(formatted_det_output_dir, exist_ok=True)\n", + " with tempfile.NamedTemporaryFile(mode=\"w\", delete=False, suffix=\".txt\") as f:\n", + " for seq in common_sequences:\n", + " f.write(seq + \"\\n\")\n", + " return Path(f.name), common_sequences\n", "\n", - "for seq_folder in sorted(os.listdir(train_split_gt_base)):\n", - " full_seq_path = os.path.join(train_split_gt_base, seq_folder)\n", - " if os.path.isdir(full_seq_path):\n", - " source_det_path = os.path.join(full_seq_path, \"det\", \"det.txt\")\n", - " destination_det_path = os.path.join(formatted_det_output_dir, f\"{seq_folder}.txt\")\n", - " if os.path.exists(source_det_path):\n", - " shutil.copy(source_det_path, destination_det_path)\n", - " print(f\"Copied Det {source_det_path} to {destination_det_path}\")\n", "\n", - "print(\"Detection files flattening complete.\")\n", + "gt_base_dir = Path(\"mot17\")\n", + "train_split_dir = gt_base_dir / \"train\"\n", + "\n", + "train_det_dir = flatten_asset(train_split_dir, asset=\"det\", output_dir_name=\"det_flattened\")\n", + "train_gt_dir = flatten_asset(train_split_dir, asset=\"gt\", output_dir_name=\"gt_flattened\")\n", "\n", "# Define variables for the tuner\n", - "det_dir = formatted_det_output_dir\n", - "print(f\"det_dir set to: {det_dir}\")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "Y_0S2-eRTUvR" - }, - "source": [ - "!! This next cells will be removed once everything is merged" + "det_dir = str(train_det_dir)\n", + "gt_dir_for_tuner = str(train_gt_dir)\n", + "print(f\"det_dir set to: {det_dir}\")\n", + "print(f\"gt_dir_for_tuner set to: {gt_dir_for_tuner}\")" ] }, { "cell_type": "code", - "execution_count": 5, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "lPU3gQojTYx0", - "outputId": "aecf4b00-62ec-46a0-8fb0-735384cc48bd" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Found existing installation: trackers 2.3.0\n", - "Uninstalling trackers-2.3.0:\n", - " Would remove:\n", - " /usr/local/bin/trackers\n", - " /usr/local/lib/python3.12/dist-packages/trackers-2.3.0.dist-info/*\n", - " /usr/local/lib/python3.12/dist-packages/trackers/*\n", - "Proceed (Y/n)? y\n", - " Successfully uninstalled trackers-2.3.0\n" - ] - } - ], - "source": [ - "!pip uninstall trackers" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "cDXpIlvn0Ndd", - "outputId": "63d0bc4f-5151-4a5b-dbcd-7f31b687f30d" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", - " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", - " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", - " Building wheel for trackers (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n" - ] - } - ], - "source": [ - "!pip install -q git+https://github.com/omkar-334/trackers.git@feat/cli/tune-stage2 --no-cache" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "bbyoah5BEhM_", - "outputId": "805ddfd9-dedd-4804-a64b-221b246619c9" - }, + "execution_count": 39, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Collecting optuna\n", - " Downloading optuna-4.8.0-py3-none-any.whl.metadata (17 kB)\n", - "Requirement already satisfied: alembic>=1.5.0 in /usr/local/lib/python3.12/dist-packages (from optuna) (1.18.4)\n", - "Collecting colorlog (from optuna)\n", - " Downloading colorlog-6.10.1-py3-none-any.whl.metadata (11 kB)\n", - "Requirement already satisfied: numpy in /usr/local/lib/python3.12/dist-packages (from optuna) (2.0.2)\n", - "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.12/dist-packages (from optuna) (26.0)\n", - "Requirement already satisfied: sqlalchemy>=1.4.2 in /usr/local/lib/python3.12/dist-packages (from optuna) (2.0.48)\n", - "Requirement already satisfied: tqdm in /usr/local/lib/python3.12/dist-packages (from optuna) (4.67.3)\n", - "Requirement already satisfied: PyYAML in /usr/local/lib/python3.12/dist-packages (from optuna) (6.0.3)\n", - "Requirement already satisfied: Mako in /usr/local/lib/python3.12/dist-packages (from alembic>=1.5.0->optuna) (1.3.10)\n", - "Requirement already satisfied: typing-extensions>=4.12 in /usr/local/lib/python3.12/dist-packages (from alembic>=1.5.0->optuna) (4.15.0)\n", - "Requirement already satisfied: greenlet>=1 in /usr/local/lib/python3.12/dist-packages (from sqlalchemy>=1.4.2->optuna) (3.3.2)\n", - "Requirement already satisfied: MarkupSafe>=0.9.2 in /usr/local/lib/python3.12/dist-packages (from Mako->alembic>=1.5.0->optuna) (3.0.3)\n", - "Downloading optuna-4.8.0-py3-none-any.whl (419 kB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m419.5/419.5 kB\u001b[0m \u001b[31m6.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading colorlog-6.10.1-py3-none-any.whl (11 kB)\n", - "Installing collected packages: colorlog, optuna\n", - "Successfully installed colorlog-6.10.1 optuna-4.8.0\n" + "Using 7 shared sequences for tuning.\n" ] } ], "source": [ - "!pip install optuna" + "temp_seqmap_path, common_sequences = build_seqmap(\n", + " det_dir=Path(det_dir),\n", + " gt_dir=Path(gt_dir_for_tuner),\n", + ")\n", + "temp_seqmap_file = str(temp_seqmap_path)\n", + "print(f\"Using {len(common_sequences)} shared sequences for tuning.\")" ] }, { @@ -419,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 40, "metadata": { "id": "o5CcrFiM3Rwo" }, @@ -451,12 +384,18 @@ }, "outputs": [], "source": [ - "gt_dir = 'mot17/train'\n", + "import inspect\n", + "\n", + "sig = inspect.signature(Tuner.__init__).parameters\n", "\n", - "tuner = Tuner(\"sort\", gt_dir, det_dir,\n", - " objective = \"HOTA\",\n", - " metrics=[\"HOTA\"],\n", - " n_trials = 15)" + "tuner_kwargs = dict(\n", + " objective=\"HOTA\",\n", + " metrics=[\"HOTA\"],\n", + " n_trials=15,\n", + " seqmap=temp_seqmap_file,\n", + ")\n", + "\n", + "tuner = Tuner(\"sort\", gt_dir_for_tuner, det_dir, **tuner_kwargs)" ] }, { @@ -471,7 +410,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 50, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -484,22 +423,22 @@ "name": "stderr", "output_type": "stream", "text": [ - "[I 2026-03-27 13:37:17,698] A new study created in memory with name: trackers-tune-sort\n", - "[I 2026-03-27 13:37:28,929] Trial 0 finished with value: 0.13256008568177796 and parameters: {'lost_track_buffer': 39, 'track_activation_threshold': 0.2377381638424672, 'minimum_consecutive_frames': 3, 'minimum_iou_threshold': 0.2845933698271799}. Best is trial 0 with value: 0.13256008568177796.\n", - "[I 2026-03-27 13:37:40,198] Trial 1 finished with value: 0.13523735123132224 and parameters: {'lost_track_buffer': 56, 'track_activation_threshold': 0.6296591435085503, 'minimum_consecutive_frames': 2, 'minimum_iou_threshold': 0.0548526844745505}. Best is trial 1 with value: 0.13523735123132224.\n", - "[I 2026-03-27 13:37:52,544] Trial 2 finished with value: 0.13291667591600373 and parameters: {'lost_track_buffer': 80, 'track_activation_threshold': 0.8083421544621436, 'minimum_consecutive_frames': 2, 'minimum_iou_threshold': 0.4882273002180623}. Best is trial 1 with value: 0.13523735123132224.\n", - "[I 2026-03-27 13:38:04,336] Trial 3 finished with value: 0.13272899554683423 and parameters: {'lost_track_buffer': 46, 'track_activation_threshold': 0.8774424270625114, 'minimum_consecutive_frames': 1, 'minimum_iou_threshold': 0.15974850961089335}. Best is trial 1 with value: 0.13523735123132224.\n", - "[I 2026-03-27 13:38:15,805] Trial 4 finished with value: 0.13262955883945873 and parameters: {'lost_track_buffer': 51, 'track_activation_threshold': 0.6341772853153977, 'minimum_consecutive_frames': 3, 'minimum_iou_threshold': 0.5131879737664423}. Best is trial 1 with value: 0.13523735123132224.\n", - "[I 2026-03-27 13:38:26,807] Trial 5 finished with value: 0.1325532818864949 and parameters: {'lost_track_buffer': 59, 'track_activation_threshold': 0.4675618830556336, 'minimum_consecutive_frames': 3, 'minimum_iou_threshold': 0.40079834943408765}. Best is trial 1 with value: 0.13523735123132224.\n", - "[I 2026-03-27 13:38:38,569] Trial 6 finished with value: 0.1330599138257475 and parameters: {'lost_track_buffer': 37, 'track_activation_threshold': 0.6627787421466715, 'minimum_consecutive_frames': 1, 'minimum_iou_threshold': 0.15394319802475565}. Best is trial 1 with value: 0.13523735123132224.\n", - "[I 2026-03-27 13:38:49,176] Trial 7 finished with value: 0.13294477555127504 and parameters: {'lost_track_buffer': 24, 'track_activation_threshold': 0.87607447815685, 'minimum_consecutive_frames': 3, 'minimum_iou_threshold': 0.5984455460515848}. Best is trial 1 with value: 0.13523735123132224.\n", - "[I 2026-03-27 13:39:00,035] Trial 8 finished with value: 0.13269523841102507 and parameters: {'lost_track_buffer': 28, 'track_activation_threshold': 0.577308324930741, 'minimum_consecutive_frames': 1, 'minimum_iou_threshold': 0.4196943720248147}. Best is trial 1 with value: 0.13523735123132224.\n", - "[I 2026-03-27 13:39:11,350] Trial 9 finished with value: 0.13298506636090984 and parameters: {'lost_track_buffer': 34, 'track_activation_threshold': 0.8247335575354222, 'minimum_consecutive_frames': 1, 'minimum_iou_threshold': 0.6117129046986972}. Best is trial 1 with value: 0.13523735123132224.\n", - "[I 2026-03-27 13:39:22,449] Trial 10 finished with value: 0.13527991637020112 and parameters: {'lost_track_buffer': 69, 'track_activation_threshold': 0.3485735415165917, 'minimum_consecutive_frames': 4, 'minimum_iou_threshold': 0.06322898044739839}. Best is trial 10 with value: 0.13527991637020112.\n", - "[I 2026-03-27 13:39:33,398] Trial 11 finished with value: 0.13516002378562741 and parameters: {'lost_track_buffer': 71, 'track_activation_threshold': 0.33745248273351086, 'minimum_consecutive_frames': 4, 'minimum_iou_threshold': 0.05030950534487981}. Best is trial 10 with value: 0.13527991637020112.\n", - "[I 2026-03-27 13:39:43,670] Trial 12 finished with value: 0.1350849259561734 and parameters: {'lost_track_buffer': 89, 'track_activation_threshold': 0.40714848540002124, 'minimum_consecutive_frames': 4, 'minimum_iou_threshold': 0.05793678852593959}. Best is trial 10 with value: 0.13527991637020112.\n", - "[I 2026-03-27 13:39:55,265] Trial 13 finished with value: 0.1326734600356485 and parameters: {'lost_track_buffer': 65, 'track_activation_threshold': 0.1719562980770182, 'minimum_consecutive_frames': 2, 'minimum_iou_threshold': 0.25038235146905297}. Best is trial 10 with value: 0.13527991637020112.\n", - "[I 2026-03-27 13:40:06,991] Trial 14 finished with value: 0.13275106387541644 and parameters: {'lost_track_buffer': 75, 'track_activation_threshold': 0.3047900177047508, 'minimum_consecutive_frames': 2, 'minimum_iou_threshold': 0.1504008582619463}. Best is trial 10 with value: 0.13527991637020112.\n" + "\u001b[32m[I 2026-05-06 11:29:26,767]\u001b[0m A new study created in memory with name: trackers-tune-sort\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:28,928]\u001b[0m Trial 0 finished with value: 0.5186650561265436 and parameters: {'lost_track_buffer': 69, 'track_activation_threshold': 0.7130570280582736, 'minimum_consecutive_frames': 2, 'minimum_iou_threshold': 0.23540528081006296}. Best is trial 0 with value: 0.5186650561265436.\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:30,971]\u001b[0m Trial 1 finished with value: 0.5074865193306491 and parameters: {'lost_track_buffer': 60, 'track_activation_threshold': 0.41309168934204377, 'minimum_consecutive_frames': 1, 'minimum_iou_threshold': 0.47399154789630427}. Best is trial 0 with value: 0.5186650561265436.\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:33,060]\u001b[0m Trial 2 finished with value: 0.5045530896178886 and parameters: {'lost_track_buffer': 59, 'track_activation_threshold': 0.3159869813866671, 'minimum_consecutive_frames': 4, 'minimum_iou_threshold': 0.47128276336992686}. Best is trial 0 with value: 0.5186650561265436.\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:35,062]\u001b[0m Trial 3 finished with value: 0.5149836121829238 and parameters: {'lost_track_buffer': 66, 'track_activation_threshold': 0.42847645551979313, 'minimum_consecutive_frames': 1, 'minimum_iou_threshold': 0.26414695272141936}. Best is trial 0 with value: 0.5186650561265436.\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:37,810]\u001b[0m Trial 4 finished with value: 0.5203045221187809 and parameters: {'lost_track_buffer': 66, 'track_activation_threshold': 0.8218442811600641, 'minimum_consecutive_frames': 1, 'minimum_iou_threshold': 0.11111383270042534}. Best is trial 4 with value: 0.5203045221187809.\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:39,775]\u001b[0m Trial 5 finished with value: 0.5174140436386967 and parameters: {'lost_track_buffer': 55, 'track_activation_threshold': 0.1447515581057484, 'minimum_consecutive_frames': 3, 'minimum_iou_threshold': 0.11549157042595042}. Best is trial 4 with value: 0.5203045221187809.\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:42,002]\u001b[0m Trial 6 finished with value: 0.505770446177535 and parameters: {'lost_track_buffer': 78, 'track_activation_threshold': 0.844461279271947, 'minimum_consecutive_frames': 2, 'minimum_iou_threshold': 0.5254346007704056}. Best is trial 4 with value: 0.5203045221187809.\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:43,918]\u001b[0m Trial 7 finished with value: 0.5112500316104994 and parameters: {'lost_track_buffer': 73, 'track_activation_threshold': 0.8332806536059795, 'minimum_consecutive_frames': 1, 'minimum_iou_threshold': 0.408102736065568}. Best is trial 4 with value: 0.5203045221187809.\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:45,718]\u001b[0m Trial 8 finished with value: 0.4840970315873794 and parameters: {'lost_track_buffer': 29, 'track_activation_threshold': 0.8654684853943477, 'minimum_consecutive_frames': 4, 'minimum_iou_threshold': 0.6610501749168268}. Best is trial 4 with value: 0.5203045221187809.\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:47,589]\u001b[0m Trial 9 finished with value: 0.5145691843259742 and parameters: {'lost_track_buffer': 36, 'track_activation_threshold': 0.7785606038017389, 'minimum_consecutive_frames': 1, 'minimum_iou_threshold': 0.26314867883914433}. Best is trial 4 with value: 0.5203045221187809.\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:49,716]\u001b[0m Trial 10 finished with value: 0.5150378316264993 and parameters: {'lost_track_buffer': 87, 'track_activation_threshold': 0.6127059247970889, 'minimum_consecutive_frames': 3, 'minimum_iou_threshold': 0.0853085869966548}. Best is trial 4 with value: 0.5203045221187809.\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:52,303]\u001b[0m Trial 11 finished with value: 0.5180093136105441 and parameters: {'lost_track_buffer': 44, 'track_activation_threshold': 0.6203186560748285, 'minimum_consecutive_frames': 2, 'minimum_iou_threshold': 0.20946603506913444}. Best is trial 4 with value: 0.5203045221187809.\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:54,829]\u001b[0m Trial 12 finished with value: 0.5041608608158924 and parameters: {'lost_track_buffer': 12, 'track_activation_threshold': 0.6789956255687448, 'minimum_consecutive_frames': 2, 'minimum_iou_threshold': 0.18225905423787656}. Best is trial 4 with value: 0.5203045221187809.\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:57,036]\u001b[0m Trial 13 finished with value: 0.5163515781570905 and parameters: {'lost_track_buffer': 89, 'track_activation_threshold': 0.7125619959569656, 'minimum_consecutive_frames': 2, 'minimum_iou_threshold': 0.3329154075772316}. Best is trial 4 with value: 0.5203045221187809.\u001b[0m\n", + "\u001b[32m[I 2026-05-06 11:29:59,137]\u001b[0m Trial 14 finished with value: 0.5114071057141582 and parameters: {'lost_track_buffer': 77, 'track_activation_threshold': 0.5439469953959495, 'minimum_consecutive_frames': 3, 'minimum_iou_threshold': 0.05338472531700066}. Best is trial 4 with value: 0.5203045221187809.\u001b[0m\n" ] } ], @@ -518,7 +457,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 51, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -531,7 +470,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'lost_track_buffer': 69, 'track_activation_threshold': 0.3485735415165917, 'minimum_consecutive_frames': 4, 'minimum_iou_threshold': 0.06322898044739839}\n" + "{'lost_track_buffer': 66, 'track_activation_threshold': 0.8218442811600641, 'minimum_consecutive_frames': 1, 'minimum_iou_threshold': 0.11111383270042534}\n" ] } ], @@ -559,7 +498,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 52, "metadata": { "id": "GTqhCAb2fpKw" }, @@ -567,9 +506,7 @@ "source": [ "from trackers.tune.tuner import _run_tracker_on_detections\n", "from trackers.eval.evaluate import evaluate_mot_sequences\n", - "from trackers import SORTTracker\n", - "from pathlib import Path\n", - "import tempfile" + "from trackers import SORTTracker" ] }, { @@ -583,7 +520,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 53, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -596,50 +533,34 @@ "name": "stdout", "output_type": "stream", "text": [ - "Copied Det /content/mot17/val/MOT17-02-DPM/det/det.txt to /content/mot17/val/det_flattened/MOT17-02-DPM.txt\n", - "Copied Det /content/mot17/val/MOT17-02-FRCNN/det/det.txt to /content/mot17/val/det_flattened/MOT17-02-FRCNN.txt\n", - "Copied Det /content/mot17/val/MOT17-02-SDP/det/det.txt to /content/mot17/val/det_flattened/MOT17-02-SDP.txt\n", - "Copied Det /content/mot17/val/MOT17-04-DPM/det/det.txt to /content/mot17/val/det_flattened/MOT17-04-DPM.txt\n", - "Copied Det /content/mot17/val/MOT17-04-FRCNN/det/det.txt to /content/mot17/val/det_flattened/MOT17-04-FRCNN.txt\n", - "Copied Det /content/mot17/val/MOT17-04-SDP/det/det.txt to /content/mot17/val/det_flattened/MOT17-04-SDP.txt\n", - "Copied Det /content/mot17/val/MOT17-05-DPM/det/det.txt to /content/mot17/val/det_flattened/MOT17-05-DPM.txt\n", - "Copied Det /content/mot17/val/MOT17-05-FRCNN/det/det.txt to /content/mot17/val/det_flattened/MOT17-05-FRCNN.txt\n", - "Copied Det /content/mot17/val/MOT17-05-SDP/det/det.txt to /content/mot17/val/det_flattened/MOT17-05-SDP.txt\n", - "Copied Det /content/mot17/val/MOT17-09-DPM/det/det.txt to /content/mot17/val/det_flattened/MOT17-09-DPM.txt\n", - "Copied Det /content/mot17/val/MOT17-09-FRCNN/det/det.txt to /content/mot17/val/det_flattened/MOT17-09-FRCNN.txt\n", - "Copied Det /content/mot17/val/MOT17-09-SDP/det/det.txt to /content/mot17/val/det_flattened/MOT17-09-SDP.txt\n", - "Copied Det /content/mot17/val/MOT17-10-DPM/det/det.txt to /content/mot17/val/det_flattened/MOT17-10-DPM.txt\n", - "Copied Det /content/mot17/val/MOT17-10-FRCNN/det/det.txt to /content/mot17/val/det_flattened/MOT17-10-FRCNN.txt\n", - "Copied Det /content/mot17/val/MOT17-10-SDP/det/det.txt to /content/mot17/val/det_flattened/MOT17-10-SDP.txt\n", - "Copied Det /content/mot17/val/MOT17-11-DPM/det/det.txt to /content/mot17/val/det_flattened/MOT17-11-DPM.txt\n", - "Copied Det /content/mot17/val/MOT17-11-FRCNN/det/det.txt to /content/mot17/val/det_flattened/MOT17-11-FRCNN.txt\n", - "Copied Det /content/mot17/val/MOT17-11-SDP/det/det.txt to /content/mot17/val/det_flattened/MOT17-11-SDP.txt\n", - "Copied Det /content/mot17/val/MOT17-13-DPM/det/det.txt to /content/mot17/val/det_flattened/MOT17-13-DPM.txt\n", - "Copied Det /content/mot17/val/MOT17-13-FRCNN/det/det.txt to /content/mot17/val/det_flattened/MOT17-13-FRCNN.txt\n", - "Copied Det /content/mot17/val/MOT17-13-SDP/det/det.txt to /content/mot17/val/det_flattened/MOT17-13-SDP.txt\n", - "Warning: Det /content/mot17/val/det_flattened/det/det.txt not found.\n", - "Detection files flattening complete.\n" + "Copied DET mot17/val/MOT17-02-DPM/det/det.txt -> mot17/val/det_flattened/MOT17-02-DPM.txt\n", + "Copied DET mot17/val/MOT17-02-FRCNN/det/det.txt -> mot17/val/det_flattened/MOT17-02-FRCNN.txt\n", + "Copied DET mot17/val/MOT17-02-SDP/det/det.txt -> mot17/val/det_flattened/MOT17-02-SDP.txt\n", + "Copied DET mot17/val/MOT17-04-DPM/det/det.txt -> mot17/val/det_flattened/MOT17-04-DPM.txt\n", + "Copied DET mot17/val/MOT17-04-FRCNN/det/det.txt -> mot17/val/det_flattened/MOT17-04-FRCNN.txt\n", + "Copied DET mot17/val/MOT17-04-SDP/det/det.txt -> mot17/val/det_flattened/MOT17-04-SDP.txt\n", + "Copied DET mot17/val/MOT17-05-DPM/det/det.txt -> mot17/val/det_flattened/MOT17-05-DPM.txt\n", + "Copied DET mot17/val/MOT17-05-FRCNN/det/det.txt -> mot17/val/det_flattened/MOT17-05-FRCNN.txt\n", + "Copied DET mot17/val/MOT17-05-SDP/det/det.txt -> mot17/val/det_flattened/MOT17-05-SDP.txt\n", + "Copied DET mot17/val/MOT17-09-DPM/det/det.txt -> mot17/val/det_flattened/MOT17-09-DPM.txt\n", + "Copied DET mot17/val/MOT17-09-FRCNN/det/det.txt -> mot17/val/det_flattened/MOT17-09-FRCNN.txt\n", + "Copied DET mot17/val/MOT17-09-SDP/det/det.txt -> mot17/val/det_flattened/MOT17-09-SDP.txt\n", + "Copied DET mot17/val/MOT17-10-DPM/det/det.txt -> mot17/val/det_flattened/MOT17-10-DPM.txt\n", + "Copied DET mot17/val/MOT17-10-FRCNN/det/det.txt -> mot17/val/det_flattened/MOT17-10-FRCNN.txt\n", + "Copied DET mot17/val/MOT17-10-SDP/det/det.txt -> mot17/val/det_flattened/MOT17-10-SDP.txt\n", + "Copied DET mot17/val/MOT17-11-DPM/det/det.txt -> mot17/val/det_flattened/MOT17-11-DPM.txt\n", + "Copied DET mot17/val/MOT17-11-FRCNN/det/det.txt -> mot17/val/det_flattened/MOT17-11-FRCNN.txt\n", + "Copied DET mot17/val/MOT17-11-SDP/det/det.txt -> mot17/val/det_flattened/MOT17-11-SDP.txt\n", + "Copied DET mot17/val/MOT17-13-DPM/det/det.txt -> mot17/val/det_flattened/MOT17-13-DPM.txt\n", + "Copied DET mot17/val/MOT17-13-FRCNN/det/det.txt -> mot17/val/det_flattened/MOT17-13-FRCNN.txt\n", + "Copied DET mot17/val/MOT17-13-SDP/det/det.txt -> mot17/val/det_flattened/MOT17-13-SDP.txt\n", + "DET files flattening complete.\n" ] } ], "source": [ - "val_split_gt_base = os.path.join(gt_base_dir, \"val\")\n", - "\n", - "formatted_det_output_dir = os.path.join(val_split_gt_base, \"det_flattened\")\n", - "os.makedirs(formatted_det_output_dir, exist_ok=True)\n", - "\n", - "for seq_folder in sorted(os.listdir(val_split_gt_base)):\n", - " full_seq_path = os.path.join(val_split_gt_base, seq_folder)\n", - " if os.path.isdir(full_seq_path):\n", - " source_det_path = os.path.join(full_seq_path, \"det\", \"det.txt\")\n", - " destination_det_path = os.path.join(formatted_det_output_dir, f\"{seq_folder}.txt\")\n", - " if os.path.exists(source_det_path):\n", - " shutil.copy(source_det_path, destination_det_path)\n", - " print(f\"Copied Det {source_det_path} to {destination_det_path}\")\n", - " else:\n", - " print(f\"Warning: Det {source_det_path} not found.\")\n", - "\n", - "print(\"Detection files flattening complete.\")\n" + "val_split_dir = gt_base_dir / \"val\"\n", + "val_det_dir = flatten_asset(val_split_dir, asset=\"det\", output_dir_name=\"det_flattened\")\n" ] }, { @@ -653,26 +574,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": { "id": "5PSWB_00gr8c" }, "outputs": [], "source": [ - "gt_dir = Path(\"mot17/val/\")\n", - "det_dir = Path(\"mot17/val/det_flattened/\")\n", - "sequences = sorted(p.stem for p in det_dir.glob(\"*.txt\"))\n", + "val_gt_dir = gt_base_dir / \"val\"\n", + "val_det_dir = Path(val_det_dir)\n", + "sequences = sorted(p.stem for p in val_det_dir.glob(\"*.txt\"))\n", "eval_kwargs = dict(\n", - " gt_dir=gt_dir,\n", + " gt_dir=val_gt_dir,\n", " metrics=[\"CLEAR\", \"HOTA\", \"Identity\"],\n", ")\n", "\n", + "\n", "def run_eval(tracker):\n", " with tempfile.TemporaryDirectory() as tmp:\n", " pred_dir = Path(tmp)\n", " for seq in sequences:\n", " tracker.reset()\n", - " _run_tracker_on_detections(tracker, det_dir / f\"{seq}.txt\", pred_dir / f\"{seq}.txt\")\n", + " _run_tracker_on_detections(tracker, val_det_dir / f\"{seq}.txt\", pred_dir / f\"{seq}.txt\")\n", " return evaluate_mot_sequences(tracker_dir=pred_dir, **eval_kwargs)\n" ] }, @@ -687,7 +609,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 55, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -715,8 +637,8 @@ } ], "source": [ - "result_tuned = run_eval(SORTTracker())\n", - "print(result_tuned.table(columns=[\"HOTA\", \"MOTA\" , \"IDF1\"]))" + "result_default = run_eval(SORTTracker())\n", + "print(result_default.table(columns=[\"HOTA\", \"MOTA\" , \"IDF1\"]))" ] }, { @@ -730,7 +652,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 56, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -745,15 +667,15 @@ "text": [ "Sequence HOTA MOTA IDF1\n", "----------------------------------------------------\n", - "MOT17-02-FRCNN 34.437 29.646 36.246\n", - "MOT17-04-FRCNN 55.560 48.805 62.519\n", - "MOT17-05-FRCNN 45.407 50.164 56.731\n", - "MOT17-09-FRCNN 49.259 50.226 56.254\n", - "MOT17-10-FRCNN 49.032 50.650 54.657\n", - "MOT17-11-FRCNN 48.085 54.240 54.501\n", - "MOT17-13-FRCNN 57.243 58.460 69.077\n", + "MOT17-02-FRCNN 34.844 30.081 36.782\n", + "MOT17-04-FRCNN 55.246 49.045 62.426\n", + "MOT17-05-FRCNN 47.274 52.398 59.273\n", + "MOT17-09-FRCNN 50.062 51.372 56.973\n", + "MOT17-10-FRCNN 50.062 52.034 55.821\n", + "MOT17-11-FRCNN 49.522 55.014 55.485\n", + "MOT17-13-FRCNN 58.514 59.981 69.936\n", "----------------------------------------------------\n", - "COMBINED 50.124 46.677 56.316\n" + "COMBINED 50.499 47.371 56.850\n" ] } ], @@ -769,7 +691,7 @@ "id": "OOdMqk3ChBTO" }, "source": [ - "As you can see, we maximized for HOTA and got +0.2% HOTA, -0.1% MOTA and +0.2% IDF1. And by increasing the number of trials we can have even bigger improvements!\n", + "As you can see, we maximized for HOTA and got +0.6% HOTA, 0.5% MOTA and +0.8% IDF1. And by increasing the number of trials we can have even bigger improvements!\n", "\n", "Try it out and get your Tracker to the best performance!" ] @@ -778,7 +700,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**Note**: MOT17 provides detections coming from different object detectors, we evaluate our trackers using the ones from FRCNN." + "**Note**: MOT17 provides detections coming from different object detectors, in this notebook we evaluate using the ones from FRCNN." ] }, { @@ -799,11 +721,21 @@ "provenance": [] }, "kernelspec": { - "display_name": "Python 3", + "display_name": "trackers_env", + "language": "python", "name": "python3" }, "language_info": { - "name": "python" + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.19" } }, "nbformat": 4,