Simple Guide to Object Detection with YOLOv8 on a custom dataset

Example image of object detection

The What’s and Whys of Object Detection

In the last article, we covered topics such as what an image was, and how to detect different colors present inside it. However, given a little more thought, it’s easy to understand that colors are not the only thing about images we perceive. There are people🗿, places, maybe animals🐓and so much more.

To all you smarties, I am excluding abstract art out of discussion. Now, why are we able to tell these things apart in pictures? How can we recognize our loved ones in an image? Aren’t they all just some particular mixture of “color🟥🟩🟦 in an area?

The answer to that lies in the way that our complex brain functions🧠, Fun Fact: Even though the brain only constitutes to about 2% of our weight, it consumes 20% of the total energy that our body consumes. Which is much higher than any other species.

Energy expenditure of brain

What happens essentially is, the image that we are seeing through our eye 👁️ gets fed into a complex neural network in the brain, which gives an output about the information that is present in the image. This is happening right at this moment as you read through this newsletter!

In this article, we are trying to essentially make a computer understand the images and try and detect objects inside the image (not just color). Similar to the process in our brain🧠, we are trying to feed in an image to a neural network (YOLO) made by a computer and get predictions of the locations of different objects in the images!

Intro to YOLO (You Only Look Once)

YOLO (You Only Look Once) is a game-changer in object detection, blending speed and accuracy like never before. This innovative algorithm processes images in real-time, identifying objects with unparalleled precision. Whether it's for autonomous driving, surveillance, or smart home applications, YOLO's efficiency and effectiveness are setting new standards. Which is why I chose to learn and use it for my project

Example of the Output of a YOLO detection mode

YOLO Quick start Tutorial

  1. Install Python3 with PATH on your local machine

    Check the add to path option when you install it

  2. Open a terminal window or CMD and run this command

pip install ultralytics torch torchvision torchaudio
  1. Create a python file and run this code!

from ultralytics import YOLO
# Import pretrained model 
model = YOLO("yolov8n.pt")
# Train the model on the coco.yaml for 3 epochs
results = model.train(data = "coco.yaml", epochs = 3)
# Evaluate the model's performance on the validation set
results = model.val()
# Perform object detection on a random image
results = model("https://ultralytics.com/images/bus.jpg", show = True)

That’s about it, you should be able to see an image with the model’s predictions! If you have any questions about any of this, feel free to shoot a comment down below, or you can also refer to the official documentation for more information 😄

Keep reading