【工具配置】【Windows】TensorFlow-GPU安装(保姆级)

1. 检查Anaconda是否安装

  1. 输入以下指令检查anaconda是否安装
(soar) C:\Users\Jon.SCORPIONE>conda -V
conda 4.10.1
  1. 如果没有出现以上提示,则证明没有安装
  2. 如果没有安装请参考这篇Anaconda的安装教程:Windows下,Anaconda安装教程(保姆级)

2. 检查CUDA和CuDNN是否安装

  1. 如果需要GPU进行训练,需要安装计算框架CUDA和深度学习工具包cudnn,输入以下指令安装
(soar) C:\Users\Jon.SCORPIONE>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Wed_Jun__2_19:25:35_Pacific_Daylight_Time_2021
Cuda compilation tools, release 11.4, V11.4.48
Build cuda_11.4.r11.4/compiler.30033411_0
  1. 如果没有出现以上提示,则证明没有安装
  2. 如果没有安装,请参考这篇安装教程:Windows下,Cuda和cudnn安装教程(保姆级)

3. 检查conda环境中的Python 版本

  1. 输入以下代码检查soar这个环境中的python的版本
(soar) C:\Users\Jon.SCORPIONE>python -V
Python 3.6.13 :: Anaconda, Inc.
  1. 如果不知道anaconda的环境的操作,可以参考这篇文章:windows下,anaconda创建、查询、删除环境

4. 安装GPU版Tesorflow

  1. 输入以下指令安装Tensorflow
(soar) C:\Users\Jon.SCORPIONE>pip install tensorflow-gpu
  1. 得到以下结果,则证明安装成功
Successfully installed absl-py-0.15.0 astunparse-1.6.3 cached-property-1.5.2 cachetools-4.2.4 clang-5.0 
flatbuffers-1.12 gast-0.4.0 google-auth-2.3.3 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.41.1 h5py-
3.1.0 keras-2.7.0 keras-preprocessing-1.1.2 markdown-3.3.4 oauthlib-3.1.1 opt-einsum-3.3.0 protobuf-3.19.1 
pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-oauthlib-1.3.0 rsa-4.7.2 six-1.15.0 tensorboard-2.7.0 tensorboard-
data-server-0.6.1 tensorboard-plugin-wit-1.8.0 tensorflow-estimator-2.6.0 tensorflow-gpu-2.6.1 termcolor-1.1.0
 typing-extensions-3.7.4.3 werkzeug-2.0.2 wrapt-1.12.1

5. 进一步验证Tensorflow是否安装成功

  1. 输入以下指令,进入Python脚本模式
(soar) C:\Users\Jon.SCORPIONE>python
Python 3.6.13 |Anaconda, Inc.| (default, Mar 16 2021, 11:37:27) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
  1. 输入以下指令,导入tensorflow包,若报错,则安装失败
>>> import tensorflow as tf
  1. 输入以下指令,检查GPU是否可用
>>> tf.test.is_gpu_available()
  1. 得到以下结果证明安装cuda和tensorflow成功
WARNING:tensorflow:From <stdin>:1: is_gpu_available (from tensorflow.python.framework.test_util) is 
deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2021-11-09 14:49:50.357138: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is
optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in 
performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-11-09 14:49:52.267842: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device
/device:GPU:0 with 3967 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 2060, pci bus id: 0000:01:00.0, 
compute capability: 7.5
True

猜你喜欢

转载自blog.csdn.net/weixin_42279212/article/details/121227333