win10+Anconda3+CUDA10.0+tensorfow-gpu2.0环境搭建教程

去年的时候装过一次但是没有写博客,导致磁盘崩溃后资料全无,现在又看到win10已经支持cuda10了,特地写下安装过程

一 安装anconda 3

搜索官网下载安装即可,不用配置环境变量,用的时候打开专属的终端就好,aconda的使用教程在这里就不说了

win10+Anconda3+CUDA10.0+tensorfow-gpu2.0环境搭建教程_第1张图片

 

在终端上创建一个环境

conda create --name tf python=3.6
activate tf
pip install tensorflow-gpu

pip下载失败可以用下面的方法

镜像源

清华:https://pypi.tuna.tsinghua.edu.cn/simple

阿里云:https://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

华中理工大学:http://pypi.hustunique.com/

山东理工大学:http://pypi.sdutlinux.org/ 

豆瓣:http://pypi.douban.com/simple/

临时使用:

可以在使用pip的时候加参数-i https://pypi.tuna.tsinghua.edu.cn/simple

例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider,这样就会从清华这边的镜像去安装pyspider库

 

二 安装CUDA

CUDA历史版本档案网址https://developer.nvidia.com/cuda-toolkit-archive

CUDA是n卡的一个用来并行计算的驱动,可以配合加速tensorflow

win10+Anconda3+CUDA10.0+tensorfow-gpu2.0环境搭建教程_第2张图片

 

选择下载离线包,完成后点击安装就可以了,直接选择精简安装即可。点击后会让你选择一个空件夹用来临时解压安装,安装完会自动删除(10.2不会删),选择一个有足够空间的就好了,CUDA的真实安装路径在C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0

win10+Anconda3+CUDA10.0+tensorfow-gpu2.0环境搭建教程_第3张图片

 

然后需要配置环境变量

在cuda_path_v10j加上这两个,原因是不加上tensorflow没法访问到bin目录,windows问题吧。。。

win10+Anconda3+CUDA10.0+tensorfow-gpu2.0环境搭建教程_第4张图片

三 安装cuDNN

CUDnn下载地址https://developer.nvidia.com/rdp/cudnn-download

这是cuda的一个补丁,用来加速深度学习的一些运算的,特地针对深度学习进行优化了

需要注册登录可以用QQ登录然后填个调查问卷就可以下载了,然后选择对应的版本

win10+Anconda3+CUDA10.0+tensorfow-gpu2.0环境搭建教程_第5张图片

 

下载后解压得到一个文件夹,将里面的东西复制到cuda对应的文件夹就可以了

win10+Anconda3+CUDA10.0+tensorfow-gpu2.0环境搭建教程_第6张图片

 

四 测试

 

##tensorflow1.0
import tensorflow as tf
tf.Session()

#tensorflow2.0 禁用2.0特性兼用1.0,因为我不会2.0
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
tf.Session()

成功

win10+Anconda3+CUDA10.0+tensorfow-gpu2.0环境搭建教程_第7张图片

可以观察到上面有个不支持cpu AVX2编译的信息,暂时忽略,加上下面的第一第三行代码就行

上面不是成功出错了

原因是没装驱动https://blog.csdn.net/miao0967020148/article/details/85248560

下面才是成功

win10+Anconda3+CUDA10.0+tensorfow-gpu2.0环境搭建教程_第8张图片


import os  
os.environ["TF_CPP_MIN_LOG_LEVEL"]='1' # 这是默认的显示等级,显示所有信息  
os.environ["TF_CPP_MIN_LOG_LEVEL"]='2' # 只显示 warning 和 Error   
os.environ["TF_CPP_MIN_LOG_LEVEL"]='3' # 只显示 Error 

需要彻底解决的话需要自己编译tensorflow,网上有轮子但是还不如自己编译,有空再说

五 总结与思考

 

进入命令行环境下,首先通过python --version确定自己的python版本是3.6.9
再通过pip list查看已经安装好的tensorflow版本,笔者本人的版本是2.0
通过nvcc --version查看cuda版本,笔者之前的cuda版本是release 10.0, V10.0.130;

经过一天的折腾终于配置好了,血的教训就是要去官网看版本适配问题,实测上面的是可以的(换成py37和tf1.14也可以),下面是我从官网找的一些版本适配图

 

win10+Anconda3+CUDA10.0+tensorfow-gpu2.0环境搭建教程_第9张图片

 

下面是尝试过程中的一个报错,最新的tensorflow2.0目前只支持cuda10.0,我试过cuda9.0和cuda10.2都会发生以下错误,不能找到一个动态库cudart64_100.dll  后面的100表示10.0

win10+Anconda3+CUDA10.0+tensorfow-gpu2.0环境搭建教程_第10张图片

 

后来去官网查了下

win10+Anconda3+CUDA10.0+tensorfow-gpu2.0环境搭建教程_第11张图片

所以想用cuda9还得安装tf的历史版本,方法是

pip install tensorflow-gpu==1.12

 

后记

装这个环境是为了跑一个fcn语义分割的代码,然后出现了以下问题

WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:283: The name tf.app.run is deprecated. Please use tf.compat.v1.app.run instead.

WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:184: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

W1202 21:08:40.419945  9692 deprecation_wrapper.py:119] From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:184: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

setting up vgg initialized conv layers ...
WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:100: The name tf.variable_scope is deprecated. Please use tf.compat.v1.variable_scope instead.

W1202 21:08:40.933573  9692 deprecation_wrapper.py:119] From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:100: The name tf.variable_scope is deprecated. Please use tf.compat.v1.variable_scope instead.

WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\TensorflowUtils.py:67: calling Constant.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
W1202 21:08:40.934570  9692 deprecation.py:506] From D:\计算机视觉系统\FCN-TensorFlow-master\TensorflowUtils.py:67: calling Constant.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\TensorflowUtils.py:68: The name tf.get_variable is deprecated. Please use tf.compat.v1.get_variable instead.

W1202 21:08:40.935567  9692 deprecation_wrapper.py:119] From D:\计算机视觉系统\FCN-TensorFlow-master\TensorflowUtils.py:68: The name tf.get_variable is deprecated. Please use tf.compat.v1.get_variable instead.

WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\TensorflowUtils.py:241: The name tf.summary.histogram is deprecated. Please use tf.compat.v1.summary.histogram instead.

W1202 21:08:40.944542  9692 deprecation_wrapper.py:119] From D:\计算机视觉系统\FCN-TensorFlow-master\TensorflowUtils.py:241: The name tf.summary.histogram is deprecated. Please use tf.compat.v1.summary.histogram instead.

WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\TensorflowUtils.py:242: The name tf.summary.scalar is deprecated. Please use tf.compat.v1.summary.scalar instead.

W1202 21:08:40.947566  9692 deprecation_wrapper.py:119] From D:\计算机视觉系统\FCN-TensorFlow-master\TensorflowUtils.py:242: The name tf.summary.scalar is deprecated. Please use tf.compat.v1.summary.scalar instead.

WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\TensorflowUtils.py:128: The name tf.nn.avg_pool is deprecated. Please use tf.nn.avg_pool2d instead.

W1202 21:08:40.996436  9692 deprecation_wrapper.py:119] From D:\计算机视觉系统\FCN-TensorFlow-master\TensorflowUtils.py:128: The name tf.nn.avg_pool is deprecated. Please use tf.nn.avg_pool2d instead.

WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\TensorflowUtils.py:124: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.

W1202 21:08:42.516366  9692 deprecation_wrapper.py:119] From D:\计算机视觉系统\FCN-TensorFlow-master\TensorflowUtils.py:124: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.

WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\TensorflowUtils.py:74: The name tf.truncated_normal is deprecated. Please use tf.random.truncated_normal instead.

W1202 21:08:42.519367  9692 deprecation_wrapper.py:119] From D:\计算机视觉系统\FCN-TensorFlow-master\TensorflowUtils.py:74: The name tf.truncated_normal is deprecated. Please use tf.random.truncated_normal instead.

WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:112: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.
Instructions for updating:
Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.
W1202 21:08:42.562251  9692 deprecation.py:506] From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:112: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.
Instructions for updating:
Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.
WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:161: calling argmax (from tensorflow.python.ops.math_ops) with dimension is deprecated and will be removed in a future version.
Instructions for updating:
Use the `axis` argument instead
W1202 21:08:42.664972  9692 deprecation.py:506] From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:161: calling argmax (from tensorflow.python.ops.math_ops) with dimension is deprecated and will be removed in a future version.
Instructions for updating:
Use the `axis` argument instead
WARNING:tensorflow:From C:\aconda\lib\site-packages\tensorflow\python\util\dispatch.py:180: calling expand_dims (from tensorflow.python.ops.array_ops) with dim is deprecated and will be removed in a future version.
Instructions for updating:
Use the `axis` argument instead
W1202 21:08:42.667932  9692 deprecation.py:506] From C:\aconda\lib\site-packages\tensorflow\python\util\dispatch.py:180: calling expand_dims (from tensorflow.python.ops.array_ops) with dim is deprecated and will be removed in a future version.
Instructions for updating:
Use the `axis` argument instead
WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:192: The name tf.summary.image is deprecated. Please use tf.compat.v1.summary.image instead.

W1202 21:08:42.731761  9692 deprecation_wrapper.py:119] From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:192: The name tf.summary.image is deprecated. Please use tf.compat.v1.summary.image instead.

WARNING:tensorflow:From C:\aconda\lib\site-packages\tensorflow\python\util\dispatch.py:180: calling squeeze (from tensorflow.python.ops.array_ops) with squeeze_dims is deprecated and will be removed in a future version.
Instructions for updating:
Use the `axis` argument instead
W1202 21:08:42.739740  9692 deprecation.py:506] From C:\aconda\lib\site-packages\tensorflow\python\util\dispatch.py:180: calling squeeze (from tensorflow.python.ops.array_ops) with squeeze_dims is deprecated and will be removed in a future version.
Instructions for updating:
Use the `axis` argument instead
WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:202: The name tf.trainable_variables is deprecated. Please use tf.compat.v1.trainable_variables instead.

W1202 21:08:42.766696  9692 deprecation_wrapper.py:119] From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:202: The name tf.trainable_variables is deprecated. Please use tf.compat.v1.trainable_variables instead.

WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:173: The name tf.train.AdamOptimizer is deprecated. Please use tf.compat.v1.train.AdamOptimizer instead.

W1202 21:08:42.840503  9692 deprecation_wrapper.py:119] From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:173: The name tf.train.AdamOptimizer is deprecated. Please use tf.compat.v1.train.AdamOptimizer instead.

Setting up summary op...
WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:212: The name tf.summary.merge_all is deprecated. Please use tf.compat.v1.summary.merge_all instead.

W1202 21:08:43.499740  9692 deprecation_wrapper.py:119] From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:212: The name tf.summary.merge_all is deprecated. Please use tf.compat.v1.summary.merge_all instead.

Setting up image reader...
Found pickle file!
0
0
Setting up dataset reader
Initializing Batch Dataset Reader...
{'resize': True, 'resize_size': 224}
(0,)
(0,)
Initializing Batch Dataset Reader...
{'resize': True, 'resize_size': 224}
(0,)
(0,)
2019-12-02 21:08:43.542603: E tensorflow/stream_executor/cuda/cuda_driver.cc:318] failed call to cuInit: CUDA_ERROR_UNKNOWN: unknown error
Setting up Saver...
WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:231: The name tf.train.Saver is deprecated. Please use tf.compat.v1.train.Saver instead.

W1202 21:08:43.562540  9692 deprecation_wrapper.py:119] From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:231: The name tf.train.Saver is deprecated. Please use tf.compat.v1.train.Saver instead.

WARNING:tensorflow:From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:232: The name tf.summary.FileWriter is deprecated. Please use tf.compat.v1.summary.FileWriter instead.

W1202 21:08:43.736075  9692 deprecation_wrapper.py:119] From D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py:232: The name tf.summary.FileWriter is deprecated. Please use tf.compat.v1.summary.FileWriter instead.

****************** Epochs completed: 1******************
Traceback (most recent call last):
  File "D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py", line 283, in 
    tf.app.run()
  File "C:\aconda\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "C:\aconda\lib\site-packages\absl\app.py", line 299, in run
    _run_main(main, args)
  File "C:\aconda\lib\site-packages\absl\app.py", line 250, in _run_main
    sys.exit(main(argv))
  File "D:\计算机视觉系统\FCN-TensorFlow-master\FCN.py", line 249, in main
    sess.run(train_op, feed_dict=feed_dict)
  File "C:\aconda\lib\site-packages\tensorflow\python\client\session.py", line 950, in run
    run_metadata_ptr)
  File "C:\aconda\lib\site-packages\tensorflow\python\client\session.py", line 1149, in _run
    str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (0,) for Tensor 'input_image:0', which has shape '(?, 224, 224, 3)'

网上查了下好像是cuda10.0和我装的tf1.14不匹配的问题

ValueError: Cannot feed value of shape (0,) for Tensor 'input_image:0', which has shape '(?, 224, 224, 3)'

问题解决https://zhuanlan.zhihu.com/p/61658977,删除一个文件,后面发现是路径问题

https://blog.csdn.net/TeFuirnever/article/details/90760179

最难的是我装好了发现我的3GB显卡跑不了这个代码,默默用了cpu版的然后收敛不了。。。。

 

参考文献

https://blog.csdn.net/fatfatmomo/article/details/81184119Python- 解决PIP下载安装速度慢

https://blog.csdn.net/sb19931201/article/details/53648615Win10 TensorFlow(gpu)安装详解

https://blog.csdn.net/liuyong5573/article/details/85472808win10+cuda10+tensorflow-gpu最新安装教程

https://blog.csdn.net/zhuhaotian/article/details/100379996tensorflow-gpu的一个问题

https://blog.csdn.net/qq_41185868/article/details/79127838#comments成功解决Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2

 

你可能感兴趣的:(机器学习)