yolo --- 快速上手
运行前环境查看
yolo settings
包括数据集路径、运行输出路径等
task 和 mode(不是model)
task:
- Detect: For identifying and localizing objects or regions of interest in an image or video.
- Segment: For dividing an image or video into regions or pixels that correspond to different objects or classes.
- Classify: For predicting the class label of an input image.
- Pose: For identifying objects and estimating their keypoints in an image or video.
- OBB: Oriented (i.e. rotated) bounding boxes suitable for satellite or medical imagery.
mode:
- Train: For training a YOLO11 model on a custom dataset.
- Val: For validating a YOLO11 model after it has been trained.
- Predict: For making predictions using a trained YOLO11 model on new images or videos.
- Export: For exporting a YOLO11 model to a format that can be used for deployment.
- Track: For tracking objects in real-time using a YOLO11 model.
- Benchmark: For benchmarking YOLO11 exports (ONNX, TensorRT, etc.) speed and accuracy.
运行方式 - 命令行
下载好 ultralytics 项目并安装好 ultralytics 项目后,可以直接使用命令行(Command Line Interface, CLI)进行快速推理一张图片、视频、视频流、摄像头等等,举个例子:
yolo 任务名称 model=本地模型权重路径 source=图片路径 yolo predict model=yolo11n.pt source='https://ultralytics.com/images/bus.jpg'
运行方式 - Python 脚本
模型训练
模型配置文件路径:
数据集配置文件路径:
from ultralytics import YOLO import multiprocessing def main(): # ---------- 加载模型 ---------- model = YOLO('yolo11n.yaml') # ---------- 模型预测 ---------- model.train( data='cs2.yaml', epochs=3 ) if __name__ == '__main__': # 如果在 Windows 上运行且需要多进程支持,保留以下行 multiprocessing.freeze_support() main()
模型验证
当我们训练得到一个 .pt
文件后,可能需要对其进行评估以获取该 .pt
的指标,代码如下:
from ultralytics import YOLO # ---------- 加载模型 ---------- model = YOLO('runs/detect/train3/weights/best.pt') # ---------- 模型评估 ---------- model.val(data='coco128.yaml')
模型预测
from ultralytics import YOLO import multiprocessing def main(): # ---------- 加载模型 ---------- model = YOLO('runs/detect/train4/weights/best.pt') # ---------- 模型预测 ---------- model.predict( source='datasets/cs2/images/train/001.png', save=True ) if __name__ == '__main__': # 如果在 Windows 上运行且需要多进程支持,保留以下行 multiprocessing.freeze_support() main()
模型导出
from ultralytics import YOLO # ---------- 加载模型 ---------- model = YOLO('runs/detect/train3/weights/best.pt') # ---------- 模型导出 ---------- model.export(format='onnx', simplify=True)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」
2022-11-20 Kconfig 使用
2022-11-20 IMX6ULL system boot