This notebook demonstrates how to set up and run ByteTrack, an advanced object tracking algorithm, using YOLOX as the detection backbone. The process involves cloning the ByteTrack repository, installing dependencies, downloading a pre-trained model, and running a video inference demo.
Setup Instructions
- Install Ultralytics This step installs the Ultralytics library, which includes YOLO models.
!pip3 install ultralytics 2. Clone ByteTrack Repository Clone the official ByteTrack repository from GitHub.
!git clone https://github.com/ifzhang/ByteTrack.git 3. Install gdown gdown is used to download files from Google Drive.
!pip3 install gdown 4. Download Pre-trained Model Navigate to the ByteTrack directory, create a pretrained folder, and download the bytetrack_x_mot17.pth.tar model weights. This model is based on YOLOX-X for MOT17.
%cd /content/ByteTrack/ %mkdir pretrained %cd pretrained !gdown --id "1P4mY0Yyd3PPTybgZkjMYhFri88nTmJX5" 5. Install ByteTrack Dependencies Install necessary libraries including cython, pycocotools, cython_bbox, and the requirements specified in ByteTrack's requirements.txt.
Note: You might encounter an ERROR: No matching distribution found for onnxruntime==1.8.0. This is likely due to version compatibility issues with newer Python environments. You may need to adjust the onnxruntime version in requirements.txt or skip its installation if not strictly needed for your use case.
!pip3 install cython !pip3 install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI' !pip3 install cython_bbox
%cd /content/ByteTrack/ !pip3 install -r requirements.txt 6. Install ByteTrack Install ByteTrack in development mode.
!python3 setup.py develop 7. Install Additional Tracking Dependencies Ensure loguru, sap, and lap are installed, as they are crucial for the tracking components.
!pip3 install loguru sap lap Running the Demo After setting up, you can run the object tracking demo. The demo script tools/demo_track.py will process a video (by default palace.mp4 in the videos directory if it exists, or you can specify your own video path) and save the results.
Note on np.float error: A common issue with older codebases like ByteTrack when used with newer NumPy versions is the deprecation of np.float. The traceback AttributeError: module 'numpy' has no attribute 'float'. indicates this. To fix this, you need to modify the ByteTrack source code (specifically yolox/tracker/byte_tracker.py) to replace np.float with float or np.float32/np.float64.
Before running the demo, modify yolox/tracker/byte_tracker.py: Find the line self._tlwh = np.asarray(tlwh, dtype=np.float) and change np.float to float.
%cd /content/ByteTrack/ !python3 tools/demo_track.py video -f exps/example/mot/yolox_x_mix_det.py -c pretrained/bytetrack_x_mot17.pth.tar --fp16 --fuse --save_result Custom YOLOv5 Tracking (using ultralytics) This section demonstrates object tracking using the ultralytics YOLOv5 model and a custom bytetrack.yaml configuration. It processes a video from Google Drive, draws bounding boxes and track IDs, and saves the output video.