最近学习深度学习,在配置环境中的过程中遇到很多问题,在这进行总结,希望对大家有帮助。
一、整个软件安装配置过程,很多博客写的很详细,附上链接;
https://blog.csdn.net/qq_36026791/article/details/88793488 https://blog.csdn.net/huanyingzhizai/article/details/89298964二、安装完成后测试如下;
整个tensorflow测试过程
(base) C:\Users\Wang>activate tensorflow--gpu//激活tensorflow环境
(tensorflow--gpu) C:\Users\Wang>python
Python 3.6.10 |Anaconda, Inc.| (default, Jan 7 2020, 15:18:16) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from tensorflow.python.client import device-lib
File "", line 1
from tensorflow.python.client import device-lib
^
SyntaxError: invalid syntax
>>> from tensorflow.python.client import device_lib
>>> print(device_lib.list_local_devices())
2020-03-08 09:44:53.011007: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-03-08 09:44:53.892132: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 0 with properties:
name: GeForce MX150 major: 6 minor: 1 memoryClockRate(GHz): 1.0375
pciBusID: 0000:01:00.0
totalMemory: 2.00GiB freeMemory: 1.62GiB
2020-03-08 09:44:53.914731: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2020-03-08 09:44:55.706053: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-03-08 09:44:55.722874: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0
2020-03-08 09:44:55.731764: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0: N
2020-03-08 09:44:55.746369: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/device:GPU:0 with 1364 MB memory) -> physical GPU (device: 0, name: GeForce MX150, pci bus id: 0000:01:00.0, compute capability: 6.1)
[name: "/device:CPU:0"
device_type: "CPU" //抓到CPU
memory_limit: 268435456
locality {
}
incarnation: 17524159819158732381
, name: "/device:GPU:0"
device_type: "GPU" //抓到GPU
memory_limit: 1431112499
locality {
bus_id: 1
links {
}
}
incarnation: 5191225488240913321
physical_device_desc: "device: 0, name: GeForce MX150, pci bus id: 0000:01:00.0, compute capability: 6.1"
]
>>> import tensorflow as tf
>>> gjm = tf.constant("Hello World ! I love TensorFlow ! ")
>>> sess = tf.Session()
2020-03-08 09:46:10.621388: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2020-03-08 09:46:11.108336: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-03-08 09:46:11.124001: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0
2020-03-08 09:46:11.133490: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0: N
2020-03-08 09:46:11.264295: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1364 MB memory) -> physical GPU (device: 0, name: GeForce MX150, pci bus id: 0000:01:00.0, compute capability: 6.1)
>>> print (sess.run(gjm))
2020-03-08 09:46:44.969417: E tensorflow/core/grappler/clusters/utils.cc:83] Failed to get device properties, error code: 30
b'Hello World ! I love TensorFlow ! ' //输出
>>> sess.close()
>>>
查看cuda是否安装成功
其他过程参见链接博客
三、遇到的几个问题;
首先是在安装过程中,python、tensorflow、Cuda版本的对应,这里我的版本如下:python3.6(在安装Anaconda3时候自带为python3.7,这里在Anaconda Prompt里执行降版本,降为3.6即可)、tensorflow1.14rc0、Cuda 10.0。如果版本有问题,不兼容,后面测试会一直报错。
Cuda 10.0安装完成后,一定要配置环境变量,具体如下:检查一下环境变量 我的电脑—> 属性—> 高级系统设置—> 环境变量—>系统变量
确认环境变量,CUDA_PATH和CUDA_PATH_V10已经存在
依此添加下列三个路径到Path里
C:\NVIDIA\CUDAv10.1\bin
C:\NVIDIA\CUDAv10.1\include
C:\NVIDIA\CUDAv10.1\lib\x64
否则在Windows CMD命令窗口执行 nvcc -V 的时候,会发生错误,查不到Cuda版本信息,并且在后续测试Tensorflow的时候,会发生如下错误找不到指定模块
安装tensorflow,如果直接使用镜像,下载速度非常慢,而且容易出现错误。这里推荐使用清华镜像pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-gpu==1.14.0rc0
还有一点,在安装完tensorflow后,一般会同时安装numpy,但是自带的numpy版本过高,会出现以下错误
这里对numpy进行降版本操作就行。
就是先卸载原来的numpy pip uninstall numpy 然后用清华镜像重新安装pip install -i https://pypi.tuna.tainghua.edu.cn/simple numpy==1.16.0
以上是我遇到的一些问题及坑的解决方法,欢迎大家参考,有问题留言交流。
作者:长安二十四小时