Are you sure you want to delete this access key?
comments | description | keywords |
---|---|---|
true | Learn how to structure datasets for YOLO classification tasks. Detailed folder structure and usage examples for effective training. | YOLO, image classification, dataset structure, CIFAR-10, Ultralytics, machine learning, training data, model evaluation |
For Ultralytics YOLO classification tasks, the dataset must be organized in a specific split-directory structure under the root
directory to facilitate proper training, testing, and optional validation processes. This structure includes separate directories for training (train
) and testing (test
) phases, with an optional directory for validation (val
).
Each of these directories should contain one subdirectory for each class in the dataset. The subdirectories are named after the corresponding class and contain all the images for that class. Ensure that each image file is named uniquely and stored in a common format such as JPEG or PNG.
Consider the CIFAR-10 dataset as an example. The folder structure should look like this:
cifar-10-/
|
|-- train/
| |-- airplane/
| | |-- 10008_airplane.png
| | |-- 10009_airplane.png
| | |-- ...
| |
| |-- automobile/
| | |-- 1000_automobile.png
| | |-- 1001_automobile.png
| | |-- ...
| |
| |-- bird/
| | |-- 10014_bird.png
| | |-- 10015_bird.png
| | |-- ...
| |
| |-- ...
|
|-- test/
| |-- airplane/
| | |-- 10_airplane.png
| | |-- 11_airplane.png
| | |-- ...
| |
| |-- automobile/
| | |-- 100_automobile.png
| | |-- 101_automobile.png
| | |-- ...
| |
| |-- bird/
| | |-- 1000_bird.png
| | |-- 1001_bird.png
| | |-- ...
| |
| |-- ...
|
|-- val/ (optional)
| |-- airplane/
| | |-- 105_airplane.png
| | |-- 106_airplane.png
| | |-- ...
| |
| |-- automobile/
| | |-- 102_automobile.png
| | |-- 103_automobile.png
| | |-- ...
| |
| |-- bird/
| | |-- 1045_bird.png
| | |-- 1046_bird.png
| | |-- ...
| |
| |-- ...
This structured approach ensures that the model can effectively learn from well-organized classes during the training phase and accurately evaluate performance during testing and validation phases.
!!! example
=== "Python"
```python
from ultralytics import YOLO
# Load a model
model = YOLO("yolo11n-cls.pt") # load a pretrained model (recommended for training)
# Train the model
results = model.train(data="path/to/dataset", epochs=100, imgsz=640)
```
=== "CLI"
```bash
# Start training from a pretrained *.pt model
yolo classify train data=path/to/data model=yolo11n-cls.pt epochs=100 imgsz=640
```
Ultralytics supports the following datasets with automatic download:
If you have your own dataset and would like to use it for training classification models with Ultralytics YOLO, ensure that it follows the format specified above under "Dataset Structure" and then point your data
argument to the dataset directory when initializing your training script.
To structure your dataset for Ultralytics YOLO classification tasks, you should follow a specific split-directory format. Organize your dataset into separate directories for train
, test
, and optionally val
. Each of these directories should contain subdirectories named after each class, with the corresponding images inside. This facilitates smooth training and evaluation processes. For an example, consider the CIFAR-10 dataset format:
cifar-10-/
|-- train/
| |-- airplane/
| |-- automobile/
| |-- bird/
| ...
|-- test/
| |-- airplane/
| |-- automobile/
| |-- bird/
| ...
|-- val/ (optional)
| |-- airplane/
| |-- automobile/
| |-- bird/
| ...
For more details, visit the Dataset Structure for YOLO Classification Tasks section.
Ultralytics YOLO supports automatic downloading of several datasets for image classification, including Caltech 101, Caltech 256, CIFAR-10, CIFAR-100, Fashion-MNIST, ImageNet, ImageNet-10, Imagenette, Imagewoof, and MNIST. These datasets are structured in a way that makes them easy to use with YOLO. Each dataset's page provides further details about its structure and applications.
To use your own dataset with Ultralytics YOLO, ensure it follows the specified directory format required for the classification task, with separate train
, test
, and optionally val
directories, and subdirectories for each class containing the respective images. Once your dataset is structured correctly, point the data
argument to your dataset's root directory when initializing the training script. Here's an example in Python:
from ultralytics import YOLO
# Load a model
model = YOLO("yolo11n-cls.pt") # load a pretrained model (recommended for training)
# Train the model
results = model.train(data="path/to/your/dataset", epochs=100, imgsz=640)
More details can be found in the Adding your own dataset section.
Ultralytics YOLO offers several benefits for image classification, including:
yolo11n-cls.pt
to jump-start your training process.For additional insights and real-world applications, you can explore Ultralytics YOLO.
Training a model using Ultralytics YOLO can be done easily in both Python and CLI. Here's an example:
!!! example
=== "Python"
```python
from ultralytics import YOLO
# Load a model
model = YOLO("yolo11n-cls.pt") # load a pretrained model
# Train the model
results = model.train(data="path/to/dataset", epochs=100, imgsz=640)
```
=== "CLI"
```bash
# Start training from a pretrained *.pt model
yolo classify train data=path/to/data model=yolo11n-cls.pt epochs=100 imgsz=640
```
These examples demonstrate the straightforward process of training a YOLO model using either approach. For more information, visit the Usage section and the Train page for classification tasks.
Press p or to see the previous file or, n or to see the next file
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?