TensorFlow GPU Anaconda ubuntu安装

5 篇文章 0 订阅
4 篇文章 1 订阅

1. Anaconda 安装
官方网站下载安装包,直接执行即可。

bash Anaconda3-4.3.1-Linux-x86_64.sh  #Python 3.5 版本

查询安装信息

conda info

查询当前已经安装的库

conda list

安装库

conda install pkg_name

更新库

conda update pkg_name
conda update -- all #更新所有包

更新Anaconda

conda update conda

2. Tensorflow 安装

官方下载更新工具包的速度很慢,所以继续添加清华大学 TUNA提供的Anaconda仓库镜像

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
conda install numpy   #测试是否添加成功

Tensorflow安装
新建Anaconda 环境:

conda create -n tensorflow python=3.6

激活tensorflow虚拟环境(之后的使用每次也都要先激活虚拟环境才可用):

source activate tensorflow

关闭tensorflow虚拟环境:

source deactivate

命令搜索当前可用的tensorflow版本

anaconda search -t conda tensorflow

选择需要的版本:

anaconda show anaconda/tensorflow-gpu

从打印出的命令安装:

conda install --channel https://conda.anaconda.org/anaconda tensorflow-gpu

测试安装

source activate tensorflow
python
import tensorflow as tf
tf.__version__
输:'1.8.0'

遇到问题:
session = tf.session()

E tensorflow/core/common_runtime/direct_session.cc:154] Internal: CUDA runtime implicit initialization on GPU:0 failed. Status: unknown error

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1" #设置使用的GPU,并没用解决使用GPU的问题。
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
session = tf.Session()
print(sess.run(hello))

输出:
2018-06-24 20:35:02.462192: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-06-24 20:35:02.470414: E tensorflow/stream_executor/cuda/cuda_driver.cc:406] failed call to cuInit: CUDA_ERROR_NO_DEVICE
2018-06-24 20:35:02.470590: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:158] retrieving CUDA diagnostic information for host: zc-GE62-2QD
2018-06-24 20:35:02.470633: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:165] hostname: zc-GE62-2QD
2018-06-24 20:35:02.470778: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:189] libcuda reported version is: 384.130.0
2018-06-24 20:35:02.470887: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:193] kernel reported version is: 384.130.0
2018-06-24 20:35:02.470925: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:300] kernel version seems to match DSO: 384.130.0

这是由于TensorFlow 使用的是Cuda-9.2的驱动版本,可参照tensorflow官网的介绍:tf安装指导
并参照其中的CUDA安装链接:cuda 安装链接
本人下载了.run的安装文件:cuda_9.2.88_396.26_linux.run 和 cuda_9.2.88.1_linux.run, 先安装前者。
安装命令:

sudo ./cuda_9.2.88_396.26_linux.run
sudo ./cuda_9.2.88.1_linux.run

注意:安装CUDA驱动需要ctrl+alt+f1, 进入tty命令行安装,并关闭x-config:sudo service lightdm stop
另外,安装的时候需要注意不要安装open-gl选项,不选择nvidia-xconfig选项,选择上述选项会导致重启后
进入登录界面的无限循环,如果不幸进入了循环,请参照恢复链接:登录循环恢复链接

测试:

(tensorflow) zc@zc-GE62-2QD:~$ python
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:51:32) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('hello, Tensorflow')
>>> session=tf.Session()
2018-07-28 00:02:35.801458: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-07-28 00:02:35.986928: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-07-28 00:02:35.987282: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 0 with properties: 
name: GeForce GTX 960M major: 5 minor: 0 memoryClockRate(GHz): 1.176
pciBusID: 0000:01:00.0
totalMemory: 1.96GiB freeMemory: 1.92GiB
2018-07-28 00:02:35.987302: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0
2018-07-28 00:05:14.965212: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-07-28 00:05:14.965244: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929]      0 
2018-07-28 00:05:14.965253: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0:   N 
2018-07-28 00:05:14.965397: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1687 MB memory) -> physical GPU (device: 0, name: GeForce GTX 960M, pci bus id: 0000:01:00.0, compute capability: 5.0)
>>> print(session.run(hello))
b'hello, Tensorflow'
>>> 

终于配置GPU 成功,接下来的一个博客将实现CNN 和 RNN的Mnist识别实现代码。

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值