✅ 虽然标题说是YOLOv11,但其实适用于v5及以上的任何版本,毕竟配置“YOLO环境”本质上是配置ultralytics这个库所需的环境,也就是pytorch+torchvision,与YOLO版本其实是没有关系的。

References:

https://www.intel.com/content/www/us/en/developer/articles/tool/pytorch-prerequisites-for-intel-gpu/2-5.html

https://dgpu-docs.intel.com/driver/client/overview.html

https://pytorch.org/docs/stable/notes/get_start_xpu.html

Hardware:

Intel NUC 13 Pro Desk Edition / i5-1340P / 8G DDR4 / 256G SSD

Operating System:

Ubuntu 24.10 Desktop

安装Intel PyTorch支持包

本文章内容可能过时,如果遇到错误,建议直接阅读Intel官方说明:
https://www.intel.com/content/www/us/en/developer/articles/tool/pytorch-prerequisites-for-intel-gpu/2-5.html

添加公钥

sudo apt update
sudo apt install -y gpg-agent wget
wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
| gpg --dearmor > /tmp/intel-for-pytorch-gpu-dev-keyring.gpg

sudo mv /tmp/intel-for-pytorch-gpu-dev-keyring.gpg /usr/share/keyrings

echo "deb [signed-by=/usr/share/keyrings/intel-for-pytorch-gpu-dev-keyring.gpg] https://apt.repos.intel.com/intel-for-pytorch-gpu-dev all main" > /tmp/intel-for-pytorch-gpu-dev.list

sudo mv /tmp/intel-for-pytorch-gpu-dev.list /etc/apt/sources.list.d

安装支持包

sudo apt update
sudo apt install intel-for-pytorch-gpu-dev-0.5 intel-pti-dev-0.9

配置oneAPI环境变量

使用nano ~/.bashrc打开编辑器(或nano ~/.zshrc),

在文件底部添加以下内容:

source /opt/intel/oneapi/pytorch-gpu-dev-0.5/oneapi-vars.sh
source $ONEAPI_ROOT/../pti/0.9/env/vars.sh
export Pti_DIR=$ONEAPI_ROOT/../pti/0.9/lib/cmake/pti

保存文件并退出,source一下:

source ~/.bashrc 

如果能看到以下提示,则代表路径没有问题:

:: initializing oneAPI environment ...
   -bash: BASH_VERSION = 5.2.32(1)-release
   args: Using "$@" for oneapi-vars.sh arguments:
:: compiler -- processing etc/compiler/vars.sh
:: debugger -- processing etc/debugger/vars.sh
:: dpl -- processing etc/dpl/vars.sh
:: mkl -- processing etc/mkl/vars.sh
:: tbb -- processing etc/tbb/vars.sh
:: oneAPI environment initialized ::

如果出现了找不到文件的错误,将刚才添加的第一行改为:

source ~/intel/oneapi/pytorch-gpu-dev-0.5/oneapi-vars.sh

安装Intel GPU驱动

本文章内容可能过时,如果遇到错误,建议直接阅读Intel官方说明:
https://dgpu-docs.intel.com/driver/client/overview.html

sudo apt-get update
sudo apt-get install -y software-properties-common

# Add the intel-graphics PPA for 24.10
sudo add-apt-repository -y ppa:kobuk-team/intel-graphics

# Install the compute-related packages
sudo apt-get install -y libze-intel-gpu1 libze1 intel-ocloc intel-opencl-icd clinfo

# Install the media-related packages
sudo apt-get install -y intel-media-va-driver-non-free libmfx1 libmfx-gen1.2 libvpl2 libvpl-tools libva-glx2 va-driver-all vainfo

安装并配置Python3环境

⚠ 以下实践均基于系统范围环境配置,如果你的系统范围Python环境运行有其他重要程序(对pytorch、numpy等深度学习相关软件包敏感),建议使用venv或conda环境隔离。

如果你只需要在这台机器上运行YOLO(ultralytics),那么可以直接继续。

sudo apt update
sudo apt install python3 python-is-python3 python3-pip

允许系统范围安装Python程序包:

python3 -m pip config set global.break-system-packages true

Python换源(以下都是国内源,任选其一即可):

pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/simple
pip config set global.index-url https://mirror.sjtu.edu.cn/pypi/web/simple

安装ultralytics

pip install ultralytics

⚠ 如果先安装torch,则安装ultralytics过程中可能会替换你的torch或torchvision版本为CPU版本(而我们需要的是XPU版本)
因此这里先安装ultralytics,再卸载CPU版本的torch重新安装XPU版本

安装OpenVINO

❔ 如果你需要运行/转换OpenVINO格式的模型,则需要安装此库,不需要则可以跳过

pip install openvino

安装torch+torchvision+torchaudio(xpu)

本文章内容可能过时,如果出现错误,建议直接阅读PyTorch官方说明:
https://pytorch.org/docs/stable/notes/get_start_xpu.html

pip uninstall torch torchvision torchaudio
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/test/xpu

测试一下

该装的都装好了,你可以测试一下你的YOLO程序。

或者使用一行命令快速检测一下:

yolo predict model=yolo11n.pt