Analytics Vidhya
Published in

Analytics Vidhya

Large Scale Object Detection & Tracking with YOLOv5 Package

Only ‘pip install yolov5’ away from you…

Simple as that.
  • Are you having a hard time installing latest YOLO object detector in Windows/Linux?
  • Are you getting errors during training/inference with your custom YOLOv5 models?
  • Are you looking for a real-time object tracker with only few lines of code?
  • Do you want to perform large-scale (drone surveillance/satellite imagery/wide-area surveillance) object detection in one click?

Keep reading this post and you will be able to handle all of these in seconds..

YOLOv5 Object Detector

https://ultralytics.com/yolov5

YOLOv5 is the fastest and most accurate YOLO ever made and you can use it for any object detection problem you need.

Installation is simple: run pip install yolov5 in Windows/Linux terminal and you are ready to go.

https://ultralytics.com/yolov5

Basic Usage

import yolov5# model
model = yolov5.load('yolov5s')
# image
img = 'https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg'
# inference
results = model(img)
# inference with larger input size
results = model(img, size=1280)
# inference with test time augmentation
results = model(img, augment=True)
# show results
results.show()
# save results
results.save(save_dir='results/')

Training

Run command below to fine tune on your data. Training times for YOLOv5s/m/l/x are 2/4/6/8 days on a single V100 (multi-GPU times faster). Use the largest --batch-size your GPU allows (batch sizes shown for 8 GB devices). For detailed info, refer to: https://pypi.org/project/yolov5/

$ yolov5 train --data coco.yaml --cfg --weights 'yolov5s6.pt' --batch-size 16

Inference

yolov5 detect command runs inference on a variety of sources, downloading models automatically from the latest YOLOv5 release and saving results to runs/detect. For detailed info, refer to: https://pypi.org/project/yolov5/

$ yolov5 detect --source 0  # webcam
file.jpg # image
file.mp4 # video
path/ # directory
path/*.jpg # glob

State-of-the-art Object Tracking with YOLOv5

You can create a real-time custom multi object tracker in few lines of code, here is the minimal example:

State-of-the-art YOLOv5 Object Tracker in few lines of code.

And here is the output:

YOLOv5 Object Tracking Demo.

In this colab notebook you can find a YOLOv5 object tracker in action. It performs high accuracy pedestrian and car tracking from any YouTube video! Refer here for the full YOLOv5 tracking code.

Large Scale Object Detection with YOLOv5

If you are working with huge satellite images or wide area surveillance images, inference with standard input sizes are not possible. Here comes the SAHI package with its sliced inference feature:

Sliced inference from SAHI.

In this demo notebook, you can see how to perform large scale sliced inference with YOLOv5 in few lines!

Or you can perform YOLOv5 sliced inference from CLI:

python scripts/predict.py --model_type yolov5 --source image/file/or/folder --model_path path/to/model

For detail on CLI arguments refer to here.

Conclusion

With this article, we have covered:

Feel free to ask questions if you have trouble at any step!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store