Erste Schritte

Befehlszeilenschnittstelle

Die Befehlszeilenschnittstelle (CLI) von Ultralytics bietet eine einfache Möglichkeit, Ultralytics-YOLO-Modelle ohne Python-Code zu verwenden. Mit der CLI kannst du jede Aufgabe und jeden Modus direkt im Terminal über den Befehl yolo ausführen.



Ansehen: Ultralytics YOLO meistern: CLI
Beispiel

Ultralytics-Befehle yolo verwenden die folgende Syntax:

yolo TASK MODE ARGS

Dabei gilt:

  • TASK (optional) ist einer der Werte [detect, segment, semantic, depth, classify, pose, obb]
  • MODE (erforderlich) ist einer der Werte [train, val, predict, export, track, benchmark]
  • ARGS (optional) sind beliebig viele benutzerdefinierte Paare aus arg=value wie imgsz=320, die Standardwerte überschreiben.

Alle ARGS findest du im vollständigen Konfigurationsleitfaden oder mit yolo cfg.

Dabei gilt:

  • TASK (optional) ist einer der Werte [detect, segment, semantic, depth, classify, pose, obb]. Wenn der Wert nicht ausdrücklich angegeben wird, versucht YOLO, TASK anhand des Modelltyps zu ermitteln.
  • MODE (erforderlich) ist einer der Werte [train, val, predict, export, track, benchmark].
  • ARGS (optional) sind beliebig viele benutzerdefinierte Paare aus arg=value wie imgsz=320, die Standardwerte überschreiben. Eine vollständige Liste der verfügbaren ARGS findest du auf der Seite Konfiguration und mit default.yaml.
Warnung

Argumente müssen als Paare aus arg=val übergeben werden. Die Werte werden durch ein Gleichheitszeichen = getrennt; die Paare werden durch Leerzeichen voneinander abgegrenzt. Verwende weder Argumentpräfixe -- noch Kommas , zwischen den Argumenten.

  • yolo predict model=yolo26n.pt imgsz=640 conf=0.25 ✅
  • yolo predict model yolo26n.pt imgsz 640 conf 0.25 ❌
  • yolo predict --model yolo26n.pt --imgsz 640 --conf 0.25 ❌

Trainieren#

Trainiere YOLO 100 Epochen lang mit Bildgröße 640 auf dem COCO8-Datensatz.

Beispiel

Starte das Training von YOLO26n mit COCO8 für 100 Epochen und einer Bildgröße von 640:

yolo detect train data=coco8.yaml model=yolo26n.pt epochs=100 imgsz=640

Validieren#

Validiere die Genauigkeit des trainierten Modells mit dem COCO8-Datensatz. Ein benutzerdefiniertes Modell verwendet erneut sein Trainings-data, wenn data nicht angegeben ist; bei offiziellen Gewichten wird standardmäßig auf das aufgabenbezogene coco8.yaml zurückgegriffen.

Beispiel

Validiere ein offizielles YOLO26n-Modell:

yolo detect val model=yolo26n.pt data=coco8.yaml

Vorhersagen#

Verwende ein trainiertes Modell, um Vorhersagen für Bilder auszuführen.

Beispiel

Führe Vorhersagen mit einem offiziellen YOLO26n-Modell aus:

yolo detect predict model=yolo26n.pt source='https://ultralytics.com/images/bus.jpg'

Exportieren#

Exportiere ein Modell in ein anderes Format wie ONNX oder CoreML.

Beispiel

Exportiere ein offizielles YOLO26n-Modell ins ONNX-Format:

yolo export model=yolo26n.pt format=onnx

Die verfügbaren Ultralytics-Exportformate sind in der Tabelle unten aufgeführt. Mit dem Argument format kannst du in jedes Format exportieren, zum Beispiel mit format='onnx' oder format='engine'.

FormatArgument formatModellMetadatenArgumente
PyTorch-yolo26n.pt✅-
TorchScripttorchscriptyolo26n.torchscript✅imgsz, quantize, dynamic, nms, batch, device
ONNXonnxyolo26n.onnx✅imgsz, quantize, dynamic, simplify, opset, nms, batch, data, fraction, device
OpenVINOopenvinoyolo26n_openvino_model/✅imgsz, quantize, dynamic, nms, batch, data, fraction, device
TensorRTengineyolo26n.engine✅imgsz, quantize, dynamic, simplify, opset, workspace, nms, batch, data, fraction, device
CoreMLcoremlyolo26n.mlpackage✅imgsz, dynamic, quantize, nms, batch, device
Apple Core AIcoreaiyolo26n.aimodel✅imgsz, batch, quantize
TF SavedModelsaved_modelyolo26n_saved_model/✅imgsz, quantize, opset, nms, batch, data, fraction, device
TF GraphDefpbyolo26n.pb❌imgsz, opset, batch, device
TF Edge TPUedgetpuyolo26n_edgetpu.tflite✅imgsz, quantize, opset, data, fraction, device
LiteRTlitertyolo26n.tflite✅imgsz, quantize, batch, data, fraction, device
PaddlePaddlepaddleyolo26n_paddle_model/✅imgsz, batch, device
MNNmnnyolo26n.mnn✅imgsz, batch, dynamic, quantize, simplify, opset, nms, device
NCNNncnnyolo26n_ncnn_model/✅imgsz, quantize, device
IMX500imxyolo11n_imx_model/✅imgsz, quantize, data, fraction, nms, device
RKNNrknnyolo26n_rknn_model/✅imgsz, batch, name, quantize, simplify, opset, data, fraction, device
ExecuTorchexecutorchyolo26n_executorch_model/✅imgsz, quantize, batch, data, fraction, device
Axeleraaxelerayolo26n_axelera_model/✅imgsz, batch, quantize, data, fraction, device
DEEPXdeepxyolo26n_deepx_model/✅imgsz, quantize, simplify, opset, data, optimize, device
Qualcomm QNNqnnyolo26n_qnn.onnx✅imgsz, batch, name, quantize, simplify, opset, data, fraction, device
Hailohailoyolo26n_hailo_model/✅imgsz, name, quantize, data, fraction, simplify, conf, iou, device
Huawei Ascendascendyolo26n_ascend_model/✅imgsz, batch, name, quantize, opset, simplify, nms, device
AMD Xilinxxilinxyolo26n_xilinx_model/✅imgsz, name, quantize, data, fraction, opset, simplify, device
NXPnxpyolo26n_nxp.tflite✅imgsz, quantize, data, fraction, device
ST Edge AIstedgeaiyolo26n_stedgeai.onnx✅imgsz, quantize, data, fraction, opset, simplify, device

nms=None gibt standardmäßig Rohdaten für externe NMS aus (YOLO26 behält seinen Kopf ohne NMS auf Axelera). Setze nms=False, um einen verfügbaren Kopf ohne NMS auszuwählen; nicht unterstützte Formate greifen auf ihren nativen Ausgabepfad zurück. Die oben aufgeführten Einträge für nms kennzeichnen Formate, die NMS mit nms=True einbetten können.

Alle Details zu export findest du auf der Seite Export.

Standardargumente überschreiben#

Du kannst Standardargumente überschreiben, indem du sie in der CLI als arg=value-Paare übergibst.

Tipp

Trainiere ein Erkennungsmodell 10 Epochen lang mit einer Lernrate von 0.01:

yolo detect train data=coco8.yaml model=yolo26n.pt epochs=10 optimizer=SGD lr0=0.01

Standardkonfigurationsdatei überschreiben#

Überschreibe die Konfigurationsdatei default.yaml vollständig, indem du mit dem Argument cfg eine neue Datei übergibst, zum Beispiel cfg=custom.yaml.

Erstelle dazu zunächst mit dem Befehl yolo copy-cfg eine Kopie von default.yaml in deinem aktuellen Arbeitsverzeichnis. Dabei wird eine Datei default_copy.yaml erstellt.

Anschließend kannst du diese Datei zusammen mit zusätzlichen Argumenten als cfg=default_copy.yaml übergeben, zum Beispiel imgsz=320 wie in diesem Beispiel:

Beispiel
yolo copy-cfg
yolo cfg=default_copy.yaml imgsz=320

Befehle für Lösungen#

Ultralytics stellt über die CLI sofort einsatzbereite Lösungen für gängige Computer-Vision-Anwendungen bereit. Der Befehl yolo solutions bietet Objekterkennung und -zählung, Zuschneiden, Weichzeichnen, Trainingsüberwachung, Heatmaps, Instanzsegmentierung, VisionEye, Geschwindigkeitsschätzung, Warteschlangenverwaltung, Analysen, Streamlit-Inferenz, zonenbasiertes Tracking, Bereichszählung, Sicherheitsalarme und Parkraummanagement – die vollständige Übersicht findest du auf der Seite Solutions. Führe yolo solutions help aus, um alle unterstützten Lösungen und ihre Argumente aufzulisten.

Beispiel

Zähle Objekte in einem Video oder Livestream:

yolo solutions count show=True
yolo solutions count source="path/to/video.mp4" # specify video file path

Weitere Informationen zu den Ultralytics-Lösungen findest du auf der Seite Solutions.

Häufig gestellte Fragen#

  • Um ein Modell über die CLI zu trainieren, führe im Terminal einen einzelnen Befehl aus. Um beispielsweise ein Erkennungsmodell 10 Epochen lang zu trainieren, führe Folgendes aus:

    yolo train data=coco8.yaml model=yolo26n.pt epochs=10

    Dieser Befehl verwendet den Modus train mit bestimmten Argumenten. Eine vollständige Liste der verfügbaren Argumente findest du im Konfigurationsleitfaden.

  • Die Ultralytics YOLO CLI unterstützt verschiedene Aufgaben, darunter Objekterkennung, Segmentierung, semantische Segmentierung, Tiefenschätzung, Klassifizierung, Posenschätzung und Erkennung orientierter Begrenzungsrahmen. Du kannst außerdem Folgendes ausführen:

    • Modell trainieren: Führe yolo train data=<data.yaml> model=<model.pt> epochs=<num> aus.
    • Vorhersagen ausführen: Verwende yolo predict model=<model.pt> source=<data_source> imgsz=<image_size>.
    • Modell exportieren: Führe yolo export model=<model.pt> format=<export_format> aus.
    • Lösungen verwenden: Führe yolo solutions <solution_name> für sofort einsatzbereite Anwendungen aus.

    Passe jede Aufgabe mit verschiedenen Argumenten an. Ausführliche Syntaxangaben und Beispiele findest du in den jeweiligen Abschnitten, etwa Train, Predict und Export.

  • Um die Genauigkeit eines Modells zu validieren, verwende den Modus val. Um beispielsweise ein vortrainiertes Erkennungsmodell mit einer Batch-Größe von 1 und einer Bildgröße von 640 zu validieren, führe folgenden Befehl aus:

    yolo val model=yolo26n.pt data=coco8.yaml batch=1 imgsz=640

    Dieser Befehl wertet das Modell anhand des angegebenen Datensatzes aus und liefert Leistungskennzahlen wie mAP, Präzision und Recall. Weitere Informationen findest du im Abschnitt Val.

  • Du kannst YOLO-Modelle in verschiedene Formate exportieren, darunter ONNX, TensorRT, CoreML, TensorFlow und weitere. Um ein Modell beispielsweise in das ONNX-Format zu exportieren, führe Folgendes aus:

    yolo export model=yolo26n.pt format=onnx

    Der Exportbefehl unterstützt zahlreiche Optionen, mit denen du dein Modell für bestimmte Bereitstellungsumgebungen optimieren kannst. Eine vollständige Übersicht über alle verfügbaren Exportformate und ihre jeweiligen Parameter findest du auf der Seite Export.

  • Ultralytics stellt über den Befehl solutions sofort einsatzbereite Lösungen bereit. Um beispielsweise Objekte in einem Video zu zählen:

    yolo solutions count source="path/to/video.mp4"

    Diese Lösungen erfordern nur wenig Konfiguration und bieten sofort einsatzbereite Funktionen für gängige Computer-Vision-Aufgaben. Führe yolo solutions help aus, um alle verfügbaren Lösungen anzuzeigen. Jede Lösung bietet bestimmte Parameter, die du an deine Anforderungen anpassen kannst.

Kommentare28

Stell eine Frage, teile deine Ergebnisse oder hilf jemand anderem.

  1. Lishiquan12GitHub

    Usage: yolo [OPTIONS] COMMAND [ARGS]... Try 'yolo -h' for help.

    Error: No such command 'detect'. why?

    1
    1. Glenn JocherUltralytics

      嘿!看起来你在尝试使用 detect 命令,但这实际上并不直接作为命令使用。😅 在YOLOv8 CLI中,detect 更像是一个任务类型标识符,而不是直接使用的命令。

      比如说,如果你想要对一张图片进行预测(检测),你可以这样做:

      yolo detect predict model=yolov8n.pt source='path/to/image.jpg'

      这里 detect 指出你想要进行的是物体检测任务,predict 是你想要进行的模式,接着是模型和图像源的具体参数。🔍

      确保检查 Ultralytics YOLO 文档 获取更多详细信息和参数选项!希望这有助于解决问题!

    2. Glenn JocherUltralytics

      看起来你遇到了 'yolo detect' 是无效命令 的问题。 😊 对于YOLOv8 CLI的用法, 实际上你不需要直接使用 "detect" 作为命令。以下是一个简单的例子,演示如何正确地使用 CLI 来运行一个预测:

      yolo predict model=yolov8n.pt source='path/to/your/image.jpg'

      在这个例子中,我们使用 predict 而不是 detect,然后指定模型和要进行预测的数据源。希望这能帮助到你!如果还有其他疑问,欢迎继续提问。👍

  2. User

    Hello Team Ultralytics,

    Good morning!

    Many thanks for the great work.

    Couple of questions:

    1. How can i generate same graphs (graphs after training) after using the trained model on my unsense samples data?
    2. I can use the target folder after training the model, however, it only exports the images with the prediction boxes. I want to have a pie chart or bar chart or even the same plots it exports after the training run
    3. For the object detection via a video, if i have 4 images to display in one second, the model looks the same image multiple times. How can we correct the frames reading?

    Looking forward to your kind input,

    Kind regards,

    MUK

  3. duoerkuGitHub

    你好,进一部沟通请联系15680550171, 或者添加微信 BK-Mike

    1. Glenn JocherUltralytics(bearbeitet)

      @yizhihuo666 好问题!当你更新到最新版本的Ultralytics库时,不指定模型时使用的默认模型会随版本更新(现在检测任务默认为 yolo26n.pt)。这就是为什么你的原始命令会提示下载新的默认模型文件。

      如果你想继续使用YOLOv8模型,可以显式指定模型路径:

      yolo train model=yolov8n.pt data=your_data.yaml epochs=100

      如果你想使用最新的YOLO26模型(推荐),可以直接使用:

      yolo train model=yolo26n.pt data=your_data.yaml epochs=100

      YOLO26提供了更好的性能和准确性,所以建议升级到新模型。

      @duoerku 请在GitHub上提出具体的技术问题,我们会在这里为你提供支持,无法提供私人联系方式。

    2. yizhihuo666GitHub

      Thank you for your reply. As you mentioned, the system has now been updated to the YOLOv11 algorithm. I would like to know how I should proceed if I want to train the yolov8n.pt model using the YOLOv8 algorithm. Do I need to revert to a previous version of Ultralytics?

    3. Glenn JocherUltralytics(bearbeitet)

      @yizhihuo666 You don't need to downgrade Ultralytics! The current version still fully supports YOLOv8 models. Simply specify the YOLOv8 model explicitly in your command:

      yolo train model=yolov8n.pt data=your_data.yaml epochs=100

      The latest Ultralytics version supports both YOLOv8 and YOLO26 models - it just defaults to the current default model (yolo26n.pt for detection) when no model is specified. By explicitly using model=yolov8n.pt, you'll train with the YOLOv8 architecture as intended.

  4. yizhihuo666GitHub

    May I ask which algorithm is used by default for training through the ultralytic command line, YOLOV8 or YOLOV11

    1. yizhihuo666GitHub

      I trained yolov8n.pt using the command line in 2023 and recently updated the latest version of the ultralytic library. I found that when I used the original command, it kept prompting me to download the yolo11n.pt file

  5. muhammadrizwan11GitHub

    I noticed some discrepancies in the training and validation commands under the CLI chapter of the Ultralytics YOLO documentation. The documented training command is written as '' yolo detect train data=coco8.yaml model=yolo11n.pt epochs=100 imgsz=640 '' but the correct command should be '' yolo train data=coco8.yaml model=yolo11n.pt epochs=10 lr0=0.01'' The word "detect" should be removed. Similarly, the validation command is written as '' yolo detect val model=yolo11n.pt'' , whereas the correct command should be '' yolo val model=yolo11n.pt data=coco8.yaml batch=1 imgsz=640 ''. Again, "detect" is unnecessary, and important parameters such as the dataset (data=coco8.yaml), batch size (batch=1), and image size (imgsz=640) are missing. These inconsistencies might cause confusion for users following the documentation. Could the team review and update this section for accuracy? i am also doing working in yolo https://github.com/muhammadrizwan11

    1. Glenn JocherUltralytics

      @muhammadrizwan11 thank you for pointing this out! You're correct that the detect task argument is optional in CLI commands when the model type is specified, as YOLO can infer the task from the model name. Both yolo detect train and yolo train syntaxes are valid, but we'll standardize the docs to use the more concise form where possible. The validation example should indeed include explicit parameters for clarity, even though data is inherited from training. We'll update the documentation to reflect these points. For reference, see the CLI Syntax section in the Ultralytics YOLO documentation.

  6. aryakptGitHub

    HI, can you help me, how do i save the validation result if i use CLI? Because i clone github ultralytics directly

    1. Glenn JocherUltralytics(bearbeitet)

      @aryakpt validation results (metrics and plots such as the confusion matrix) are saved to a run folder like runs/detect/val by default. Add save_json=True to also save predictions as a COCO-format JSON file:

      yolo val model=path/to/best.pt data=data.yaml save_json=True

    2. aryakptGitHub(bearbeitet)

      thanks glenn for the response. but how can i access the val result like this using CLI? I want to save it in a variable

      best_model = YOLO(f"{output_path}/train{suffix}/weights/best.pt")
      val_result = best_model.val(data=data,  project=output_path)
      map50 = val_result.box.map50
    3. Glenn JocherUltralytics(bearbeitet)

      The CLI doesn't return variables, and save_json=True saves per-image predictions in COCO JSON format rather than the summary metrics. To access metrics like mAP50 programmatically, use the Python API:

      from ultralytics import YOLO
      
      metrics = YOLO("path/to/best.pt").val(data="data.yaml")
      print(metrics.box.map50)

      For details, see the Val mode documentation.

  7. sakrigGitHub

    Apple's NeuralEngine API accelerates models for all new Apple products with the M4 chips.

    Does the IOS CLI app use the NeuralEngine for all Apple M4 products? Does Ultralytics support the M4 processor on the latest Mac, MacMini, Mac Pro, iPad, iPhone ...?

    Seems straight forward to support the M4 NeuralEngine for all Apple products, but I have not tried.

    1. Glenn JocherUltralytics

      @sakrig ultralytics YOLO models can be exported to CoreML format for Apple devices, which leverages Apple's native acceleration including NeuralEngine where available. For M4 support, ensure you're using the latest PyTorch versions with macOS MPS backend. See our CoreML export docs for implementation details.

    1. Glenn JocherUltralytics

      @arasul42 yes, you can pass a hyperparameter file in the CLI using the cfg argument, like this: yolo train cfg=your_hyperparameters.yaml.

      2
  8. duoerkuGitHub

    你好,进一部沟通请联系15680550171, 或者添加微信 BK-Mike

    1. Glenn JocherUltralytics

      @duoerku 你好!很抱歉,我们无法通过电话或微信进行交流,但我们很乐意在这个问题跟踪系统中帮助你解决任何有关Ultralytics YOLO的问题。如果你有任何技术问题或需要进一步的帮助,请随时在这里详细说明,我们会尽快给你回复。感谢你的理解,并期待你的回复。🙂

    1. Paula DerrengerUltralytics

      您好,谢谢您对Ultralytics YOLOv8的兴趣!🚀 对于技术支持和进一步的沟通,请优先利用GitHub Issues功能提出您的问题或需求,这样我们能够提供更有条理且可追踪的支持。

      就您提供的信息来看,您似乎对命令行界面(CLI)的使用方法有兴趣,这里是可以通过几个简单示例来帮助您开始:

      1. 训练一个模型:

        yolo train data=coco128.yaml model=yolov8n.pt epochs=10 lr0=0.01
      2. 运行预测:

        yolo predict model=yolov8n-seg.pt source='https://youtu.be/LNwODJXcvt4' imgsz=320
      3. 验证模型:

        yolo val model=yolov8n.pt data=coco128.yaml batch=1 imgsz=640
      4. 导出模型为ONNX格式:

        yolo export model=yolov8n-cls.pt format=onnx imgsz=224,128

      更多详细命令和选项,请参阅我们的官方文档。如果有更具体的问题或需求,欢迎在GitHub上开启一个issue进行讨论。🤗