YOLOv8-based object detection, multi-object tracking, trajectory analysis, and movement visualization.
This project demonstrates an end-to-end computer vision workflow for detecting and tracking objects in video or image-sequence data. It uses Ultralytics YOLOv8 with ByteTrack to assign stable object IDs across frames, generate annotated tracking output, analyze object trajectories, and visualize movement patterns with heatmaps and distribution plots.
The workflow is implemented in Object_detection.ipynb, making it easy to run locally in Jupyter or on Google Colab with GPU acceleration.
- Object detection with YOLOv8 models
- Multi-object tracking with ByteTrack
- Persistent tracking IDs across frames
- Annotated output video generation
- Object trajectory collection and plotting
- Movement heatmap visualization
- Horizontal and vertical movement distribution analysis
- Basic quantitative tracking metrics, including unique object count and average trajectory length
- GPU support through PyTorch and Ultralytics
Object-Detection/
├── Object_detection.ipynb # Main notebook for detection, tracking, and analysis
├── requirements.txt # Python dependencies
├── videos/
│ └── test.mp4 # Sample input video
├── output/
│ └── tracked_output.mp4 # Sample tracked output video
├── trajectory_frame.jpg # Example trajectory frame
├── yolov8m.pt # YOLOv8 medium model weights
├── yolov8n.pt # YOLOv8 nano model weights
├── LICENSE # MIT license
└── README.md
| Category | Tools |
|---|---|
| Detection and tracking | Ultralytics YOLOv8, ByteTrack |
| Computer vision | OpenCV |
| ML runtime | PyTorch, Torchvision |
| Data analysis | NumPy, Pandas |
| Visualization | Matplotlib |
| Notebook runtime | Jupyter / Google Colab |
- Python 3.10 or newer
- Jupyter Notebook or JupyterLab
- A CUDA-capable GPU is recommended for faster processing, but CPU execution is supported
Clone the repository:
git clone https://github.com/Shashwat-19/Object-Detection.git
cd Object-DetectionCreate and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activateInstall dependencies:
pip install -r requirements.txtLaunch Jupyter:
jupyter notebook Object_detection.ipynb-
Open
Object_detection.ipynb. -
Choose the model weights:
model = YOLO("yolov8m.pt")
Use
yolov8n.ptfor faster inference oryolov8m.ptfor stronger detection quality. -
Set the input source:
VIDEO_PATH = "videos/test.mp4"
The notebook can also process an image folder, such as a MOT dataset frame directory.
-
Run tracking:
results = model.track( source=VIDEO_PATH, tracker="bytetrack.yaml", save=True, show=False, conf=0.3, persist=True )
-
Generate and inspect the tracked output video and trajectory visualizations.
The notebook includes Colab-oriented cells for mounting Google Drive and cloning this repository. To run on Colab:
- Open the notebook using the Colab badge above.
- Enable GPU from
Runtime > Change runtime type > GPU. - Mount Google Drive if your dataset is stored there.
- Update
VIDEO_PATHto point to your video or frame directory. - Run all notebook cells.
The workflow can produce:
- Annotated tracking frames from YOLOv8 and ByteTrack
- MP4 tracking output, saved as
tracked_output.mp4or underoutput/ - Object ID logs per frame
- Trajectory history for each tracked object
- Movement heatmap
- Horizontal and vertical movement distribution plots
- Tracking metrics such as unique objects tracked and average trajectory length
| Preview | Description |
|---|---|
output/tracked_output.mp4 |
Sample tracked output video |
trajectory_frame.jpg |
Example frame used for trajectory visualization |
Common values to tune in the notebook:
| Parameter | Description | Default |
|---|---|---|
VIDEO_PATH |
Input video or image-frame directory | Colab Drive path / sample video |
tracker |
Tracking algorithm configuration | bytetrack.yaml |
conf |
Detection confidence threshold | 0.3 |
persist |
Reuse object IDs across frames | True |
device |
Inference device, such as 0 for GPU or cpu |
0 in Colab cells |
max_trajectories_to_show |
Number of trajectories plotted | 10 |
- The included
.ptfiles are YOLOv8 model weights. If they are removed, Ultralytics can download supported weights automatically when requested. - For local CPU-only runs, replace
device=0withdevice="cpu"or remove thedeviceargument. - The Colab notebook references
/content/drive/MyDrive/MOT17-02-FRCNN/img1as an example dataset path. Update it to match your own dataset location. - Large video outputs and model weights can make the repository heavy. Consider using Git LFS for future model and media assets.
Comprehensive documentation for this project is available on Hashnode.
At present, this README serves as the primary source of documentation.
This project is distributed under the MIT License.
For detailed licensing information, please refer to the LICENSE file included in this repository.
Machine Learning Engineer | Scalable AI Systems
🔹 ML systems: (CV, NLP) + data pipelines
🔹 End-to-end: training → deployment
🔹 Backend & Cloud: Python, Flask, Node.js, Docker, AWS
🔹 Projects: Traffic AI, Video Summarizer, AI Assistants
Building robust applications and leveraging cloud technologies for high-performance solutions.
Feel free to connect for tech collaborations, open-source contributions, or brainstorming innovative solutions!