0% found this document useful (0 votes)
6 views5 pages

Detailed Human Detection Model Guide Retry

This guide provides detailed steps for training a human detection model using YOLOv5, including setup, data preparation, model configuration, training, evaluation, and inference. Key steps involve cloning the YOLOv5 repository, organizing the dataset, creating a YAML configuration file, and executing training and evaluation commands. Additionally, it covers exporting the model for deployment on edge devices and includes links to relevant resources.

Uploaded by

Adhyayan Tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Detailed Human Detection Model Guide Retry

This guide provides detailed steps for training a human detection model using YOLOv5, including setup, data preparation, model configuration, training, evaluation, and inference. Key steps involve cloning the YOLOv5 repository, organizing the dataset, creating a YAML configuration file, and executing training and evaluation commands. Additionally, it covers exporting the model for deployment on edge devices and includes links to relevant resources.

Uploaded by

Adhyayan Tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Guide: Detailed Steps for Training a Human Detection Model Using YOLOv5

1. Setup and Install Required Libraries

- First, clone the YOLOv5 repository and install the required libraries.

- You can do this by running the following commands:

```bash

!git clone https://github.com/ultralytics/yolov5.git

%cd yolov5

!pip install -r requirements.txt

```

- Ensure that you have GPU support for efficient training, especially on large datasets.

2. Import Libraries

- Import necessary libraries like PyTorch and others for display and path handling.

```python

import torch

from pathlib import Path

from IPython.display import Image, clear_output

```

3. Download or Load Data


- Download a dataset like the COCO dataset or prepare your own custom dataset with human

annotations.

- Organize the dataset as follows:

- `train/`: Training images

- `val/`: Validation images

- `labels/train/`: Training labels in YOLO format

- `labels/val/`: Validation labels in YOLO format

- You can use tools like LabelImg (https://github.com/tzutalin/labelImg) for labeling custom data.

4. Configure YOLOv5 Model for Custom Training

- Create a YAML file specifying dataset paths and classes. Here's an example configuration:

```python

dataset_config = """

path: /content/dataset # dataset root dir

train: images/train # train images

val: images/val # validation images

# number of classes

nc: 1

# class names

names: ['human']

"""
with open("human_detection.yaml", "w") as file:

file.write(dataset_config)

```

- This YAML file is necessary to specify the dataset paths and classes for YOLOv5.

5. Training the Model

- Use the following command to start training the YOLOv5 model on your custom dataset:

```python

!python train.py --img 640 --batch 16 --epochs 50 --data human_detection.yaml --weights

yolov5s.pt --cache

```

- Parameters:

- `--img`: Image size for training.

- `--batch`: Batch size for each step.

- `--epochs`: Number of epochs.

- `--data`: Path to the YAML file with dataset config.

- `--weights`: Pre-trained weights for initialization.

6. Evaluate the Model

- After training, evaluate the model using the following command:

```python

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


```

- This will output metrics such as Precision, Recall, and mAP (mean Average Precision).

7. Inference on New Images

- Use the trained model for inference on new images or video. Example command:

```python

!python detect.py --weights runs/train/exp/weights/best.pt --img 640 --conf 0.5 --source

/content/test_images

```

- Parameters:

- `--weights`: Path to the trained model weights.

- `--conf`: Confidence threshold for detections.

- `--source`: Directory containing test images.

8. Export the Model for Deployment

- Export the trained model in formats like ONNX or CoreML for deployment on edge devices:

```python

!python export.py --weights runs/train/exp/weights/best.pt --img 640 --batch 1 --device 0

--include onnx

```

- This allows deploying the model on devices such as drones and mobile applications.
Additional Resources

- **COCO Dataset**: https://cocodataset.org/

- **LabelImg Tool**: https://github.com/tzutalin/labelImg

- **YOLOv5 Repository**: https://github.com/ultralytics/yolov5

You might also like