欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

win10 conda安装tensorflow-gpu+cuda+cudnn

程序员文章站 2022-03-17 08:48:49
...

准备

  1. conda会为你的电脑自动安装匹配的适合的tensorflow-gpu,cuda,cudnn无需自己复杂的查找,但是前提条件是你的anaconda没问题,下载的镜像源也没问题,conda不熟悉的推荐百度一下学习真的很好用。
  2. 下载安装anacond。
  3. 创建虚拟环境,除非特殊需求否则强烈建议新建环境避免奇怪错误。
  4. python版本3.6。
  5. 更换镜像,下载更快且一些镜像太旧可能会导致失败至少我这次镜像是成功的,如果你能高速度连接anaconda的国外服务器最好,肯定最新,就不需要这一步了,我一开始是清华某镜像但是听说停用了,又找了最新的。
    参考:更换清华源镜像
  6. 更新conda,如果你原先安装过anaconda,可能不是最新的了推荐更新一下,可以尝试输入conda install numpy,如果不是最新版本会有警告并提醒你升级conda。
  7. 其中4,5步最好都做我一开始没做出现了错误,在import tensorflow时会出现 ImportError: DLL load failed:Failed to load the native 之类的,很多错误报告忘记截图了。原因应该是镜像或者是conda非最新导致下载少东西了,如图
    图一:正确执行4,5步骤后下载的文件,这里还没列完超过一页显示了win10 conda安装tensorflow-gpu+cuda+cudnn
    图二:抱歉没有截图也复现不了,但是写出来也能理解,4,5步没有执行,下载的文件就8-10个左右。tensorflow只有一个版本就是tensorflow-gpu。
    而图一的安装完后会有4个
    tensorflow
    tensorflow-base
    tensorflow-estimator
    tensorflow-gpu
    其他还有各种需求的依赖包也安装了,所以我估计错误原因是少安装了很多东西导致的,解决方法就是更新anaconda和源

安装

其实搞定准备步骤后安装就非常简单了conda帮你搞定一切复杂问题

conda install tensorflow-gpu

测试

python
>>> import tensorflow as tf
>>> tf.compat.v1.Session()

若成功安装会出现,自己机器的GPU信息等内容

2020-01-08 16:45:10.116345: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-01-08 16:45:10.191656: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce GTX 1060 6GB major: 6 minor: 1 memoryClockRate(GHz): 1.7335
pciBusID: 0000:01:00.0
2020-01-08 16:45:10.198283: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2020-01-08 16:45:10.203311: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2020-01-08 16:45:10.206730: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2020-01-08 16:45:10.215299: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce GTX 1060 6GB major: 6 minor: 1 memoryClockRate(GHz): 1.7335
pciBusID: 0000:01:00.0
2020-01-08 16:45:10.221127: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2020-01-08 16:45:10.226595: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2020-01-08 16:45:10.995465: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-01-08 16:45:11.000585: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0
2020-01-08 16:45:11.002715: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N
2020-01-08 16:45:11.006338: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4708 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 6GB, pci bus id: 0000:01:00.0, compute capability: 6.1)
<tensorflow.python.client.session.Session object at 0x000002452E910518>
相关标签: 环境配置