【深度学习笔记】——win10安装tensorflow-gpu==2.0.0-rc0

目 录

  • 1 安装CUDA10.0(注意不是10.1)和CUDNN for CUDA 10.0
  • 2 安装tensorflow

1 安装CUDA10.0(注意不是10.1)和CUDNN for CUDA 10.0

  因为前面安装过tensorflow-gpu 1.13,所以这里不详细介绍了,有兴趣可以看那个帖子。安装2.0最大的不同就是用CUDA10.1无法正确安装,所以先把CUDA都卸载之后再安装10.0的版本

  • 卸载tensorflow 1.13

pip uninstall tensorflow-gpu

  • CUDA10.0下载地址

  • 取消勾选“GeForce Experience”

  • 查看“Driver comonents”

  前面的序列号是CUDA种包含的驱动版本,后面的是你计算机中的驱动版本,如果当前版本更高,那么该项也取消勾选

  • 可能提示安装Visual Studio

  绝大部分计算机中是有适应的版本的,所以不会提示,如果没有那么可以先安装,另一种可能是计算机中有更高的版本,比如2019,那么直接勾选“忽略该提示”继续安装就可以了

  • 安装完毕,检查CUDA成功安装

  安装目录的bin路径下有nvcc.exe

  安装目录的extras/CUPTI/libx64下有cuti64.dll

  • CUDNN下载地址

  需要注册一个用户

  选择对应CUDA版本的CUDNN

  • 将下载后的文件解压到CUDA的安装路径下

  直接覆盖就可以

  • 新增环境变量

  将以下三个变量增加到系统变量的Path中

C:\NVIDIA\CUDAv10.0\bin

C:\NVIDIA\CUDAv10.0\include

C:\NVIDIA\CUDAv10.0\lib\x64
  • 测试CUDA

  cmd下运行nvcc -V显示版本为10.0说明成功安装CUDN

2 安装tensorflow

  直接在cmd中运行

pip install tensorflow-gpu==2.0.0-rc0

至此安装完毕,可以在python中运行tf.test.is_gpu_available(),显示True说明成功,也可以跑一个小的程序进行尝试

import tensorflow as tf

tf.__version__

‘2.0.0-rc0’

tf.test.is_gpu_available()

True

model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(32, activation='relu'))
model.add(tf.keras.layers.Dense(32, activation='relu'))
model.add(tf.keras.layers.Dense(10, activation='softmax'))

model.compile(optimizer=tf.keras.optimizers.Adam(0.001),
             loss=tf.keras.losses.categorical_crossentropy,
             metrics=[tf.keras.metrics.categorical_accuracy])
import numpy as np

train_x = np.random.random((1000, 72))
train_y = np.random.random((1000, 10))

val_x = np.random.random((200, 72))
val_y = np.random.random((200, 10))

model.fit(train_x, train_y, epochs=10, batch_size=100,
          validation_data=(val_x, val_y))

Train on 1000 samples, validate on 200 samples
Epoch 1/10
1000/1000 [] - 1s 727us/sample - loss: 11.9072 - categorical_accuracy: 0.1020 - val_loss: 12.3786 - val_categorical_accuracy: 0.0750
Epoch 2/10
1000/1000 [
] - 0s 33us/sample - loss: 12.3815 - categorical_accuracy: 0.1050 - val_loss: 13.1911 - val_categorical_accuracy: 0.0750
Epoch 3/10
1000/1000 [] - 0s 35us/sample - loss: 13.4550 - categorical_accuracy: 0.1020 - val_loss: 14.6454 - val_categorical_accuracy: 0.0800
Epoch 4/10
1000/1000 [
] - 0s 34us/sample - loss: 15.3618 - categorical_accuracy: 0.1050 - val_loss: 17.2383 - val_categorical_accuracy: 0.0800
Epoch 5/10
1000/1000 [] - 0s 36us/sample - loss: 18.5347 - categorical_accuracy: 0.1050 - val_loss: 20.9539 - val_categorical_accuracy: 0.0800
Epoch 6/10
1000/1000 [
] - 0s 34us/sample - loss: 22.3715 - categorical_accuracy: 0.1150 - val_loss: 24.9382 - val_categorical_accuracy: 0.1250
Epoch 7/10
1000/1000 [] - 0s 38us/sample - loss: 26.4199 - categorical_accuracy: 0.1070 - val_loss: 28.8979 - val_categorical_accuracy: 0.0800
Epoch 8/10
1000/1000 [
] - 0s 36us/sample - loss: 29.4841 - categorical_accuracy: 0.1160 - val_loss: 30.7806 - val_categorical_accuracy: 0.1050
Epoch 9/10
1000/1000 [] - 0s 37us/sample - loss: 31.0540 - categorical_accuracy: 0.1110 - val_loss: 32.7501 - val_categorical_accuracy: 0.0900
Epoch 10/10
1000/1000 [
] - 0s 36us/sample - loss: 34.7381 - categorical_accuracy: 0.1130 - val_loss: 38.8677 - val_categorical_accuracy: 0.0750

你可能感兴趣的:(深度学习,tensorflow2.0,gpu,win10,安装,python,深度学习)