机器学习笔记 - win10安装tensorflow-gpu.2.2 + Cuda10+cudnn7.6.5

一、条件说明

win10操作系统

GTX 750 Ti

Anaconda

PyCharm 2019.3.4 x64

PS:最终运行成功的环境是,

tensorflow-gpu 2.2

cuda_10.1.105_418.96_win10.exe

cudnn-10.0-windows10-x64-v7.6.5.32.zip

二、安装步骤

1、安装Anaconda及搭建基本的环境,可以参考,https://blog.csdn.net/bashendixie5/article/details/109803329

但是不要安装cpu版本的tensorflow,安装gpu版本的,默认会安装最新的,目前是2.3.1。但是后面运行失败,所以卸载重新安装了2.2版本)

2、安装cuda和cudnn,安装什么版本的,查看网址:https://www.tensorflow.org/install/source_windows

3、下载cudatoolkit,下载地址https://developer.nvidia.com/cuda-toolkit-archive,找到对应版本

4、下载cudnn,下载地址https://developer.nvidia.com/rdp/cudnn-archive,需要登陆。

但是安装cuDNN7.4,运行的时候报了错误,后又下载了cudnn-10.0-windows10-x64-v7.6.5.32.zip版本,运行正常。

5、先安装cudatoolkit,下一步下一步就好。

6、解压cudnn,并将解压出来的文件copy到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0中。

三、遇到的问题

1、运行时报异常 “[Op:Assert] name: EagerVariableNameReuse ”,卸载掉了2.3.1,安装了2.2版本,不再出现这个异常。

2、再次运行时,“Loaded runtime CuDNN library: 7.4.2 but source was compiled with: 7.6.5.  CuDNN library major and minor version needs to match or have higher minor version in case of CuDNN 7.0 or later version. If using a binary install, upgrade your CuDNN library.  If building from sources, make sure the library loaded at runtime is compatible with the version specified during compile configuration.”。

所以又下载了v7.6.5.32.zip版本覆盖了7.4版本的cudnn文件,就可以正常运行了。

四、性能比较测试

使用了https://blog.csdn.net/bashendixie5/article/details/109754138手写数字识别训练

model.fit(x_train, y_train, epochs=100, batch_size=128, validation_split=0.1)

epochs=100的时候

cpu版本(core i7)需要大概37分钟能完成

gpu版本(750Ti)需要大概7分钟能完成,还是快了不少的,毕竟显卡有些渣。

D:\deeplearn\tensorflow1\python.exe D:/deeplearn/pyenv/venv/second.py
2020-11-28 14:19:59.355241: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-11-28 14:20:22.142186: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-11-28 14:20:22.317415: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GTX 750 Ti computeCapability: 5.0
coreClock: 1.0845GHz coreCount: 5 deviceMemorySize: 2.00GiB deviceMemoryBandwidth: 80.47GiB/s
2020-11-28 14:20:22.317872: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-11-28 14:20:22.332031: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-11-28 14:20:22.340662: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-11-28 14:20:22.345845: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-11-28 14:20:22.356066: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-11-28 14:20:22.370024: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-11-28 14:20:22.752723: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-11-28 14:20:22.753920: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-11-28 14:20:22.764530: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1637a433390 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-11-28 14:20:22.764882: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-11-28 14:20:22.765845: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GTX 750 Ti computeCapability: 5.0
coreClock: 1.0845GHz coreCount: 5 deviceMemorySize: 2.00GiB deviceMemoryBandwidth: 80.47GiB/s
2020-11-28 14:20:22.766278: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-11-28 14:20:22.766498: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-11-28 14:20:22.766718: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-11-28 14:20:22.766938: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-11-28 14:20:22.767156: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-11-28 14:20:22.767378: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-11-28 14:20:22.767598: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-11-28 14:20:22.768827: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-11-28 14:20:26.583398: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-11-28 14:20:26.583633: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
2020-11-28 14:20:26.583744: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
2020-11-28 14:20:26.584779: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:39] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.
2020-11-28 14:20:26.585044: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1365 MB memory) -> physical GPU (device: 0, name: GeForce GTX 750 Ti, pci bus id: 0000:01:00.0, compute capability: 5.0)
2020-11-28 14:20:26.588321: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x16319eae0e0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-11-28 14:20:26.588545: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce GTX 750 Ti, Compute Capability 5.0
Epoch 1/100
2020-11-28 14:20:27.462037: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-11-28 14:20:28.747728: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-11-28 14:20:30.914185: W tensorflow/stream_executor/gpu/redzone_allocator.cc:314] Internal: Invoking GPU asm compilation is supported on Cuda non-Windows platforms only
Relying on driver to perform ptx compilation. 
Modify $PATH to customize ptxas location.
This message will be only logged once.
422/422 [==============================] - 5s 11ms/step - loss: 0.3077 - sparse_categorical_accuracy: 0.9085 - val_loss: 0.0729 - val_sparse_categorical_accuracy: 0.9783
Epoch 2/100
422/422 [==============================] - 4s 10ms/step - loss: 0.0737 - sparse_categorical_accuracy: 0.9773 - val_loss: 0.0613 - val_sparse_categorical_accuracy: 0.9825
Epoch 3/100
422/422 [==============================] - 4s 10ms/step - loss: 0.0511 - sparse_categorical_accuracy: 0.9845 - val_loss: 0.0516 - val_sparse_categorical_accuracy: 0.9860
Epoch 4/100
422/422 [==============================] - 4s 10ms/step - loss: 0.0415 - sparse_categorical_accuracy: 0.9870 - val_loss: 0.0456 - val_sparse_categorical_accuracy: 0.9882
Epoch 5/100
422/422 [==============================] - 4s 10ms/step - loss: 0.0337 - sparse_categorical_accuracy: 0.9893 - val_loss: 0.0409 - val_sparse_categorical_accuracy: 0.9900
Epoch 6/100
422/422 [==============================] - 4s 10ms/step - loss: 0.0292 - sparse_categorical_accuracy: 0.9904 - val_loss: 0.0398 - val_sparse_categorical_accuracy: 0.9895
Epoch 7/100
422/422 [==============================] - 4s 10ms/step - loss: 0.0249 - sparse_categorical_accuracy: 0.9919 - val_loss: 0.0385 - val_sparse_categorical_accuracy: 0.9910
Epoch 8/100

猜你喜欢

转载自blog.csdn.net/bashendixie5/article/details/110260615