Giao diện dòng lệnh
Giao diện dòng lệnh (CLI) của Ultralytics cung cấp cách đơn giản để sử dụng model Ultralytics YOLO mà không cần viết mã Python. CLI hỗ trợ chạy trực tiếp mọi tác vụ và mode từ terminal bằng lệnh yolo.
Xem: Làm chủ Ultralytics YOLO: CLI
Các lệnh yolo của Ultralytics sử dụng cú pháp sau:
yolo TASK MODE ARGSTrong đó:
TASK(tùy chọn) là một trong các giá trị [detect, segment, semantic, depth, classify, pose, obb]MODE(bắt buộc) là một trong các giá trị [train, val, predict, export, track, benchmark]ARGS(tùy chọn) gồm bất kỳ số lượng cặparg=valuetùy chỉnh nào, chẳng hạnimgsz=320, dùng để ghi đè các giá trị mặc định.
Xem tất cả ARGS trong Hướng dẫn cấu hình đầy đủ hoặc bằng yolo cfg.
Trong đó:
TASK(tùy chọn) là một trong các giá trị[detect, segment, semantic, depth, classify, pose, obb]. Nếu không được chỉ định rõ, YOLO sẽ cố gắng suy luậnTASKtừ loại model.MODE(bắt buộc) là một trong các giá trị[train, val, predict, export, track, benchmark]ARGS(tùy chọn) gồm bất kỳ số lượng cặparg=valuetùy chỉnh nào, chẳng hạnimgsz=320, dùng để ghi đè các giá trị mặc định. Để xem danh sách đầy đủ cácARGShiện có, hãy tham khảo trang Cấu hình vàdefault.yaml.
Các đối số phải được truyền theo cặp arg=val, phân tách bằng dấu bằng = và ngăn cách giữa các cặp bằng dấu cách. Không sử dụng tiền tố đối số -- hoặc dấu phẩy , giữa các đối số.
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❌
Huấn luyện#
Huấn luyện YOLO trên dataset COCO8 trong 100 epoch với kích thước ảnh 640.
Bắt đầu huấn luyện YOLO26n trên COCO8 trong 100 epoch với kích thước ảnh 640:
yolo detect train data=coco8.yaml model=yolo26n.pt epochs=100 imgsz=640Đánh giá#
Xác thực độ chính xác của model đã huấn luyện trên dataset COCO8. Model tùy chỉnh sẽ dùng lại data trong quá trình huấn luyện nếu không chỉ định data; trọng số chính thức sẽ dùng giá trị mặc định của tác vụ coco8.yaml.
Đánh giá model YOLO26n chính thức:
yolo detect val model=yolo26n.pt data=coco8.yamlDự đoán#
Dùng model đã huấn luyện để chạy dự đoán trên ảnh.
Dự đoán bằng model YOLO26n chính thức:
yolo detect predict model=yolo26n.pt source='https://ultralytics.com/images/bus.jpg'Export#
Export model sang định dạng khác, chẳng hạn ONNX hoặc CoreML.
Export model YOLO26n chính thức sang định dạng ONNX:
yolo export model=yolo26n.pt format=onnxCác định dạng export Ultralytics hiện có được liệt kê trong bảng bên dưới. Bạn có thể export sang bất kỳ định dạng nào bằng tham số format, ví dụ: format='onnx' hoặc format='engine'.
| Định dạng | Đối số format | Model | Metadata | Đối số |
|---|---|---|---|---|
| PyTorch | - | yolo26n.pt | ✅ | - |
| TorchScript | torchscript | yolo26n.torchscript | ✅ | imgsz, quantize, dynamic, nms, batch, device |
| ONNX | onnx | yolo26n.onnx | ✅ | imgsz, quantize, dynamic, simplify, opset, nms, batch, data, fraction, device |
| OpenVINO | openvino | yolo26n_openvino_model/ | ✅ | imgsz, quantize, dynamic, nms, batch, data, fraction, device |
| TensorRT | engine | yolo26n.engine | ✅ | imgsz, quantize, dynamic, simplify, opset, workspace, nms, batch, data, fraction, device |
| CoreML | coreml | yolo26n.mlpackage | ✅ | imgsz, dynamic, quantize, nms, batch, device |
| Apple Core AI | coreai | yolo26n.aimodel | ✅ | imgsz, batch, quantize |
| TF SavedModel | saved_model | yolo26n_saved_model/ | ✅ | imgsz, quantize, opset, nms, batch, data, fraction, device |
| TF GraphDef | pb | yolo26n.pb | ❌ | imgsz, opset, batch, device |
| TF Edge TPU | edgetpu | yolo26n_edgetpu.tflite | ✅ | imgsz, quantize, opset, data, fraction, device |
| LiteRT | litert | yolo26n.tflite | ✅ | imgsz, quantize, batch, data, fraction, device |
| PaddlePaddle | paddle | yolo26n_paddle_model/ | ✅ | imgsz, batch, device |
| MNN | mnn | yolo26n.mnn | ✅ | imgsz, batch, dynamic, quantize, simplify, opset, nms, device |
| NCNN | ncnn | yolo26n_ncnn_model/ | ✅ | imgsz, quantize, device |
| IMX500 | imx | yolo11n_imx_model/ | ✅ | imgsz, quantize, data, fraction, nms, device |
| RKNN | rknn | yolo26n_rknn_model/ | ✅ | imgsz, batch, name, quantize, simplify, opset, data, fraction, device |
| ExecuTorch | executorch | yolo26n_executorch_model/ | ✅ | imgsz, quantize, batch, data, fraction, device |
| Axelera | axelera | yolo26n_axelera_model/ | ✅ | imgsz, batch, quantize, data, fraction, device |
| DEEPX | deepx | yolo26n_deepx_model/ | ✅ | imgsz, quantize, simplify, opset, data, optimize, device |
| Qualcomm QNN | qnn | yolo26n_qnn.onnx | ✅ | imgsz, batch, name, quantize, simplify, opset, data, fraction, device |
| Hailo | hailo | yolo26n_hailo_model/ | ✅ | imgsz, name, quantize, data, fraction, simplify, conf, iou, device |
| Huawei Ascend | ascend | yolo26n_ascend_model/ | ✅ | imgsz, batch, name, quantize, opset, simplify, nms, device |
| AMD Xilinx | xilinx | yolo26n_xilinx_model/ | ✅ | imgsz, name, quantize, data, fraction, opset, simplify, device |
| NXP | nxp | yolo26n_nxp.tflite | ✅ | imgsz, quantize, data, fraction, device |
| ST Edge AI | stedgeai | yolo26n_stedgeai.onnx | ✅ | imgsz, quantize, data, fraction, opset, simplify, device |
nms=None mặc định xuất dữ liệu thô để thực hiện NMS bên ngoài (YOLO26 vẫn giữ head không cần NMS trên Axelera). Đặt nms=False để chọn head không cần NMS hiện có; các định dạng không được hỗ trợ sẽ chuyển về đường dẫn xuất dữ liệu gốc của định dạng đó. Các mục nms ở trên xác định những định dạng có thể tích hợp NMS bằng nms=True.
Xem thông tin chi tiết đầy đủ về export trên trang Xuất.
Ghi đè các đối số mặc định#
Ghi đè các đối số mặc định bằng cách truyền chúng dưới dạng các cặp arg=value trong CLI.
Huấn luyện model phát hiện trong 10 epoch với learning rate 0.01:
yolo detect train data=coco8.yaml model=yolo26n.pt epochs=10 optimizer=SGD lr0=0.01Ghi đè tệp cấu hình mặc định#
Ghi đè hoàn toàn tệp cấu hình default.yaml bằng cách truyền tệp mới với đối số cfg, chẳng hạn như cfg=custom.yaml.
Để thực hiện việc này, trước tiên hãy tạo bản sao của default.yaml trong thư mục làm việc hiện tại bằng lệnh yolo copy-cfg, lệnh này tạo tệp default_copy.yaml.
Sau đó, bạn có thể truyền tệp này dưới dạng cfg=default_copy.yaml cùng với bất kỳ đối số bổ sung nào, như imgsz=320 trong ví dụ này:
yolo copy-cfg
yolo cfg=default_copy.yaml imgsz=320Các lệnh về giải pháp#
Ultralytics cung cấp các giải pháp sẵn dùng cho những ứng dụng thị giác máy tính phổ biến thông qua CLI. Lệnh yolo solutions cung cấp các chức năng đếm đối tượng, cắt ảnh, làm mờ, theo dõi bài tập thể dục, tạo bản đồ nhiệt, phân đoạn đối tượng, VisionEye, ước tính tốc độ, quản lý hàng đợi, phân tích, suy luận bằng Streamlit, theo dõi dựa trên vùng, đếm theo khu vực, cảnh báo an ninh và quản lý bãi đỗ xe — xem trang Giải pháp để biết danh mục đầy đủ. Chạy yolo solutions help để liệt kê tất cả giải pháp được hỗ trợ cùng các đối số của chúng.
Đếm đối tượng trong video hoặc luồng trực tiếp:
yolo solutions count show=True
yolo solutions count source="path/to/video.mp4" # specify video file pathĐể biết thêm thông tin về các giải pháp của Ultralytics, hãy truy cập trang Giải pháp.
Câu hỏi thường gặp#
Để huấn luyện model bằng CLI, hãy chạy một lệnh trên terminal. Ví dụ: để huấn luyện model phát hiện trong 10 epoch, hãy chạy:
yolo train data=coco8.yaml model=yolo26n.pt epochs=10Lệnh này sử dụng chế độ
trainvới các đối số cụ thể. Để xem danh sách đầy đủ các đối số hiện có, hãy tham khảo Hướng dẫn cấu hình.CLI Ultralytics YOLO hỗ trợ nhiều tác vụ, bao gồm phát hiện, phân đoạn, phân đoạn ngữ nghĩa, ước tính độ sâu, phân loại, ước tính pose và phát hiện hộp giới hạn có định hướng. Bạn cũng có thể thực hiện các thao tác như:
- Huấn luyện model: Chạy
yolo train data=<data.yaml> model=<model.pt> epochs=<num>. - Chạy dự đoán: Sử dụng
yolo predict model=<model.pt> source=<data_source> imgsz=<image_size>. - Xuất model: Thực thi
yolo export model=<model.pt> format=<export_format>. - Sử dụng giải pháp: Chạy
yolo solutions <solution_name>để dùng các ứng dụng có sẵn.
Tùy chỉnh từng tác vụ bằng nhiều đối số khác nhau. Để xem cú pháp và ví dụ chi tiết, hãy tham khảo các phần tương ứng như Huấn luyện, Dự đoán và Xuất.
- Huấn luyện model: Chạy
Để xác thực độ chính xác của model, hãy dùng mode
val. Ví dụ, để xác thực model phát hiện pretrained với batch size 1 và kích thước ảnh 640, hãy chạy:yolo val model=yolo26n.pt data=coco8.yaml batch=1 imgsz=640Lệnh này đánh giá model trên dataset được chỉ định và cung cấp các chỉ số hiệu năng như mAP, precision và recall. Để biết thêm chi tiết, hãy tham khảo phần Val.
Bạn có thể xuất model YOLO sang nhiều định dạng, bao gồm ONNX, TensorRT, CoreML, TensorFlow và các định dạng khác. Ví dụ: để xuất model sang định dạng ONNX, hãy chạy:
yolo export model=yolo26n.pt format=onnxLệnh xuất hỗ trợ nhiều tùy chọn để tối ưu hóa model cho các môi trường triển khai cụ thể. Để biết đầy đủ thông tin về tất cả định dạng xuất hiện có và tham số tương ứng, hãy truy cập trang Xuất.
Ultralytics cung cấp các giải pháp sẵn dùng thông qua lệnh
solutions. Ví dụ: để đếm đối tượng trong video:yolo solutions count source="path/to/video.mp4"Các giải pháp này cần rất ít cấu hình và cung cấp chức năng tức thì cho các tác vụ thị giác máy tính phổ biến. Để xem tất cả giải pháp hiện có, hãy chạy
yolo solutions help. Mỗi giải pháp có các tham số riêng để tùy chỉnh theo nhu cầu của bạn.
Bình luận28
Đặt câu hỏi, chia sẻ kết quả hoặc giúp đỡ người khác.
Lishiquan12
Usage: yolo [OPTIONS] COMMAND [ARGS]... Try 'yolo -h' for help.
Error: No such command 'detect'. why?
1
Glenn JocherUltralytics嘿!看起来你在尝试使用
detect命令,但这实际上并不直接作为命令使用。😅 在YOLOv8 CLI中,detect更像是一个任务类型标识符,而不是直接使用的命令。比如说,如果你想要对一张图片进行预测(检测),你可以这样做:
yolo detect predict model=yolov8n.pt source='path/to/image.jpg'这里
detect指出你想要进行的是物体检测任务,predict是你想要进行的模式,接着是模型和图像源的具体参数。🔍确保检查 Ultralytics YOLO 文档 获取更多详细信息和参数选项!希望这有助于解决问题!
JackeShen
too
Glenn JocherUltralytics看起来你遇到了
'yolo detect' 是无效命令的问题。 😊 对于YOLOv8 CLI的用法, 实际上你不需要直接使用 "detect" 作为命令。以下是一个简单的例子,演示如何正确地使用 CLI 来运行一个预测:yolo predict model=yolov8n.pt source='path/to/your/image.jpg'在这个例子中,我们使用
predict而不是detect,然后指定模型和要进行预测的数据源。希望这能帮助到你!如果还有其他疑问,欢迎继续提问。👍
UserHello Team Ultralytics,
Good morning!
Many thanks for the great work.
Couple of questions:
- How can i generate same graphs (graphs after training) after using the trained model on my unsense samples data?
- 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
- 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
duoerku
你好,进一部沟通请联系15680550171, 或者添加微信 BK-Mike
Glenn JocherUltralytics(đã chỉnh sửa)@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=100YOLO26提供了更好的性能和准确性,所以建议升级到新模型。
@duoerku 请在GitHub上提出具体的技术问题,我们会在这里为你提供支持,无法提供私人联系方式。
yizhihuo666
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?
Glenn JocherUltralytics(đã chỉnh sửa)@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=100The latest Ultralytics version supports both YOLOv8 and YOLO26 models - it just defaults to the current default model (
yolo26n.ptfor detection) when no model is specified. By explicitly usingmodel=yolov8n.pt, you'll train with the YOLOv8 architecture as intended.
yizhihuo666
May I ask which algorithm is used by default for training through the ultralytic command line, YOLOV8 or YOLOV11
yizhihuo666
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
muhammadrizwan11
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
Glenn JocherUltralytics@muhammadrizwan11 thank you for pointing this out! You're correct that the
detecttask argument is optional in CLI commands when the model type is specified, as YOLO can infer the task from the model name. Bothyolo detect trainandyolo trainsyntaxes 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 thoughdatais inherited from training. We'll update the documentation to reflect these points. For reference, see the CLI Syntax section in the Ultralytics YOLO documentation.
aryakpt
HI, can you help me, how do i save the validation result if i use CLI? Because i clone github ultralytics directly
Glenn JocherUltralytics(đã chỉnh sửa)@aryakpt validation results (metrics and plots such as the confusion matrix) are saved to a run folder like
runs/detect/valby default. Addsave_json=Trueto also save predictions as a COCO-format JSON file:yolo val model=path/to/best.pt data=data.yaml save_json=Truearyakpt(đã chỉnh sửa)
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
Glenn JocherUltralytics(đã chỉnh sửa)The CLI doesn't return variables, and
save_json=Truesaves 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.
sakrig
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.
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.
ashikrasul
Is there a way to pass the hypeparameter file in CLI during training?
Glenn JocherUltralytics@arasul42 yes, you can pass a hyperparameter file in the CLI using the
cfgargument, like this:yolo train cfg=your_hyperparameters.yaml.2muhammadrizwan11
thank you so much i was confused but you give us a good thing
duoerku
你好,进一部沟通请联系15680550171, 或者添加微信 BK-Mike
Glenn JocherUltralytics@duoerku 你好!很抱歉,我们无法通过电话或微信进行交流,但我们很乐意在这个问题跟踪系统中帮助你解决任何有关Ultralytics YOLO的问题。如果你有任何技术问题或需要进一步的帮助,请随时在这里详细说明,我们会尽快给你回复。感谢你的理解,并期待你的回复。🙂
duoerku
你好,进一部沟通请联系15680550171, 或者添加微信 BK-Mike
Paula DerrengerUltralytics您好,谢谢您对Ultralytics YOLOv8的兴趣!🚀 对于技术支持和进一步的沟通,请优先利用GitHub Issues功能提出您的问题或需求,这样我们能够提供更有条理且可追踪的支持。
就您提供的信息来看,您似乎对命令行界面(CLI)的使用方法有兴趣,这里是可以通过几个简单示例来帮助您开始:
-
训练一个模型:
yolo train data=coco128.yaml model=yolov8n.pt epochs=10 lr0=0.01 -
运行预测:
yolo predict model=yolov8n-seg.pt source='https://youtu.be/LNwODJXcvt4' imgsz=320 -
验证模型:
yolo val model=yolov8n.pt data=coco128.yaml batch=1 imgsz=640 -
导出模型为ONNX格式:
yolo export model=yolov8n-cls.pt format=onnx imgsz=224,128
更多详细命令和选项,请参阅我们的官方文档。如果有更具体的问题或需求,欢迎在GitHub上开启一个issue进行讨论。🤗
-