About Expertise Projects Posts Contact
Back to Home

Object Detection Application on DIOR Dataset by Using YOLOv5

Instructions: Using YOLOv5 for Object Detection on the DIOR Dataset

1. Setup and Installation

Install the YOLOv5 framework by cloning its repository:

git clone https://github.com/ultralytics/yolov5.git
cd yolov5
pip install -r requirements.txt

Verify that dependencies like PyTorch, OpenCV, and Tensorboard are installed.

2. Dataset Preparation

Download the DIOR Dataset:

  • The DIOR dataset contains 20 categories with 23,463 sub-images and 190,288 instances.
  • Ensure the dataset is formatted with images and annotations compatible with YOLOv5 (e.g., .txt files for bounding boxes).

Organize the dataset into:

  • train/: Images for training.
  • val/: Images for validation.
  • labels/: Corresponding bounding box labels for each image.

3. Configuring YOLOv5

Modify the dataset configuration file (dior.yaml):

train: path/to/train/images
val: path/to/val/images
nc: 20  # number of classes
names: ['airplane', 'airport', 'baseball field', ...]  # class names

Adjust hyperparameters for training in data/hyps/hyp.scratch.yaml:

  • Example: Set learning rate, batch size, and epochs based on your hardware.

4. Model Training

Use transfer learning by starting with a pre-trained YOLOv5 model (e.g., YOLOv5s):

python train.py --img 640 --batch 16 --epochs 50 --data dior.yaml --weights yolov5s.pt

Parameters:

  • --img: Image size (default: 640x640).
  • --batch: Batch size (adjust based on GPU memory).
  • --epochs: Number of training iterations.

5. Evaluation

Evaluate the model performance using metrics like mAP (Mean Average Precision) and IoU (Intersection Over Union):

python val.py --weights runs/train/exp/weights/best.pt --data dior.yaml --img 640

Analyze precision-recall curves, confusion matrices, and other outputs.

6. Inference

Use the trained model for inference on new images:

python detect.py --weights runs/train/exp/weights/best.pt --img 640 --conf 0.5 --source path/to/test/images

Note: Adjust --conf (confidence threshold) and --source (path to images or videos).

7. Visualization

Visualize results using YOLOv5's Tensorboard integration:

tensorboard --logdir runs/train

Review detected bounding boxes, training curves, and metrics.

8. Advanced Techniques

  • Augmentation: Apply mosaic, albumentation, and flipping techniques during training to improve robustness.
  • Model Selection: Use YOLOv5m for better accuracy or YOLOv5s for faster inference.
  • Fine-tuning: Experiment with hyperparameters like learning rate, batch size, and epochs.

For detailed steps, refer to the full project report.

Project Report

Test Videos

YOLOv5 Object Detection Test 1

YOLOv5 Object Detection Test 2

YOLOv5 Object Detection Test 3