A collection of scripts and utilities for dataset preparation, conversion, auto-annotation & training of YOLO object detection models.
The pipeline involves extracting frames from raw videos, generating YOLO labels, splitting the dataset, and training or predicting hoop detections.
This repository also includes hoop detection inference visualization from a sample video run.
Dataset preparation:
- Place raw videos in the
videos/directory. - Use
extract_frames.pyto extract all video frames.
Generate labels:
- Use
generate_labels.pyto predict and save YOLO labels for your dataset.
Split dataset:
- Use
autosplit.pyorgenerate_kfold_dataset.pyfor train/val/test splits.
Train a model:
- Use
training.pyfor automated queue-based training.
Predict on videos:
- Use
predict_video.pyorbatch_predict_video.pyto run inference and save annotated videos.
Format conversion:
- If you use CVAT for annotation, use
yolo_to_cvat.pyto convert between annotation formats and neatly zip up your dataset to easily upload to CVAT.
.
├── datasets/
│ ├── my_dataset/
│ │ ├── images/
│ │ │ ├── img001.jpg
│ │ │ └── ...
│ │ ├── labels/
│ │ │ ├── img001.txt
│ │ │ └── ...
│ │ ├── all_images.txt
│ │ ├── data.yaml
│ │ └── autosplit_train.txt
│ └── ...
├── runs/
│ └── my_project/
│ ├── my_model/
│ │ └── weights/
│ │ ├── best.pt
│ │ └── last.pt
│ └── ...
└── videos/
├── video1.mp4
├── video2.mp4
└── output/
├── video1_out.mp4
└── ...
Make sure you've installed Pytorch according to your system requirements.
Install Required Python Packages:
pip install -r requirements.txt-
Extract frames from a video:
python extract_frames.py videos/video1.mp4 datasets/new_dataset/images
-
Generate labels:
python generate_labels.py datasets/new_dataset runs/my_project/my_model/weights/best.pt --save --autosplit --split 0.8 0.2 0
-
Start model training queue:
python training.py
-
Batch predict videos:
python batch_predict_video.py videos/ videos/output/ runs/my_project/
- All scripts accept
--helpfor usage instructions. - Place your datasets in the
datasets/directory and trained models inruns/.