YOLO V26安装与快速入门
安装 Ultralytics
前置要求
- 安装Conda环境并配置国内源
安装方式
Ultralytics官方提供了pip、conda、docker等方式,对于windows上推荐使用Conda方式
基于python3.11创建ultralytics-env的conda的环境并激活,如果需要使用GPU的功能,推荐与pytorch一起安装:
conda create--nameultralytics-env-cconda-forgepython=3.11ultralytics torchvision pytorch-gpu-yconda activate ultralytics-env如果不需要使用GPU,安装方式如下:
conda create--nameultralytics-env-cconda-forgepython=3.11ultralytics torchvision-yconda activate ultralytics-env如果后续还想继续使用gpu功能,可以继续单独安装pytorch
condainstallpytorch torchvision torchaudio pytorch-cuda=11.8-cpytorch-cnvidia通过 Python 使用 Ultralytics
在 Python 中执行相同的预测:
fromultralyticsimportYOLO model=YOLO("yolo26n.pt")# 加载预训练的 YOLO26n 检测模型results=model("https://ultralytics.com/images/bus.jpg",save=True)# 进行预测并保存标注后的图像第一次运行时会下载模型参数到本地缓存路径,如果没有配置代理可能会比较慢,可以手动用 ghproxy 镜像下载
Update Settings with'yolo settings key=value', i.e.'yolo settings runs_dir=path/to/dir'.Forhelpsee 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.3MB6.6KB/s2: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也可以提前通过代理下载到本地
curl-Ohttps://v4.gh-proxy.org/https://github.com/ultralytics/assets/releases/download/v0.0.0/bus.jpg同时更新代码:
fromultralyticsimportYOLO model=YOLO("C:\\Users\\Administrator\\.ultralytics\\models\\yolo26n.pt")# 加载预训练的 YOLO26n 检测模型results=model("../../../images/yolo/bus.jpg",save=True)# 进行预测并保存标注后的图像