TensorFlow_GPU版安装与测试(Anaconda,CUDA,Jupyter)

条件

(2024-12-25)

  • 操作系统:Windows 11 专业版 24H2
  • GPU:Geforce RTX 2080 Ti
  • CPU:AMD Ryzen 5 9600X 6-Core Processor 3.90 GHz

预操作:

  1. 删除原安装的CUDA和cuDNN(未安装可忽略)
  2. 安装Visual Studio最新版(默认)
  3. 安装Anaconda最新版(默认)

环境创建:Python3.9

使用Anaconda Prompt命令提示符

conda create -n tf_gpu python=3.9

(base) C:\Users\jing>conda create -n tf_gpu python=3.9
Channels:
 - defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: D:\anaconda3\envs\tf_gpu

  added / updated specs:
    - python=3.9


The following NEW packages will be INSTALLED:

  ca-certificates    pkgs/main/win-64::ca-certificates-2024.11.26-haa95532_0
  openssl            pkgs/main/win-64::openssl-3.0.15-h827c3e9_0
  pip                pkgs/main/win-64::pip-24.2-py39haa95532_0
  python             pkgs/main/win-64::python-3.9.21-h8205438_1
  setuptools         pkgs/main/win-64::setuptools-75.1.0-py39haa95532_0
  sqlite             pkgs/main/win-64::sqlite-3.45.3-h2bbff1b_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-py39haa95532_0


Proceed ([y]/n)? y

CUDA与cuDNN安装:指定版本

https://www.tensorflow.org/install/pip#windows-native

conda activate tf_gpu

conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0

(tf_gpu) C:\Users\jing>conda list
# packages in environment at D:\anaconda3\envs\tf_gpu:
#
# Name                    Version                   Build  Channel
ca-certificates           2024.12.14           h56e8100_0    conda-forge
cudatoolkit               11.2.2              h7d7167e_13    conda-forge
cudnn                     8.1.0.77             h3e0f4f4_0    conda-forge
openssl                   3.4.0                h2466b09_0    conda-forge
pip                       24.2             py39haa95532_0
python                    3.9.21               h8205438_1
setuptools                75.1.0           py39haa95532_0
sqlite                    3.45.3               h2bbff1b_0
tzdata                    2024b                h04d1e81_0
ucrt                      10.0.22621.0         h57928b3_1    conda-forge
vc                        14.40                haa95532_2
vc14_runtime              14.42.34433         he29a5d6_23    conda-forge
vs2015_runtime            14.42.34433         hdffcdeb_23    conda-forge
wheel                     0.44.0           py39haa95532_0

TensorFlow安装:<2.11

Anything above 2.10 is not supported on the GPU on Windows Native

python -m pip install "tensorflow<2.11"

(tf_gpu) C:\Users\jing>conda list
# packages in environment at D:\anaconda3\envs\tf_gpu:
#
# Name                    Version                   Build  Channel
absl-py                   2.1.0                    pypi_0    pypi
astunparse                1.6.3                    pypi_0    pypi
ca-certificates           2024.12.14           h56e8100_0    conda-forge
cachetools                5.5.0                    pypi_0    pypi
certifi                   2024.12.14               pypi_0    pypi
charset-normalizer        3.4.1                    pypi_0    pypi
cudatoolkit               11.2.2              h7d7167e_13    conda-forge
cudnn                     8.1.0.77             h3e0f4f4_0    conda-forge
flatbuffers               24.12.23                 pypi_0    pypi
gast                      0.4.0                    pypi_0    pypi
google-auth               2.37.0                   pypi_0    pypi
google-auth-oauthlib      0.4.6                    pypi_0    pypi
google-pasta              0.2.0                    pypi_0    pypi
grpcio                    1.68.1                   pypi_0    pypi
h5py                      3.12.1                   pypi_0    pypi
idna                      3.10                     pypi_0    pypi
importlib-metadata        8.5.0                    pypi_0    pypi
keras                     2.10.0                   pypi_0    pypi
keras-preprocessing       1.1.2                    pypi_0    pypi
libclang                  18.1.1                   pypi_0    pypi
markdown                  3.7                      pypi_0    pypi
markupsafe                3.0.2                    pypi_0    pypi
numpy                     2.0.2                    pypi_0    pypi
oauthlib                  3.2.2                    pypi_0    pypi
openssl                   3.4.0                h2466b09_0    conda-forge
opt-einsum                3.4.0                    pypi_0    pypi
packaging                 24.2                     pypi_0    pypi
pip                       24.2             py39haa95532_0
protobuf                  3.19.6                   pypi_0    pypi
pyasn1                    0.6.1                    pypi_0    pypi
pyasn1-modules            0.4.1                    pypi_0    pypi
python                    3.9.21               h8205438_1
requests                  2.32.3                   pypi_0    pypi
requests-oauthlib         2.0.0                    pypi_0    pypi
rsa                       4.9                      pypi_0    pypi
setuptools                75.1.0           py39haa95532_0
six                       1.17.0                   pypi_0    pypi
sqlite                    3.45.3               h2bbff1b_0
tensorboard               2.10.1                   pypi_0    pypi
tensorboard-data-server   0.6.1                    pypi_0    pypi
tensorboard-plugin-wit    1.8.1                    pypi_0    pypi
tensorflow                2.10.1                   pypi_0    pypi
tensorflow-estimator      2.10.0                   pypi_0    pypi
tensorflow-io-gcs-filesystem 0.31.0                   pypi_0    pypi
termcolor                 2.5.0                    pypi_0    pypi
typing-extensions         4.12.2                   pypi_0    pypi
tzdata                    2024b                h04d1e81_0
ucrt                      10.0.22621.0         h57928b3_1    conda-forge
urllib3                   2.3.0                    pypi_0    pypi
vc                        14.40                haa95532_2
vc14_runtime              14.42.34433         he29a5d6_23    conda-forge
vs2015_runtime            14.42.34433         hdffcdeb_23    conda-forge
werkzeug                  3.1.3                    pypi_0    pypi
wheel                     0.44.0           py39haa95532_0
wrapt                     1.17.0                   pypi_0    pypi
zipp                      3.21.0                   pypi_0    pypi

验证安装:出错

Verify the installation:

python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

(tf_gpu) C:\Users\jing>python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.2 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time t
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值