This project implements automated person detection using the YOLOv5 object detection model. It processes a structured dataset of images, applies detection using a pre-trained YOLOv5 model, and saves the output images with bounding boxes.
The dataset should follow this folder structure:
dataset/
├── subfolder1/
│ └── images/
│ ├── image1.jpg
│ └── image2.jpg
├── subfolder2/
│ └── images/
│ ├── image3.jpg
│ └── image4.jpg
- Python 3.x
- PyTorch
- OpenCV
- Matplotlib
- YOLOv5 via Torch Hub
- Install the required packages:
pip install torch torchvision opencv-python matplotlib-
Place your dataset in the
./datasetfolder. -
Run the script:
python detect_from_dataset.py- Detected images with bounding boxes will be saved in the
./detectionsfolder, organized by subfolder.
To restrict detection to only persons (class 0 in the COCO dataset), modify the model as follows in the script:
model.classes = [0]The script saves the annotated images and optionally displays them using Matplotlib.
