Zum Inhalt springen

Bildklassifizierung

Beispiele zur Bildklassifizierung

Image classification is the simplest of the three tasks and involves classifying an entire image into one of a set of predefined classes.

Die Ausgabe eines Bildklassifizierers ist eine einzelne Klassenbezeichnung und ein Vertrauenswert. Die Bildklassifizierung ist nützlich, wenn du nur wissen musst, zu welcher Klasse ein Bild gehört, ohne zu wissen, wo sich die Objekte dieser Klasse befinden oder welche Form sie genau haben.



Pass auf: Erkunde Ultralytics YOLO Aufgaben: Bildklassifizierung mit Ultralytics HUB

Tipp

YOLO11 Classify models use the -cls Suffix, d.h.. yolo11n-cls.pt und sind vorgebildet auf ImageNet.

Modelle

YOLO11 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.

Die Modelle werden bei der ersten Verwendung automatisch von der neuestenVersion von Ultralytics heruntergeladen.

ModellGröße
(Pixel)
acc
top1
acc
top5
Geschwindigkeit
CPU ONNX
(ms)
Speed
T4 TensorRT10
(ms)
params
(M)
FLOPs
(B) at 640
YOLO11n-cls22470.089.45.0 ± 0.31.1 ± 0.01.63.3
YOLO11s-cls22475.492.77.9 ± 0.21.3 ± 0.05.512.1
YOLO11m-cls22477.393.917.2 ± 0.42.0 ± 0.010.439.3
YOLO11l-cls22478.394.323.2 ± 0.32.8 ± 0.012.949.4
YOLO11x-cls22479.594.941.4 ± 0.93.8 ± 0.028.4110.4
  • acc Werte sind Modellgenauigkeiten auf den ImageNet Datensatz Validierungssatz.
    Reproduzieren durch yolo val classify data=path/to/ImageNet device=0
  • Geschwindigkeit über ImageNet val-Bilder gemittelt, indem ein Amazon EC2 P4d Instanz.
    Reproduzieren durch yolo val classify data=path/to/ImageNet batch=1 device=0|cpu

Zug

Train YOLO11n-cls on the MNIST160 dataset for 100 epochs at image size 64. For a full list of available arguments see the Configuration page.

Beispiel

from ultralytics import YOLO

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

# Train the model
results = model.train(data="mnist160", epochs=100, imgsz=64)
# Build a new model from YAML and start training from scratch
yolo classify train data=mnist160 model=yolo11n-cls.yaml epochs=100 imgsz=64

# Start training from a pretrained *.pt model
yolo classify train data=mnist160 model=yolo11n-cls.pt epochs=100 imgsz=64

# Build a new model from YAML, transfer pretrained weights to it and start training
yolo classify train data=mnist160 model=yolo11n-cls.yaml pretrained=yolo11n-cls.pt epochs=100 imgsz=64

Format des Datensatzes

YOLO Das Format der Klassifizierungsdatensätze findest du im Detail im Datensatz-Leitfaden.

Val

Validate trained YOLO11n-cls model accuracy on the MNIST160 dataset. No arguments are needed as the model seine Ausbildung beibehält data und Argumente als Modellattribute.

Beispiel

from ultralytics import YOLO

# Load a model
model = YOLO("yolo11n-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
yolo classify val model=yolo11n-cls.pt  # val official model
yolo classify val model=path/to/best.pt  # val custom model

Vorhersage

Use a trained YOLO11n-cls model to run predictions on images.

Beispiel

from ultralytics import YOLO

# Load a model
model = YOLO("yolo11n-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
yolo classify predict model=yolo11n-cls.pt source='https://ultralytics.com/images/bus.jpg'  # predict with official model
yolo classify predict model=path/to/best.pt source='https://ultralytics.com/images/bus.jpg'  # predict with custom model

Siehe voll predict Modus Details in der Vorhersage Seite.

exportieren

Export a YOLO11n-cls model to a different format like ONNX, CoreML, etc.

Beispiel

from ultralytics import YOLO

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

# Export the model
model.export(format="onnx")
yolo export model=yolo11n-cls.pt format=onnx  # export official model
yolo export model=path/to/best.pt format=onnx  # export custom trained model

Available YOLO11-cls export formats are in the table below. You can export to any format using the format Argument, d.h. format='onnx' oder format='engine'. Du kannst exportierte Modelle direkt vorhersagen oder validieren, d.h. yolo predict model=yolo11n-cls.onnx. Nach Abschluss des Exports werden Anwendungsbeispiele für dein Modell angezeigt.

Formatformat ArgumentModellMetadatenArgumente
PyTorch-yolo11n-cls.pt-
TorchScripttorchscriptyolo11n-cls.torchscriptimgsz, optimize, batch
ONNXonnxyolo11n-cls.onnximgsz, half, dynamic, simplify, opset, batch
OpenVINOopenvinoyolo11n-cls_openvino_model/imgsz, half, int8, batch
TensorRTengineyolo11n-cls.engineimgsz, half, dynamic, simplify, workspace, int8, batch
CoreMLcoremlyolo11n-cls.mlpackageimgsz, half, int8, nms, batch
TF SavedModelsaved_modelyolo11n-cls_saved_model/imgsz, keras, int8, batch
TF GraphDefpbyolo11n-cls.pbimgsz, batch
TF Litetfliteyolo11n-cls.tfliteimgsz, half, int8, batch
TF Kante TPUedgetpuyolo11n-cls_edgetpu.tfliteimgsz
TF.jstfjsyolo11n-cls_web_model/imgsz, half, int8, batch
PaddlePaddlepaddleyolo11n-cls_paddle_model/imgsz, batch
NCNNncnnyolo11n-cls_ncnn_model/imgsz, half, batch

Siehe voll export Details in der exportieren Seite.

FAQ

What is the purpose of YOLO11 in image classification?

YOLO11 models, such as yolo11n-cls.ptsind für eine effiziente Bildklassifizierung konzipiert. Sie ordnen einem ganzen Bild eine einzige Klassenbezeichnung und eine Vertrauensbewertung zu. Dies ist besonders nützlich für Anwendungen, bei denen es ausreicht, die spezifische Klasse eines Bildes zu kennen, anstatt die Position oder Form von Objekten im Bild zu identifizieren.

How do I train a YOLO11 model for image classification?

To train a YOLO11 model, you can use either Python or CLI commands. For example, to train a yolo11n-cls Modell auf dem MNIST160-Datensatz für 100 Epochen bei einer Bildgröße von 64:

Beispiel

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="mnist160", epochs=100, imgsz=64)
yolo classify train data=mnist160 model=yolo11n-cls.pt epochs=100 imgsz=64

Weitere Konfigurationsoptionen findest du auf der Seite Konfiguration.

Where can I find pretrained YOLO11 classification models?

Pretrained YOLO11 classification models can be found in the Modelle Abschnitt. Modelle wie yolo11n-cls.pt, yolo11s-cls.pt, yolo11m-cls.ptusw., werden auf der Grundlage der ImageNet Datensatz und kann leicht heruntergeladen und für verschiedene Bildklassifizierungsaufgaben verwendet werden.

How can I export a trained YOLO11 model to different formats?

You can export a trained YOLO11 model to various formats using Python or CLI commands. For instance, to export a model to ONNX format:

Beispiel

from ultralytics import YOLO

# Load a model
model = YOLO("yolo11n-cls.pt")  # load the trained model

# Export the model to ONNX
model.export(format="onnx")
yolo export model=yolo11n-cls.pt format=onnx  # export the trained model to ONNX format

Ausführliche Informationen zu den Exportoptionen findest du auf der Seite Export.

How do I validate a trained YOLO11 classification model?

Um die Genauigkeit eines trainierten Modells anhand eines Datensatzes wie MNIST160 zu überprüfen, kannst du die folgenden Befehle verwenden: Python oder CLI :

Beispiel

from ultralytics import YOLO

# Load a model
model = YOLO("yolo11n-cls.pt")  # load the trained model

# Validate the model
metrics = model.val()  # no arguments needed, uses the dataset and settings from training
metrics.top1  # top1 accuracy
metrics.top5  # top5 accuracy
yolo classify val model=yolo11n-cls.pt  # validate the trained model

Weitere Informationen findest du im Abschnitt Validieren.

📅 Created 11 months ago ✏️ Updated 20 days ago

Kommentare