How to Train YOLOv5-Classification on a Custom Dataset

Roboflow · Beginner ·👁️ Computer Vision ·3y ago

Key Takeaways

This video demonstrates how to train YOLOv5 for image classification on a custom dataset, covering the setup of a Python environment, dataset format, and training process using Google Colab and Roboflow.

Full Transcript

YOLO you only look once arguably the most influential and successful image classification model ever wait what I mean yeah according to the latest release notes they are doing classification now so in our last video we are talking about yellow V5 being capable of commit segmentation and today we'll be talking about image classification by the way link to that video will be in the description below and in the card displayed right now but before we start we actually need to explain why it's such a big deal so YOLO has algorithm and YOLO V5 as a framework are very good at training object detection models yeah object detection not image classification those are definitely two different things object detection is where you say what object do you see and where on the image you see that so for example over here we say that we see raccoon and we precisely where the raccoon is located image classification is simpler task we just say I see raccoon on the image why would I train image classification model if I can train object detection there are actually multiple reasons where you would do that for starters image classification models are lighter they simply consume less space in the memory second of all you can train a model with significantly more classes than in case of object detection typically hundreds or even thousands not to mention that the actual inference takes less time which is very important in many scenarios every architecture has pros and cons but you can definitely come up with scenario where the image classification model is the desired one roboflow has actually a very good article about different computer vision tasks once again the link is in the description below it's time to get our hands dirty and train our first YOLO V5 classification model so as previously with image segmentation we have a dedicated blog post that describe the whole process but we will go straight into the Google collab that is linked over here Google Cloud app opens a new tab now we can just save copy on our hard drive the next steps are similar like in the case of object detection and image segmentation so we just connect our jupyter notebook to the python environment with gpus and after that is done we run the first cell the first cell is mostly responsible for colliding the repository and setting up the python project installing the dependencies mainly pytorch now we can make sure that everything installed properly so we will download the weights of every model that is accessible within a yellow V5 repository and use one of those models to infer on example image so the first cell is actually downloading an example image the second one loads model into the memory and produce classification the name of the image slightly ruins the surprise bananas JPEG but yeah our model is 96 sure that there are bananas on the image so now the time has finally come and we'll actually train the model ourselves on our custom data set before we start however I guess it's worth to mention that the format of data for image classification is different than usual yellow format for object detection typically when you train your model you work with something called yellow darknet txt format where every Row in the txt file is separate detection and you have the ID of the class as well as the coordinates of the bounding box in it for image classification we don't have any additional annotation file so how do we know what is the class of the object visible on the image we know that by the name of the directory that the image is located so for example over here inside the train data set we have class 1 directory and we know that all images in that directory are of class 1 and similarly over here we know that all images in that directory are of class number two now the moment that we've all been waiting for let's train our own classification model so we will use tomato classification data set that is the one that we used in our tutorial so let's follow the link in the tutorial we click download select the format so in our case like I said it will be file structure click continue and copy the snippet straight into our jupyter notebook over here in our Jupiter notebook we have few cells one of them will create the data sets directory the other one will download the data set from roboflow website protect your API key at all costs don't share it with anybody our data set has downloaded correctly and we can start the training there are just few more cells that we need to run the first one is setting the data set name as an environment variable and then we are ready to run the actual training script we use 100 epochs over here so that may take a little bit of time to train although it's nothing compared to image segmentation or object detection actually it wasn't so bad took less than 15 minutes finally we are ready to validate our model so let's use script classified slash valve slash py to run our validation on pretty small but still validation set and we are 100 correct and that's it leave a comment under the video if you like it we have a lot of similar content in the pipeline mainly about yellow V5 yellow V6 and yellow V7 leave a sap if you find this video useful and my name was Peter and I see you next time bye

Original Description

YOLOv5 is one of the most popular object detection networks in the world, and now object detection isn't the only trick up its sleeve! Chapters: 0:00 Introduction 0:14 Image classification vs. object detection 1:42 Setting up python environment 3:00 Dataset format 4:02 Getting open source data from Roboflow Universe 4:48 Training classification model 5:40 Outro Roboflow - https://roboflow.com Roboflow Universe: https://universe.roboflow.com "How to Train YOLOv5-Classification on a Custom Dataset" Blog Post: https://blog.roboflow.com/train-yolov5-classification-custom-data/ Official Roboflow YOLOv5 Classification Colab Training Colab: https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/train-yolov5-classification-on-custom-data.ipynb "Object Detection vs Image Classification vs. Keypoint Detection: What's the Difference?" Blog Post: https://blog.roboflow.com/object-detection-vs-image-classification-vs-keypoint-detection/ "How to Train YOLOv5 Instance Segmentation on a Custom Dataset" YouTube Video: https://youtu.be/vKzfvtEtiYo 📓 Learn more about YOLOv7 and other Computer Vision models with Roboflow Notebooks: https://github.com/roboflow-ai/notebooks Stay up to date with the projects I'm working on at https://github.com/roboflow-ai and https://github.com/SkalskiP! ⭐
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Roboflow · Roboflow · 0 of 60

← Previous Next →
1 YOLOv3 PyTorch Notebook Tutorial
YOLOv3 PyTorch Notebook Tutorial
Roboflow
2 How to Train YOLOv4 on a Custom Dataset (PyTorch)
How to Train YOLOv4 on a Custom Dataset (PyTorch)
Roboflow
3 How to Train YOLOv5 on a Custom Dataset
How to Train YOLOv5 on a Custom Dataset
Roboflow
4 How to Use the Roboflow Dataset Health Check
How to Use the Roboflow Dataset Health Check
Roboflow
5 What is Mean Average Precision (mAP)?
What is Mean Average Precision (mAP)?
Roboflow
6 How to Use the Roboflow Model Library
How to Use the Roboflow Model Library
Roboflow
7 How to Train EfficientDet in TensorFlow 2 Object Detection
How to Train EfficientDet in TensorFlow 2 Object Detection
Roboflow
8 How to Train YOLO v4 Tiny (Darknet) on a Custom Dataset
How to Train YOLO v4 Tiny (Darknet) on a Custom Dataset
Roboflow
9 Ask the Roboflow Team Anything - Episode 1
Ask the Roboflow Team Anything - Episode 1
Roboflow
10 Exploring The COCO Dataset
Exploring The COCO Dataset
Roboflow
11 Community Spotlight: Improving Uno with Computer Vision
Community Spotlight: Improving Uno with Computer Vision
Roboflow
12 Mosaic Data Augmentation - Deep Dive
Mosaic Data Augmentation - Deep Dive
Roboflow
13 Hands on with the OAK-1
Hands on with the OAK-1
Roboflow
14 Glenn Jocher: What is New in YOLO v5?
Glenn Jocher: What is New in YOLO v5?
Roboflow
15 How to Use Amazon Rekognition Custom Labels and Roboflow to Build an Object Detection Model
How to Use Amazon Rekognition Custom Labels and Roboflow to Build an Object Detection Model
Roboflow
16 An Interview with Brandon Gilles, Luxonis Founder and OAK Chief Architect
An Interview with Brandon Gilles, Luxonis Founder and OAK Chief Architect
Roboflow
17 How to Train a Custom Mobile Object Detection Model (with YOLOv4 Tiny and TensorFlow Lite)
How to Train a Custom Mobile Object Detection Model (with YOLOv4 Tiny and TensorFlow Lite)
Roboflow
18 Tackling the Small Object Problem in Object Detection
Tackling the Small Object Problem in Object Detection
Roboflow
19 Fast.ai v2 Released - What's New?
Fast.ai v2 Released - What's New?
Roboflow
20 Teaser: Roboflow Train (1-Click Computer Vision AutoML)
Teaser: Roboflow Train (1-Click Computer Vision AutoML)
Roboflow
21 How to Train a Custom Resnet34 Image Classification Model
How to Train a Custom Resnet34 Image Classification Model
Roboflow
22 How to Label Images for Object Detection with CVAT
How to Label Images for Object Detection with CVAT
Roboflow
23 Deploy YOLOv5 to Jetson Xavier NX at 30 FPS
Deploy YOLOv5 to Jetson Xavier NX at 30 FPS
Roboflow
24 Elisha Odemakinde Hosts Roboflow ML Engineer, Jacob Solawetz
Elisha Odemakinde Hosts Roboflow ML Engineer, Jacob Solawetz
Roboflow
25 Getting Started with VoTT - Computer Vision Annotation
Getting Started with VoTT - Computer Vision Annotation
Roboflow
26 How to Manage Classes in Object Detection (Rename, Combine, Balance)
How to Manage Classes in Object Detection (Rename, Combine, Balance)
Roboflow
27 How to Train YOLOv4 on a Custom Dataset in Darknet
How to Train YOLOv4 on a Custom Dataset in Darknet
Roboflow
28 Is Grayscale a Preprocessing or Augmentation Step in Computer Vision?
Is Grayscale a Preprocessing or Augmentation Step in Computer Vision?
Roboflow
29 Getting Started with Image Data Augmentation
Getting Started with Image Data Augmentation
Roboflow
30 Glenn Jocher: Image Augmentation in YOLO v5 and Beyond
Glenn Jocher: Image Augmentation in YOLO v5 and Beyond
Roboflow
31 GA Hosts Roboflow - Healthcare and AI
GA Hosts Roboflow - Healthcare and AI
Roboflow
32 How do self driving cars know when to stop?
How do self driving cars know when to stop?
Roboflow
33 What is PASCAL VOC XML?
What is PASCAL VOC XML?
Roboflow
34 AutoML Showdown: Google vs Amazon vs Microsoft
AutoML Showdown: Google vs Amazon vs Microsoft
Roboflow
35 How is computer vision changing manufacturing?
How is computer vision changing manufacturing?
Roboflow
36 The Alphabet in American Sign Language
The Alphabet in American Sign Language
Roboflow
37 Luxonis OAK-D: Computer Vision on Device
Luxonis OAK-D: Computer Vision on Device
Roboflow
38 How to Train a Custom Faster R-CNN Model with Facebook AI's Detectron2 | Use Your Own Dataset
How to Train a Custom Faster R-CNN Model with Facebook AI's Detectron2 | Use Your Own Dataset
Roboflow
39 TensorFlow vs PyTorch: Fireside
TensorFlow vs PyTorch: Fireside
Roboflow
40 Occlusion Techniques in Computer Vision
Occlusion Techniques in Computer Vision
Roboflow
41 A Customizable Web Application for Your Computer Vision Model
A Customizable Web Application for Your Computer Vision Model
Roboflow
42 Model Tradeoffs and the Future of Computer Vision
Model Tradeoffs and the Future of Computer Vision
Roboflow
43 Designing an Augmented Reality Board Game App
Designing an Augmented Reality Board Game App
Roboflow
44 YOLOv4 - Advanced Tactics
YOLOv4 - Advanced Tactics
Roboflow
45 How to Use CreateML and Build a Computer Vision iPhone App | AR Object Detection
How to Use CreateML and Build a Computer Vision iPhone App | AR Object Detection
Roboflow
46 Fireside Chat: Computer Vision in Agriculture
Fireside Chat: Computer Vision in Agriculture
Roboflow
47 Scaled-YOLOv4 Tops EfficientDet: Research Rundown
Scaled-YOLOv4 Tops EfficientDet: Research Rundown
Roboflow
48 What is Image Preprocessing?
What is Image Preprocessing?
Roboflow
49 Building a Community of Creators with BlkArthouse and Von Deon
Building a Community of Creators with BlkArthouse and Von Deon
Roboflow
50 How to Train Scaled-YOLOv4 to Detect Custom Objects
How to Train Scaled-YOLOv4 to Detect Custom Objects
Roboflow
51 Intro to Computer Vision: Fireside
Intro to Computer Vision: Fireside
Roboflow
52 The Best Way to Annotate Images for Object Detection
The Best Way to Annotate Images for Object Detection
Roboflow
53 The Computer Vision Process: Fireside
The Computer Vision Process: Fireside
Roboflow
54 How to Annotate Images with Your Team Using Roboflow
How to Annotate Images with Your Team Using Roboflow
Roboflow
55 Introducing the Roboflow Object Count Histogram
Introducing the Roboflow Object Count Histogram
Roboflow
56 How Fast is the M1 at Machine Learning? Benchmarking Apple's M1 and Intel's Chips
How Fast is the M1 at Machine Learning? Benchmarking Apple's M1 and Intel's Chips
Roboflow
57 CLIP: OpenAI's amazing new zero-shot image classifier
CLIP: OpenAI's amazing new zero-shot image classifier
Roboflow
58 How I hacked my Nest camera to run custom models
How I hacked my Nest camera to run custom models
Roboflow
59 Getting Started with the Roboflow Inference API
Getting Started with the Roboflow Inference API
Roboflow
60 Transfer Learning in Computer Vision | What, How, Why
Transfer Learning in Computer Vision | What, How, Why
Roboflow

This video teaches how to train YOLOv5 for image classification on a custom dataset, covering the setup of a Python environment, dataset format, and training process. It's a hands-on guide for beginners in computer vision.

Key Takeaways
  1. Set up a Python environment with GPU support
  2. Install required dependencies, including PyTorch
  3. Download a custom dataset for image classification
  4. Prepare the dataset by organizing images into class directories
  5. Train YOLOv5 using the custom dataset
  6. Validate the trained model on a validation set
💡 YOLOv5 can be used for image classification, and the dataset format for image classification is different from object detection, relying on directory names to indicate class labels.

Related Reads

Chapters (7)

Introduction
0:14 Image classification vs. object detection
1:42 Setting up python environment
3:00 Dataset format
4:02 Getting open source data from Roboflow Universe
4:48 Training classification model
5:40 Outro
Up next
9-Phase Computer Vision Roadmap 2026 | AI & Deep Learning | #shorts
SCALER
Watch →