外观
YoloV11
约 779 字大约 3 分钟
yolo
2024-12-18
环境安装
# 运行环境
D:\ML>conda env list
D:\ML>conda create -n yolov11 python=3.12 #Python>=3.8 Pytorch>=1.8
D:\ML>conda activate yolov11
#安装yolo
D:\ML>conda activate yolov11
(yolov11) D:\ML>pip install ultralytics
...
Successfully installed MarkupSafe-3.0.2 certifi-2024.12.14 charset-normalizer-3.4.0 colorama-0.4.6 contourpy-1.3.1 cycler-0.12.1 filelock-3.16.1 fonttools-4.55.3 fsspec-2024.10.0 idna-3.10
jinja2-3.1.4 kiwisolver-1.4.7 matplotlib-3.10.0 mpmath-1.3.0 networkx-3.4.2 packaging-24.2 pandas-2.2.3 pillow-11.0.0 psutil-6.1.0 py-cpuinfo-9.0.0 pyparsing-3.2.0 python-dateutil-2.9.0.pos
t0 pytz-2024.2 pyyaml-6.0.2 requests-2.32.3 scipy-1.14.1 seaborn-0.13.2 six-1.17.0 sympy-1.13.1 torch-2.5.1 torchvision-0.20.1 tqdm-4.67.1 typing-extensions-4.12.2 tzdata-2024.2 ultralytics
-8.3.51 ultralytics-thop-2.0.13 urllib3-2.2.3数据集准备
数据集结构:
datasets
train:数据集
images图像数据
…
img.jpg
img1.jpg
...
labels图像标注的label数据
…
label.txt
label1.txt
...
val:验证集已标注的数据
images图片数据
…
img.jpg
img1.jpg
...
labels标注数据
…
label.txt
label1.txt
...
test测试集
img.jpg未标注的图像
img1.jpg
...
训练
(yolov11) D:\ML\yolov11> yolo train model=yolo11m.yaml data=ultralytics/cfg/datasets/VOC.yaml epochs=100 batch=4 imgsz=1280`注意这些文件及数据集的位置 如果有误可能是受到基础配置文件的影响C:\Users\yuche\AppData\Roaming\Ultralytics\ 查看该路径下的配置文件
# VOC.yaml
path: datasets/locateorigin
train: # train images
- train/images
- train/labels
val: # val images
- val/images/
- val/labels/
test: # test images (optional)
- tests
# Classes
names:
0: mark
1: roi检测
(yolov11) D:\ML\yolov11>yolo detect predict model=./runs/detect/train25/weights/best.pt imgsz=1280 source=./datasets/detect
Ultralytics 8.3.51 🚀 Python-3.12.8 torch-2.5.1+cu124 CUDA:0 (NVIDIA GeForce RTX 4060, 8188MiB)
YOLO11m summary (fused): 303 layers, 20,031,574 parameters, 0 gradients, 67.7 GFLOPs
image 1/78 D:\ML\yolov11\datasets\detect\Noo1216134457138.jpg: 864x1280 1 mark, 2 rois, 31.3ms
image 2/78 D:\ML\yolov11\datasets\detect\Noo1216135017969.jpg: 864x1280 1 mark, 1 roi, 38.2ms
...
image 77/78 D:\ML\yolov11\datasets\detect\Noo1218111904081.jpg: 864x1280 1 mark, 1 roi, 23.8ms
image 78/78 D:\ML\yolov11\datasets\detect\Noo1218112259777.jpg: 864x1280 1 mark, 2 rois, 34.8ms
Speed: 6.4ms preprocess, 32.3ms inference, 2.5ms postprocess per image at shape (1, 3, 864, 1280)
Results saved to runs\detect\predict4导出模型
(yolov11) D:\ML\yolov11>yolo export model=./runs/detect/train25/weights/best.pt format=onnx
Ultralytics 8.3.51 🚀 Python-3.12.8 torch-2.5.1+cu124 CPU (12th Gen Intel Core(TM) i7-12700KF)
YOLO11m summary (fused): 303 layers, 20,031,574 parameters, 0 gradients, 67.7 GFLOPs
PyTorch: starting from 'runs\detect\train25\weights\best.pt' with input shape (1, 3, 1280, 1280) BCHW and output shape(s) (1, 6, 33600) (38.7 MB)
ONNX: starting export with onnx 1.17.0 opset 19...
ONNX: slimming with onnxslim 0.1.44...
ONNX: export success ✅ 10.7s, saved as 'runs\detect\train25\weights\best.onnx' (77.2 MB)
Export complete (13.7s)
Results saved to D:\ML\yolov11\runs\detect\train25\weights
Predict: yolo predict task=detect model=runs\detect\train25\weights\best.onnx imgsz=1280
Validate: yolo val task=detect model=runs\detect\train25\weights\best.onnx imgsz=1280 data=ultralytics/cfg/datasets/VOC.yaml
Visualize: https://netron.app导出使用异常
Microsoft.ML.OnnxRuntime.OnnxRuntimeException:“[ErrorCode:InvalidArgument] Failed to load model with error: D:\a_work\1\s\onnxruntime\core\graph\model.cc:146 onnxruntimeModel Unsupported model IR version: 9, max supported IR version: 8
导出后使用,报错。因为onnxruntime版本低 不支持9。 两种解决方案: 1.兼容两个onnxruntime的dll 2.导出v8的版本
导出v8版本: 降低torch的版本 目前是2.5 ERROR: Could not find a version that satisfies the requirement torch==1.12.1+cu116 怎么操作都下载不了
原因是因为使用了源 不包含低版本的包,以及python版本的的问题,低版本的python安装完成后自动就是正常的
pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113
