yolov12已经发布,项目地址为github.com/sunsmarterjie/yolov12,下面我们来看看如何在windows系统上配置其运行环境。首先查看官方提供的安装命令:
wget https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.3/flash_attn-2.7.3+cu11torch2.2cxx11abiFALSE-cp311-cp311-linux_x86_64.whl conda create -n yolov12 python=3.11 conda activate yolov12 pip install -r requirements.txt pip install -e .
显然,官方脚本是针对Linux系统的,因为其中使用的
flash_attn
win_amd64.whl
尝试从源码编译有一定难度,对环境要求较高,因此更推荐寻找已编译好的Windows版本whl包。例如可以从gitee.com/FIRC/flash_attn_chinese_mirror获取,当然你也可以搜索其他可信来源。
我本地使用的是Python 3.10环境,当然你也可以选择Python 3.11或其他版本。
创建并激活conda环境:
立即学习“Python免费学习笔记(深入)”;
conda create -n yolov12 python=3.10 conda activate yolov12
我下载的flash-attn版本为:
flash_attn-2.7.4+cu124torch2.5.1cxx11abiFALSE-cp310-cp310-win_amd64.whl
为确保版本兼容,我同步调整了PyTorch版本,安装命令如下:
pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu124
然后修改项目根目录下的
requirements.txt
#torch==2.5.1 #torchvision==0.20.1 #flash_attn-2.7.3+cu11torch2.2cxx11abiFALSE-cp311-cp311-linux_x86_64.whl timm==1.0.14 albumentations==2.0.4 onnx==1.14.0 onnxruntime==1.15.1 pycocotools==2.0.7 PyYAML==6.0.1 scipy==1.13.0 onnxslim==0.1.31 onnxruntime-gpu==1.18.0 gradio==4.44.1 opencv-python==4.9.0.80 psutil==5.9.8 py-cpuinfo==9.0.0 huggingface-hub==0.23.2 safetensors==0.4.3 numpy==1.26.4
继续执行依赖安装:
pip install -r requirements.txt pip install -e .
安装完成后,进行图片推理测试:
yolo task=detect mode=predict model=weights/yolov12n.pt source=E:\animal.jpg save=true
输出日志如下:
FlashAttention is not available on this device. Using scaled_dot_product_attention instead.
D:naconda3envsyolo12libsite-packages immmodelslayers__init__.py:48: FutureWarning: Importing from timm.models.layers is deprecated, please import via timm.layers
warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.layers", FutureWarning)
Ultralytics 8.3.63 ? Python-3.10.16 torch-2.5.1+cu124 CUDA:0 (NVIDIA GeForce RTX 2070 Super, 8192MiB)
YOLOv12n summary (fused): 352 layers, 2,590,824 parameters, 0 gradients, 6.5 GFLOPs
image 1/1 E:nimal.jpg: 640x640 1 zebra, 1 giraffe, 16.0ms
Speed: 4.0ms preprocess, 16.0ms inference, 91.0ms postprocess per image at shape (1, 3, 640, 640)
Results saved to runsdetectpredict看到提示“FlashAttention is not available on this device”,怀疑flash-attn未正确安装。于是进入Python环境手动导入测试:
![[python]windows上安装yolov12环境](https://img.php.cn/upload/article/001/503/042/175634726836500.jpg)
手动import测试:
![[python]windows上安装yolov12环境](https://img.php.cn/upload/article/001/503/042/175634726833977.jpg)
导入成功,说明flash-attn安装无误。问题出在
torch.cuda.get_device_capability()[0] >= 8
最终效果如下:
![[python]windows上安装yolov12环境](https://img.php.cn/upload/article/001/503/042/175634726848980.jpg)
环境配置成功,yolov12可在Windows上正常运行!
以上就是[python]windows上安装yolov12环境的详细内容,更多请关注php中文网其它相关文章!
Windows激活工具是正版认证的激活工具,永久激活,一键解决windows许可证即将过期。可激活win7系统、win8.1系统、win10系统、win11系统。下载后先看完视频激活教程,再进行操作,100%激活成功。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号