7

Tiny Object Detection Using Yolo-V5

 2 years ago
source link: https://blog.knoldus.com/tiny-object-detection-using-yolo-v5/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Tiny Object Detection Using Yolo-V5

Reading Time: 3 minutes

What is Object Detection ?

Object detection involves detecting instances of objects from a particular class in an image. Background. Object detection has been widely used for face detection, vehicle detection, pedestrian counting, web images, security systems and driverless cars.

Object detection is a computer vision technique that allows us to identify and locate objects in an image or video.

Here in our case we have detected broken wheat and damaged wheat in the given image.

These objects have been detected by Yolo – V5 Model

Binary class Detection of Object

Images clearly shows the Broken Wheat grains by using Yolo-V5

Object Localization

The difference between object localization and object detection is subtle.

An image classification or image recognition model simply detect the probability of an object in an image. An object localization algorithm will output the coordinates of the location of an object with respect to the image. In computer vision, the most popular way to localize an object in an image is to represent its location with the help of bounding boxes.

Bounding box can be intilized with this steps

  • bx, by : coordinates of the center of the bounding box
  • bw : width of the bounding box w.r.t the image width
  • bh : height of the bounding box w.r.t the image height

How to do Object Detection Using Yolo V5 and what are the steps included in it?

To train a Yolo V5 model, a few things need to be download from the internet.

  • Collecting Our Training Images
  • Environment Setup
  • Set up the data and the directories
  • Set up the configuration YAML files
  • Use your custom Yolo V5 model to detect objects on the test data
  • Annotating Our Training Images
  • Define YOLO v5 Model Configuration and Architecture
  • Train the model to learn how to detect objects
  • Evaluate YOLO v5 performance
  • Run YOLO v5 Inference on test images
  • Export Saved YOLO v5 Weights for Future Inference

Object Detection is a task in Artificial Intelligence that focuses on detecting objects in images. Yolo V5 is one of the best available models for Object Detection at the moment. The great thing about this Deep Neural Network is that it is very easy to retrain the network on your own custom dataset.

Environment Setup to train Yolo V5 object Detection Model

1- Clone the yolo V5 repository from GitHub

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

This will create a folder called ‘yolov5’ on your machine.

Requirements

The repository has some requirements to make the codes run properly. First, I will insist that you manually install the latest PyTorch framework version.

2-INSTALLING THE DEPENDENCIES

%cd yolov5 %
pip install -r requirements.txt # install dependencies

DOWNLOADING ALL VERSIONS OF YOLO-V5 MODEL

!/content/yolov5/weights/download_weights.sh

These values needs to configured

With our data.yaml and custom_yolov5s.yaml files ready to go we are ready to train!

To initiate the training phase we need to write these steps

  • img: define input image size
  • batch: determine batch size
  • epochs: define the number of training epochs. (Note: often, 3000+ are common here!)
  • data: set the path to our yaml file
  • cfg: specify our model configuration
  • weights: specify a custom path to weights. (Note: you can download weights from the Ultralytics Google Drive folder)
  • name: result names
  • nosave: only save the final checkpoint
  • cache: cache images for faster training
  1. Go to yolov5/data/
  2. Open coco128.yaml
  1.   Training and Test file path
  2.   Number of classes and Class names.

TRAINING THE YOLO-V5 MODEL

!python train.py –img 416 –batch 20 –epochs 70 –data coco128.yaml –weights yolov5s.pt –cache

VISUALIZING THE TRAINING METRICS

%load_ext tensorboard
%tensorboard –logdir runs/train

Testing

!python val.py –weights /content/yolov5/runs/train/exp/weights/best.pt –data coco128.yaml –img 416

Run YOLO v5 Inference on test images

!python val.py –weights /content/yolov5/runs/train/exp/weights/best.pt –data coco128.yaml –img 416

DETECTING ON NEW IMAGES

!python detect.py –source /content –weights /content/yolov5/runs/train/exp/weights/best.pt –img 416 –save-txt –save-conf

Colab Link for YOLO_V5_ON_YOUR_CUSTOM_DATASET.ipynb

https://colab.research.google.com/drive/1uxsf60z1rHwvJoTZbpI9tBB34rUcLxG7#scrollTo=5R3aBtYFr_5d

Official Github Link for Download of Yolo V5

https://github.com/ultralytics/yolov5

My GitHub Profile

https://github.com/priyabratknoldus/objectdetectionwheat

Conclusion

I hope you were able to follow along and was able to train successfully.

I have uploaded the notebook, config files, and weight to my Github repository.

If you have any questions, recommendations, or critiques, I can be reached via my mail .Feel free to reach out to me.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK