tensorflow-GPU安装文档

1.Anaconda安装

官网下载地址

https://www.anaconda.com/products/individual

安装流程

清华源安装torch gpu版 清华源下载tensorflow_清华源安装torch gpu版

清华源安装torch gpu版 清华源下载tensorflow_python_02

清华源安装torch gpu版 清华源下载tensorflow_清华源安装torch gpu版_03

清华源安装torch gpu版 清华源下载tensorflow_深度学习_04

注意:此处要****勾选第一项Add Anaconda3 to my PATH environment variable****

2.安装tensorflow

1、打开Anaconda Prompt

清华源安装torch gpu版 清华源下载tensorflow_深度学习_05

2.在Anaconda Prompt中更换清华源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

即可添加 Anaconda Python 免费仓库。

3.新建一个TF2.1的环境 用python3.7的版本

conda create -n TF2.1 python=3.7

清华源安装torch gpu版 清华源下载tensorflow_人工智能_06

4.安装tensorflow

首先进入tensorflow环境

conda activate TF2.1

清华源安装torch gpu版 清华源下载tensorflow_清华源安装torch gpu版_07

5.安装英伟达的SDK10.1版本

conda install cudatoolkit=10.1

清华源安装torch gpu版 清华源下载tensorflow_tensorflow_08

出现以上界面一路y即可

同理,安装英伟达深度学习包软件

conda install cudnn=7.6

清华源安装torch gpu版 清华源下载tensorflow_tensorflow_09

如果出错,说明电脑不支持,或者有可能是源没挂对,自行百度解决

3.安装tensorflow

pip install tensorflow==2.1

清华源安装torch gpu版 清华源下载tensorflow_tensorflow_10

  1. 进入 python 验证是否安装成功
    进入python
    输入import tensorflow as tf 导入
    然后输入 tf.version 查看版本
(TF2.1) C:\Users\tsl115>python
Python 3.7.11 (default, Jul 27 2021, 09:42:29) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2022-02-28 20:39:57.511027: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
>>> tf__version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'tf__version' is not defined
>>> tf.__version__
'2.1.0'
>>>

清华源安装torch gpu版 清华源下载tensorflow_清华源安装torch gpu版_11

如果显示和我差不多,说明安装成功

3.安装pycharm社区版

直接进官网下载社区版即可,具体百度就有,不会csdn上有很多教程

清华源安装torch gpu版 清华源下载tensorflow_python_12

清华源安装torch gpu版 清华源下载tensorflow_人工智能_13

需要注意这一步,其他傻瓜式

进入pycharm进行配置测试

清华源安装torch gpu版 清华源下载tensorflow_深度学习_14

清华源安装torch gpu版 清华源下载tensorflow_深度学习_15

清华源安装torch gpu版 清华源下载tensorflow_人工智能_16


清华源安装torch gpu版 清华源下载tensorflow_人工智能_17


清华源安装torch gpu版 清华源下载tensorflow_python_18


清华源安装torch gpu版 清华源下载tensorflow_清华源安装torch gpu版_19

输入代码进行测试

import tensorflow as tf

tensorflow_version = tf.__version__
gpu_available = tf.test.is_gpu_available()

print("tensorflow version:", tensorflow_version, "\tGPU available:", gpu_available)

a = tf.constant([1.0, 2.0], name="a")
b = tf.constant([1.0, 2.0], name="b")
result = tf.add(a, b, name="add")
print(result)

清华源安装torch gpu版 清华源下载tensorflow_深度学习_20