YOLO Vision 2024 is here!——图像分类

Image classification is the simplest of the three tasks and involves classifying an entire image into one of a set of predefined classes.
图像分类是这三项任务中最简单的一项,涉及将整个图像分类为一组预定义类别中的一个。

The output of an image classifier is a single class label and a confidence score. Image classification is useful when you need to know only what class an image belongs to and don't need to know where objects of that class are located or what their exact shape is.
图像分类器的输出是单个类别标签和置信度得分。当您只需要知道图像属于哪个类别,而不需要知道该类别的对象位于何处或其确切形状时,图像分类非常有用。



Watch: Explore Ultralytics YOLO Tasks: Image Classification using Ultralytics HUB
观看:探索Ultralytics YOLO任务:使用Ultralytics HUB进行图像分类

Tip 尖端

YOLOv8 Classify models use the -cls suffix, i.e. yolov8n-cls.pt and are pretrained on ImageNet.
YOLOv 8 Classify模型使用-cls后缀,即yolov8n-cls.pt,并在ImageNet上进行预训练。

Models 模型

YOLOv8 pretrained Classify models are shown here. Detect, Segment and Pose models are pretrained on the COCO dataset, while Classify models are pretrained on the ImageNet dataset.
这里显示了YOLOv 8预训练的Classify模型。检测、分割和姿态模型在COCO数据集上进行预训练,而分类模型在ImageNet数据集上进行预训练。

Models download automatically from the latest Ultralytics release on first use.
模型在首次使用时自动从最新的Ultralytics版本下载。

Modelsize 大小
(pixels) (像素)
acc
top1
acc
top5
Speed 速度
CPU ONNX
(ms) (毫秒)
Speed 速度
A100 TensorRT
(ms) (毫秒)
params
(M) (百万)
FLOPs
(B) at 640 (B)在640
YOLOv8n-cls22469.088.312.90.312.74.3
YOLOv8s-cls22473.891.723.40.356.413.5
YOLOv8m-cls22476.893.585.40.6217.042.7
YOLOv8l-cls22476.893.5163.00.8737.599.7
YOLOv8x-cls22479.094.6232.01.0157.4154.8
  • acc values are model accuracies on the ImageNet dataset validation set.
    acc值是ImageNet数据集验证集上的模型精度。
    Reproduce by yolo val classify data=path/to/ImageNet device=0 复制者 yolo val classify data=path/to/ImageNet device=0
  • Speed averaged over ImageNet val images using an Amazon EC2 P4d instance.
    使用Amazon EC2 P4 d实例的ImageNet瓦尔图像的平均速度
    Reproduce by yolo val classify data=path/to/ImageNet batch=1 device=0|cpu 复制者 yolo val classify data=path/to/ImageNet batch=1 device=0|cpu

Train 火车

Train YOLOv8n-cls on the MNIST160 dataset for 100 epochs at image size 64. For a full list of available arguments see the Configuration page.
在MNIST 160数据集上训练YOLOv 8 n-cls 100个epoch,图像大小为64。有关可用参数的完整列表,请参见“配置”页。

Example 例如

from ultralytics import YOLO

# Load a model
model = YOLO("yolov8n-cls.yaml")  # build a new model from YAML
model = YOLO("yolov8n-cls.pt")  # load a pretrained model (recommended for training)
model = YOLO("yolov8n-cls.yaml").load("yolov8n-cls.pt")  # build from YAML and transfer weights

# Train the model
results = model.train(data="mnist160", epochs=100, imgsz=64)

Dataset format 数据集格式

YOLO classification dataset format can be found in detail in the Dataset Guide.
YOLO分类数据集格式可以在数据集指南中找到详细信息。

Val 瓦尔

Validate trained YOLOv8n-cls model accuracy on the MNIST160 dataset. No arguments are needed as the model retains its training data and arguments as model attributes.
在MNIST 160数据集上训练YOLOv 8 n-cls模型的准确性。不需要参数,因为模型保留其训练数据和参数作为模型属性。

Example 例如

from ultralytics import YOLO

# Load a model
model = YOLO("yolov8n-cls.pt")  # load an official model
model = YOLO("path/to/best.pt")  # load a custom model

# Validate the model
metrics = model.val()  # no arguments needed, dataset and settings remembered
metrics.top1  # top1 accuracy
metrics.top5  # top5 accuracy

Predict 预测

Use a trained YOLOv8n-cls model to run predictions on images.
使用经过训练的YOLOv 8 n-cls模型对图像进行预测。

Example 例如

from ultralytics import YOLO

# Load a model
model = YOLO("yolov8n-cls.pt")  # load an official model
model = YOLO("path/to/best.pt")  # load a custom model

# Predict with the model
results = model("https://ultralytics.com/images/bus.jpg")  # predict on an image

See full predict mode details in the Predict page.
Predict页面中查看完整的预测模式详情。

Export 出口

Export a YOLOv8n-cls model to a different format like ONNX, CoreML, etc.
将YOLOv 8 n-cls模型导出为不同的格式,如ONNX、CoreML等。

Example 例如

from ultralytics import YOLO

# Load a model
model = YOLO("yolov8n-cls.pt")  # load an official model
model = YOLO("path/to/best.pt")  # load a custom trained model

# Export the model
model.export(format="onnx")

Available YOLOv8-cls export formats are in the table below. You can export to any format using the format argument, i.e. format='onnx' or format='engine'. You can predict or validate directly on exported models, i.e. yolo predict model=yolov8n-cls.onnx. Usage examples are shown for your model after export completes.
可用的YOLOv 8-cls导出格式如下表所示。您可以使用format参数导出为任何格式,即format ='onnx'format ='engine'。您可以直接在导出的模型上进行预测或验证,即 yolo predict model=yolov8n-cls.onnx 。导出完成后,将显示模型的使用示例。

Format 格式format Argument
格式参数
ModelMetadata 元数据Arguments 论点
PyTorch-yolov8n-cls.pt-
TorchScripttorchscriptyolov8n-cls.torchscriptimgsz, optimize, batch
ONNXonnxyolov8n-cls.onnximgsz, half, dynamic, simplify, opset, batch
OpenVINOopenvinoyolov8n-cls_openvino_model/imgsz, half, int8, batch
TensorRTengine 发动机yolov8n-cls.engineimgsz, half, dynamic, simplify, workspace, int8, batch
CoreMLcoremlyolov8n-cls.mlpackageimgsz, half, int8, nms, batch
TF SavedModelsaved_model
保存的_模型
yolov8n-cls_saved_model/imgsz, keras, int8, batch
TF GraphDefpbyolov8n-cls.pbimgsz, batch
IMGSZ批次
TF Litetflite 特弗利特yolov8n-cls.tfliteimgsz, half, int8, batch
TF Edge TPUedgetpu
埃杰普
yolov8n-cls_edgetpu.tfliteimgsz 伊姆斯
TF.jstfjsyolov8n-cls_web_model/imgsz, half, int8, batch
PaddlePaddlepaddle yolov8n-cls_paddle_model/
yolov 8 n-cls_桨_模型/
imgsz, batch
IMGSZ批次
NCNNncnnyolov8n-cls_ncnn_model/imgsz, half, batch

See full export details in the Export page.
在导出页面中查看完整的 export 详细信息。

FAQ

What is the purpose of YOLOv8 in image classification?
YOLOv 8在图像分类中的作用是什么?

YOLOv8 models, such as yolov8n-cls.pt, are designed for efficient image classification. They assign a single class label to an entire image along with a confidence score. This is particularly useful for applications where knowing the specific class of an image is sufficient, rather than identifying the location or shape of objects within the image.
YOLOv 8模型,如yolov8n-cls.pt,是为高效的图像分类而设计的。他们为整个图像分配一个单独的类别标签,沿着一个置信度得分。这对于知道图像的特定类别就足够的应用特别有用,而不是识别图像中对象的位置或形状。

How do I train a YOLOv8 model for image classification?
如何训练YOLOv 8模型进行图像分类?

To train a YOLOv8 model, you can use either Python or CLI commands. For example, to train a yolov8n-cls model on the MNIST160 dataset for 100 epochs at an image size of 64:
要训练YOLOv 8模型,您可以使用Python或CLI命令。例如,要在MNIST 160数据集上训练yolov 8 n-cls模型100个epoch,图像大小为64:

Example 例如

from ultralytics import YOLO

# Load a model
model = YOLO("yolov8n-cls.pt")  # load a pretrained model (recommended for training)

# Train the model
results = model.train(data="mnist160", epochs=100, imgsz=64)

For more configuration options, visit the Configuration page.
有关更多配置选项,请访问配置页面。

Where can I find pretrained YOLOv8 classification models?
哪里可以找到预训练的YOLOv 8分类模型?

Pretrained YOLOv8 classification models can be found in the Models section. Models like yolov8n-cls.pt, yolov8s-cls.pt, yolov8m-cls.pt, etc., are pretrained on the ImageNet dataset and can be easily downloaded and used for various image classification tasks.
预训练的YOLOv8分类模型可以在模型部分找到。例如yolov8n-cls.ptyolov8s-cls.ptyolov8m-cls.pt等模型,在ImageNet数据集上进行预训练,可以轻松下载并用于各种图像分类任务。

How can I export a trained YOLOv8 model to different formats?
如何将经过训练的YOLOv 8模型导出为不同的格式?

You can export a trained YOLOv8 model to various formats using Python or CLI commands. For instance, to export a model to ONNX format:
您可以使用Python或CLI命令将经过训练的YOLOv8模型导出为各种格式。例如,要将模型导出为ONNX格式:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值