명령줄 인터페이스

Ultralytics 명령줄 인터페이스(CLI)는 Python 코드를 작성하지 않고도 Ultralytics YOLO 모델을 간편하게 사용할 수 있는 방법을 제공합니다. CLI를 사용하면 yolo 명령으로 터미널에서 모든 작업과 모드를 직접 실행할 수 있습니다.



시청: Ultralytics YOLO 마스터하기: CLI
예제

Ultralytics yolo 명령어는 다음 구문을 사용합니다.

yolo TASK MODE ARGS

항목은 다음과 같습니다.

  • TASK(선택 사항)은 [detect, segment, semantic, depth, classify, pose, obb] 중 하나입니다.
  • MODE(필수)은 [train, val, predict, export, track, benchmark] 중 하나입니다.
  • ARGS(선택 사항)은 기본값을 재정의하는 imgsz=320와 같은 사용자 지정 arg=value 쌍을 원하는 개수만큼 지정할 수 있습니다.

전체 구성 가이드 또는 yolo cfg에서 모든 ARGS를 확인하세요.

항목은 다음과 같습니다.

  • TASK(선택 사항)은 [detect, segment, semantic, depth, classify, pose, obb] 중 하나입니다. 명시적으로 전달하지 않으면 YOLO가 모델 유형을 바탕으로 TASK를 추론합니다.
  • MODE(필수)은 [train, val, predict, export, track, benchmark] 중 하나입니다.
  • ARGS(선택 사항)은 기본값을 재정의하는 imgsz=320와 같은 사용자 지정 arg=value 쌍을 원하는 개수만큼 지정할 수 있습니다. 사용 가능한 ARGS의 전체 목록은 구성 페이지와 default.yaml를 참조하세요.
경고

인수는 arg=val 쌍으로 전달해야 합니다. 각 쌍의 인수는 등호 =로 구분하고, 쌍 사이에는 공백을 사용합니다. 인수 앞에 -- 접두사를 붙이거나 인수 사이에 쉼표 ,를 사용하지 마세요.

  • 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 ❌

학습#

이미지 크기 640으로 COCO8 데이터셋에서 100 에포크 동안 YOLO를 학습합니다.

예제

이미지 크기 640으로 COCO8에서 100 에포크 동안 YOLO26n 학습을 시작합니다:

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

검증#

학습된 모델의 정확도를 COCO8 데이터셋에서 검증합니다. data을 생략하면 커스텀 모델은 학습에 사용한 data을 재사용하고, 공식 가중치는 기본 작업 coco8.yaml로 대체됩니다.

예제

공식 YOLO26n 모델을 검증합니다.

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

예측#

학습된 모델을 사용하여 이미지에서 예측을 실행합니다.

예제

공식 YOLO26n 모델로 예측합니다.

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

내보내기#

모델을 ONNX 또는 CoreML과 같은 다른 형식으로 내보냅니다.

예제

공식 YOLO26n 모델을 ONNX 형식으로 내보냅니다.

yolo export model=yolo26n.pt format=onnx

사용 가능한 Ultralytics 내보내기 형식은 아래 표에 나와 있습니다. format 인수로 원하는 형식으로 내보낼 수 있습니다(예: format='onnx' 또는 format='engine').

형식format 인수모델메타데이터인수
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은 외부 NMS를 위해 기본적으로 원시 출력을 사용합니다(YOLO26은 Axelera에서 NMS가 필요 없는 헤드를 유지합니다). 사용 가능한 NMS가 필요 없는 헤드를 선택하려면 nms=False를 설정하세요. 지원되지 않는 형식은 해당 형식의 기본 출력 경로로 대체됩니다. 위의 nms 항목은 nms=True로 NMS를 포함할 수 있는 형식을 나타냅니다.

Export 페이지에서 전체 export 세부 정보를 확인하세요.

기본 인수 재정의#

CLI에서 arg=value 쌍으로 인수를 전달하여 기본 인수를 재정의합니다.

팁

학습률 0.01로 10 epoch 동안 detection 모델을 학습합니다:

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

기본 설정 파일 재정의#

cfg 인수와 함께 새 파일(예: cfg=custom.yaml)을 전달하여 default.yaml 설정 파일 전체를 재정의합니다.

먼저 yolo copy-cfg 명령을 사용해 현재 작업 디렉터리에 default.yaml의 복사본을 만듭니다. 이 명령은 default_copy.yaml 파일을 생성합니다.

그런 다음 이 파일을 cfg=default_copy.yaml으로 전달하고, 이 예시의 imgsz=320과 같은 추가 인수를 함께 지정할 수 있습니다:

예제
yolo copy-cfg
yolo cfg=default_copy.yaml imgsz=320

Solutions 명령#

Ultralytics는 CLI를 통해 일반적인 컴퓨터 비전 애플리케이션에 바로 사용할 수 있는 솔루션을 제공합니다. yolo solutions 명령을 사용하면 객체 계수, 자르기, 블러 처리, 운동 모니터링, 히트맵, 인스턴스 세그멘테이션, VisionEye, 속도 추정, 대기열 관리, 분석, Streamlit 추론, 영역 기반 추적, 구역 계수, 보안 알람, 주차 관리를 사용할 수 있습니다. 전체 목록은 Solutions 페이지를 참조하세요. 지원되는 모든 솔루션과 인수를 확인하려면 yolo solutions help를 실행합니다.

예제

비디오 또는 라이브 스트림에서 객체를 계수합니다:

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

Ultralytics 솔루션에 관한 자세한 내용은 Solutions 페이지를 참조하세요.

자주 묻는 질문#

  • CLI를 사용해 모델을 학습하려면 터미널에서 한 줄 명령을 실행합니다. 예를 들어 detection 모델을 10 epoch 동안 학습하려면 다음을 실행합니다:

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

    이 명령은 특정 인수를 사용하여 train 모드로 실행됩니다. 사용 가능한 인수 전체 목록은 Configuration Guide를 참조하세요.

  • Ultralytics YOLO CLI는 detection, segmentation, semantic segmentation, depth estimation, classification, pose estimation, oriented bounding box detection 등 다양한 작업을 지원합니다. 다음과 같은 작업도 수행할 수 있습니다:

    • 모델 학습: yolo train data=<data.yaml> model=<model.pt> epochs=<num>을 실행합니다.
    • 예측 실행: yolo predict model=<model.pt> source=<data_source> imgsz=<image_size>을 사용합니다.
    • 모델 내보내기: yolo export model=<model.pt> format=<export_format>을 실행합니다.
    • 솔루션 사용: 바로 사용할 수 있는 애플리케이션을 위해 yolo solutions <solution_name>을 실행합니다.

    다양한 인수로 각 작업을 사용자 지정할 수 있습니다. 자세한 구문과 예시는 Train, Predict, Export 등의 해당 섹션을 참조하세요.

  • 모델의 정확도를 검증하려면 val 모드를 사용합니다. 예를 들어 배치 크기 1, 이미지 크기 640으로 사전 학습된 감지 모델을 검증하려면 다음을 실행합니다:

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

    이 명령은 지정된 데이터셋에서 모델을 평가하고 mAP, 정밀도, 재현율과 같은 성능 지표를 제공합니다. 자세한 내용은 Val 섹션을 참조하세요.

  • YOLO 모델은 ONNX, TensorRT, CoreML, TensorFlow 등 다양한 형식으로 내보낼 수 있습니다. 예를 들어 모델을 ONNX 형식으로 내보내려면 다음을 실행합니다:

    yolo export model=yolo26n.pt format=onnx

    내보내기 명령은 특정 배포 환경에 맞게 모델을 최적화하는 다양한 옵션을 지원합니다. 사용 가능한 모든 내보내기 형식과 각 형식의 매개변수에 관한 자세한 내용은 Export 페이지를 참조하세요.

  • Ultralytics는 solutions 명령을 통해 바로 사용할 수 있는 솔루션을 제공합니다. 예를 들어 비디오에서 객체를 계수하려면 다음을 실행합니다:

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

    이 솔루션은 최소한의 설정만으로 일반적인 컴퓨터 비전 작업을 즉시 수행할 수 있습니다. 사용 가능한 모든 솔루션을 확인하려면 yolo solutions help을 실행합니다. 각 솔루션에는 필요에 맞게 사용자 지정할 수 있는 특정 매개변수가 있습니다.

댓글28

질문을 하거나 결과를 공유하거나 다른 사람을 도와주세요.

    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,然后指定模型和要进行预测的数据源。希望这能帮助到你!如果还有其他疑问,欢迎继续提问。👍

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

    1. Glenn JocherUltralytics(수정됨)

      @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(수정됨)

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

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

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

  4. 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(수정됨)

      @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(수정됨)

      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(수정됨)

      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.

  5. 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
    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进行讨论。🤗