(new_env) D:\Miniconda3\envs\new_env>conda clean --all
There are no unused tarball(s) to remove.
There are no index cache(s) to remove.
There are no unused package(s) to remove.
There are no tempfile(s) to remove.
There are no logfile(s) to remove.
(new_env) D:\Miniconda3\envs\new_env>conda create -n new_env python=3.10
WARNING: A conda environment already exists at 'D:\Miniconda3\envs\new_env'
Remove existing environment (y/[n])? y
Channels:
- defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done
Package Plan
environment location: D:\Miniconda3\envs\new_env
added / updated specs:
- python=3.10
The following packages will be downloaded:
package | build
---------------------------|-----------------
vc-14.40 | haa95532_2 10 KB
Total: 10 KB
The following NEW packages will be INSTALLED:
bzip2 pkgs/main/win-64::bzip2-1.0.8-h2bbff1b_6
ca-certificates pkgs/main/win-64::ca-certificates-2024.11.26-haa95532_0
libffi pkgs/main/win-64::libffi-3.4.4-hd77b12b_1
openssl pkgs/main/win-64::openssl-3.0.15-h827c3e9_0
pip pkgs/main/win-64::pip-24.2-py310haa95532_0
python pkgs/main/win-64::python-3.10.15-h4607a30_1
setuptools pkgs/main/win-64::setuptools-75.1.0-py310haa95532_0
sqlite pkgs/main/win-64::sqlite-3.45.3-h2bbff1b_0
tk pkgs/main/win-64::tk-8.6.14-h0416ee5_0
tzdata pkgs/main/noarch::tzdata-2024b-h04d1e81_0
vc pkgs/main/win-64::vc-14.40-haa95532_2
vs2015_runtime pkgs/main/win-64::vs2015_runtime-14.42.34433-h9531ae6_2
wheel pkgs/main/win-64::wheel-0.44.0-py310haa95532_0
xz pkgs/main/win-64::xz-5.4.6-h8cc25b3_1
zlib pkgs/main/win-64::zlib-1.2.13-h8cc25b3_1
Proceed ([y]/n)? y
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
To activate this environment, use
$ conda activate new_env
To deactivate an active environment, use
$ conda deactivate
(new_env) D:\Miniconda3\envs\new_env>conda activate new_env
(new_env) D:\Miniconda3\envs\new_env>conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
Channels:
-
pytorch
-
nvidia
-
defaults
Platform: win-64
Collecting package metadata (repodata.json): | Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1007)')': /pkgs/r/win-64/repodata.json.zst
done
Solving environment: done
Package Plan
environment location: D:\Miniconda3\envs\new_env
added / updated specs:
-
pytorch
-
pytorch-cuda=11.8
-
torchaudio
-
torchvision
The following packages will be downloaded:
package | build
---------------------------|-----------------
blas-1.0 | mkl 6 KB
brotli-python-1.0.9 | py310hd77b12b_8 346 KB
certifi-2024.8.30 | py310haa95532_0 163 KB
charset-normalizer-3.3.2 | pyhd3eb1b0_0 44 KB
cuda-cccl-12.6.77 | 0 16 KB nvidia
cuda-cccl_win-64-12.6.77 | 0 1.0 MB nvidia
cuda-cudart-11.8.89 | 0 1.4 MB nvidia
cuda-cudart-dev-11.8.89 | 0 723 KB nvidia
cuda-cupti-11.8.87 | 0 11.5 MB nvidia
cuda-libraries-11.8.0 | 0 1 KB nvidia
cuda-libraries-dev-11.8.0 | 0 1 KB nvidia
cuda-nvrtc-11.8.89 | 0 72.1 MB nvidia
cuda-nvrtc-dev-11.8.89 | 0 16.1 MB nvidia
cuda-nvtx-11.8.86 | 0 43 KB nvidia
cuda-profiler-api-12.6.77 | 0 19 KB nvidia
cuda-runtime-11.8.0 | 0 1 KB nvidia
cuda-version-12.6 | 3 16 KB nvidia
filelock-3.13.1 | py310haa95532_0 22 KB
freetype-2.12.1 | ha860e81_0 490 KB
giflib-5.2.2 | h7edc060_0 105 KB
gmpy2-2.1.2 | py310h7f96b67_0 160 KB
idna-3.7 | py310haa95532_0 132 KB
intel-openmp-2023.1.0 | h59b6b97_46320 2.7 MB
jinja2-3.1.4 | py310haa95532_1 281 KB
jpeg-9e | h827c3e9_3 334 KB
lcms2-2.12 | h83e58a3_0 454 KB
lerc-3.0 | hd77b12b_0 120 KB
libcublas-11.11.3.6 | 0 33 KB nvidia
libcublas-dev-11.11.3.6 | 0 375.9 MB nvidia
libcufft-10.9.0.58 | 0 6 KB nvidia
libcufft-dev-10.9.0.58 | 0 144.6 MB nvidia
libcurand-10.3.7.77 | 0 41.6 MB nvidia
libcurand-dev-10.3.7.77 | 0 262 KB nvidia
libcusolver-11.4.1.48 | 0 29 KB nvidia
libcusolver-dev-11.4.1.48 | 0 94.1 MB nvidia
libcusparse-11.7.5.86 | 0 13 KB nvidia
libcusparse-dev-11.7.5.86 | 0 175.7 MB nvidia
libdeflate-1.17 | h2bbff1b_1 153 KB
libjpeg-turbo-2.0.0 | h196d8e1_0 618 KB
libnpp-11.8.0.86 | 0 294 KB nvidia
libnpp-dev-11.8.0.86 | 0 143.2 MB nvidia
libnvjpeg-11.9.0.86 | 0 4 KB nvidia
libnvjpeg-dev-11.9.0.86 | 0 1.9 MB nvidia
libpng-1.6.39 | h8cc25b3_0 369 KB
libtiff-4.5.1 | hd77b12b_0 1.1 MB
libuv-1.48.0 | h827c3e9_0 322 KB
libwebp-1.3.2 | hbc33d0d_0 73 KB
libwebp-base-1.3.2 | h3d04722_1 303 KB
lz4-c-1.9.4 | h2bbff1b_1 152 KB
markupsafe-2.1.3 | py310h2bbff1b_0 25 KB
mkl-2023.1.0 | h6b88ed4_46358 155.9 MB
mkl-service-2.4.0 | py310h2bbff1b_1 44 KB
mkl_fft-1.3.11 | py310h827c3e9_0 168 KB
mkl_random-1.2.8 | py310hc64d2fc_0 257 KB
mpc-1.1.0 | h7edee0f_1 260 KB
mpfr-4.0.2 | h62dcd97_1 1.5 MB
mpir-3.0.0 | hec2e145_1 1.3 MB
mpmath-1.3.0 | py310haa95532_0 834 KB
networkx-3.2.1 | py310haa95532_0 2.4 MB
numpy-2.0.1 | py310h055cbcc_1 11 KB
numpy-base-2.0.1 | py310h65a83cf_1 9.1 MB
openjpeg-2.5.2 | hae555c5_0 268 KB
pillow-11.0.0 | py310hb5480e2_0 767 KB
pysocks-1.7.1 | py310haa95532_0 28 KB
pytorch-2.5.1 |py3.10_cuda11.8_cudnn9_0 1.38 GB pytorch
pytorch-cuda-11.8 | h24eeafa_6 7 KB pytorch
pytorch-mutex-1.0 | cuda 3 KB pytorch
pyyaml-6.0.2 | py310h827c3e9_0 174 KB
requests-2.32.3 | py310haa95532_1 101 KB
sympy-1.13.2 | py310haa95532_0 11.3 MB
tbb-2021.8.0 | h59b6b97_0 149 KB
torchaudio-2.5.1 | py310_cu118 7.0 MB pytorch
torchvision-0.20.1 | py310_cu118 7.7 MB pytorch
typing_extensions-4.11.0 | py310haa95532_0 62 KB
urllib3-2.2.3 | py310haa95532_0 184 KB
win_inet_pton-1.1.0 | py310haa95532_0 9 KB
yaml-0.2.5 | he774522_0 62 KB
zstd-1.5.6 | h8880b57_0 708 KB
Total: 2.64 GB
The following NEW packages will be INSTALLED:
blas pkgs/main/win-64::blas-1.0-mkl
brotli-python pkgs/main/win-64::brotli-python-1.0.9-py310hd77b12b_8
certifi pkgs/main/win-64::certifi-2024.8.30-py310haa95532_0
charset-normalizer pkgs/main/noarch::charset-normalizer-3.3.2-pyhd3eb1b0_0
cuda-cccl nvidia/win-64::cuda-cccl-12.6.77-0
cuda-cccl_win-64 nvidia/noarch::cuda-cccl_win-64-12.6.77-0
cuda-cudart nvidia/win-64::cuda-cudart-11.8.89-0
cuda-cudart-dev nvidia/win-64::cuda-cudart-dev-11.8.89-0
cuda-cupti nvidia/win-64::cuda-cupti-11.8.87-0
cuda-libraries nvidia/win-64::cuda-libraries-11.8.0-0
cuda-libraries-dev nvidia/win-64::cuda-libraries-dev-11.8.0-0
cuda-nvrtc nvidia/win-64::cuda-nvrtc-11.8.89-0
cuda-nvrtc-dev nvidia/win-64::cuda-nvrtc-dev-11.8.89-0
cuda-nvtx nvidia/win-64::cuda-nvtx-11.8.86-0
cuda-profiler-api nvidia/win-64::cuda-profiler-api-12.6.77-0
cuda-runtime nvidia/win-64::cuda-runtime-11.8.0-0
cuda-version nvidia/noarch::cuda-version-12.6-3
filelock pkgs/main/win-64::filelock-3.13.1-py310haa95532_0
freetype pkgs/main/win-64::freetype-2.12.1-ha860e81_0
giflib pkgs/main/win-64::giflib-5.2.2-h7edc060_0
gmpy2 pkgs/main/win-64::gmpy2-2.1.2-py310h7f96b67_0
idna pkgs/main/win-64::idna-3.7-py310haa95532_0
intel-openmp pkgs/main/win-64::intel-openmp-2023.1.0-h59b6b97_46320
jinja2 pkgs/main/win-64::jinja2-3.1.4-py310haa95532_1
jpeg pkgs/main/win-64::jpeg-9e-h827c3e9_3
lcms2 pkgs/main/win-64::lcms2-2.12-h83e58a3_0
lerc pkgs/main/win-64::lerc-3.0-hd77b12b_0
libcublas nvidia/win-64::libcublas-11.11.3.6-0
libcublas-dev nvidia/win-64::libcublas-dev-11.11.3.6-0
libcufft nvidia/win-64::libcufft-10.9.0.58-0
libcufft-dev nvidia/win-64::libcufft-dev-10.9.0.58-0
libcurand nvidia/win-64::libcurand-10.3.7.77-0
libcurand-dev nvidia/win-64::libcurand-dev-10.3.7.77-0
libcusolver nvidia/win-64::libcusolver-11.4.1.48-0
libcusolver-dev nvidia/win-64::libcusolver-dev-11.4.1.48-0
libcusparse nvidia/win-64::libcusparse-11.7.5.86-0
libcusparse-dev nvidia/win-64::libcusparse-dev-11.7.5.86-0
libdeflate pkgs/main/win-64::libdeflate-1.17-h2bbff1b_1
libjpeg-turbo pkgs/main/win-64::libjpeg-turbo-2.0.0-h196d8e1_0
libnpp nvidia/win-64::libnpp-11.8.0.86-0
libnpp-dev nvidia/win-64::libnpp-dev-11.8.0.86-0
libnvjpeg nvidia/win-64::libnvjpeg-11.9.0.86-0
libnvjpeg-dev nvidia/win-64::libnvjpeg-dev-11.9.0.86-0
libpng pkgs/main/win-64::libpng-1.6.39-h8cc25b3_0
libtiff pkgs/main/win-64::libtiff-4.5.1-hd77b12b_0
libuv pkgs/main/win-64::libuv-1.48.0-h827c3e9_0
libwebp pkgs/main/win-64::libwebp-1.3.2-hbc33d0d_0
libwebp-base pkgs/main/win-64::libwebp-base-1.3.2-h3d04722_1
lz4-c pkgs/main/win-64::lz4-c-1.9.4-h2bbff1b_1
markupsafe pkgs/main/win-64::markupsafe-2.1.3-py310h2bbff1b_0
mkl pkgs/main/win-64::mkl-2023.1.0-h6b88ed4_46358
mkl-service pkgs/main/win-64::mkl-service-2.4.0-py310h2bbff1b_1
mkl_fft pkgs/main/win-64::mkl_fft-1.3.11-py310h827c3e9_0
mkl_random pkgs/main/win-64::mkl_random-1.2.8-py310hc64d2fc_0
mpc pkgs/main/win-64::mpc-1.1.0-h7edee0f_1
mpfr pkgs/main/win-64::mpfr-4.0.2-h62dcd97_1
mpir pkgs/main/win-64::mpir-3.0.0-hec2e145_1
mpmath pkgs/main/win-64::mpmath-1.3.0-py310haa95532_0
networkx pkgs/main/win-64::networkx-3.2.1-py310haa95532_0
numpy pkgs/main/win-64::numpy-2.0.1-py310h055cbcc_1
numpy-base pkgs/main/win-64::numpy-base-2.0.1-py310h65a83cf_1
openjpeg pkgs/main/win-64::openjpeg-2.5.2-hae555c5_0
pillow pkgs/main/win-64::pillow-11.0.0-py310hb5480e2_0
pysocks pkgs/main/win-64::pysocks-1.7.1-py310haa95532_0
pytorch pytorch/win-64::pytorch-2.5.1-py3.10_cuda11.8_cudnn9_0
pytorch-cuda pytorch/win-64::pytorch-cuda-11.8-h24eeafa_6
pytorch-mutex pytorch/noarch::pytorch-mutex-1.0-cuda
pyyaml pkgs/main/win-64::pyyaml-6.0.2-py310h827c3e9_0
requests pkgs/main/win-64::requests-2.32.3-py310haa95532_1
sympy pkgs/main/win-64::sympy-1.13.2-py310haa95532_0
tbb pkgs/main/win-64::tbb-2021.8.0-h59b6b97_0
torchaudio pytorch/win-64::torchaudio-2.5.1-py310_cu118
torchvision pytorch/win-64::torchvision-0.20.1-py310_cu118
typing_extensions pkgs/main/win-64::typing_extensions-4.11.0-py310haa95532_0
urllib3 pkgs/main/win-64::urllib3-2.2.3-py310haa95532_0
win_inet_pton pkgs/main/win-64::win_inet_pton-1.1.0-py310haa95532_0
yaml pkgs/main/win-64::yaml-0.2.5-he774522_0
zstd pkgs/main/win-64::zstd-1.5.6-h8880b57_0
Proceed ([y]/n)? y
done 怎么办
2
您已经再次确认安装了 pytorch、torchvision、torchaudio 以及与 CUDA 11.8 对应的 pytorch-cuda 包。在最后一步,当您输入 y
时,Conda 已开始进行下载和安装。如果安装过程顺利完成(未出现新的错误信息),说明这些包已正确安装到 new_env
环境中。
接下来您可以进行如下验证步骤:
-
验证安装是否成功:
在
new_env
环境下执行:python -c "import torch; print(torch.version.cuda); print(torch.cuda.is_available())"
如果输出中返回了
11.8
或与您预期的 CUDA 版本号接近的数值,并且True
表示torch.cuda.is_available()
为可用,则说明 CUDA 加速已经正确启用。 -
运行您的 YOLOv8 程序:
将工作目录切换到您的项目目录:
cd /d D:\code\ultralytics-main
然后运行您的训练脚本(例如
train.py
)或 YOLOv8 命令行(例如yolo task=detect mode=train ...
):python train.py
或
yolo task=detect mode=train data=data.yaml model=yolov8n.pt epochs=100
如若上述验证步骤仍有问题,请检查网络稳定性、再次清理并使用 mamba
(如果需要)尝试安装,或确保未同时使用 pip 与 conda 混装 PyTorch 相关包。
如果您已经成功安装了带有 CUDA 支持的 PyTorch,并且 torch.cuda.is_available()
返回了 True
,那么您的环境就已经能够使用 GPU 进行深度学习训练了。接下来可以进行以下步骤:
-
验证 GPU 是否可用
在终端中再次确认:
python -c "import torch; print(torch.cuda.is_available())"
输出
True
则说明 PyTorch 已经识别到 GPU。 -
使用 YOLOv8 训练时自动检测 GPU
YOLOv8(由 ultralytics 提供的工具包)会在默认情况下自动检测 GPU 并在有 GPU 时使用它。如果您使用
yolo
命令行接口进行训练,例如:yolo task=detect mode=train model=yolov8n.pt data=coco.yaml epochs=100
YOLOv8 会自动选择 GPU(CUDA)作为设备。如果需要强制指定 GPU,可以通过
device
参数:yolo task=detect mode=train model=yolov8n.pt data=coco.yaml epochs=100 device=0
device=0
表示使用第0号 GPU,如果您有多块GPU,可以指定对应编号。 -
在 Python 脚本中显式指定 GPU
如果您是通过脚本(例如
train.py
)使用 YOLOv8 的 Python 接口,可以在加载 YOLO 类或 ultralytics 库时指定设备:from ultralytics import YOLO # 加载模型 model = YOLO('yolov8n.pt') # 使用GPU进行训练 results = model.train(data='coco.yaml', epochs=100, device=0)
如果不指定
device
,模型会自动尝试使用 GPU。如果找不到 CUDA GPU,就会使用 CPU。
总结 :
一旦您的 PyTorch CUDA 环境搭建完成,YOLOv8 在训练时会自动检测并使用 GPU。您只需要正常运行 YOLOv8 的训练命令或脚本即可享受 GPU 加速的训练过程。