YOLO V26安装与快速入门
安装 Ultralytics
前置要求
- 安装Conda环境并配置国内源
安装方式
Ultralytics官方提供了pip、conda、docker等方式,对于windows上推荐使用Conda方式
基于python3.11创建ultralytics-env的conda的环境并激活,如果需要使用GPU的功能,推荐与pytorch一起安装:
shell
conda create --name ultralytics-env -c conda-forge python=3.11 ultralytics torchvision pytorch-gpu -y
conda activate ultralytics-env
如果不需要使用GPU,安装方式如下:
shell
conda create --name ultralytics-env -c conda-forge python=3.11 ultralytics torchvision -y
conda activate ultralytics-env
如果后续还想继续使用gpu功能,可以继续单独安装pytorch
shell
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
通过 Python 使用 Ultralytics
在 Python 中执行相同的预测:
python
from ultralytics import YOLO
model = YOLO("yolo26n.pt") # 加载预训练的 YOLO26n 检测模型
results = model("https://ultralytics.com/images/bus.jpg", save=True) # 进行预测并保存标注后的图像
第一次运行时会下载模型参数到本地缓存路径,如果没有配置代理可能会比较慢,可以手动用 ghproxy 镜像下载
shell
Update Settings with 'yolo settings key=value', i.e. 'yolo settings runs_dir=path/to/dir'. For help see https://docs.ultralytics.com/usage/settings.
Downloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolo26n.pt to 'yolo26n.pt': 0% ──────────── 48.0KB/5.3MB 6.6KB/s 2:56<13:36
原链接: https://github.com/ultralytics/assets/releases/download/v8.4.0/yolo26n.pt
加上国内代理前缀,浏览器 /wget/curl 直接下:
curl -O https://gh-proxy.org/https://github.com/ultralytics/assets/releases/download/v8.4.0/yolo26n.pt
备选代理(ghproxy 挂了就换其他代理如):
curl -O https://shturl.cc//https://github.com/ultralytics/assets/releases/download/v8.4.0/yolo26n.pt
下载完把 yolo26n.pt 放到 ultralytics 的模型缓存目录,代码就不会再重新下载:
- Windows:
C:\Users\你的用户名\.ultralytics\models\ - Linux / WSL:
~/.ultralytics/models/
同理bus.jpg也可以提前通过代理下载到本地
shell
curl -O https://v4.gh-proxy.org/https://github.com/ultralytics/assets/releases/download/v0.0.0/bus.jpg
同时更新代码:
python
from ultralytics import YOLO
model = YOLO("C:\\Users\\Administrator\\.ultralytics\\models\\yolo26n.pt") # 加载预训练的 YOLO26n 检测模型
results = model("../../../images/yolo/bus.jpg", save=True) # 进行预测并保存标注后的图像