在UBUNTU 16.04上配置TensorFlow + cuDNN + CUDA深度学习系统(30分钟傻瓜版)

来源:互联网 发布:下载杂志的软件 编辑:程序博客网 时间:2024/06/05 10:07

新配了一台电脑(i7-7700,GTX1070),装了UBUNTU 16.04,准备折腾折腾tensorflow。

之前看网上林林总总的安装教程,一个个都复杂无比。当然,复杂有复杂的道理,但是我实在是不想又在这台家用电脑上折腾一遍,于是又开始了偷懒大法。

貌似还真可以偷偷懒。


1、安装Anaconda

电信百兆直连官网都只有5K左右的下载速度,推荐去清华大学开源软件站下载。

mirrors.tuna.tsinghua.edu.cn

下载之后顺便把软件源更换了,添加个conda-forge。


2、安装CUDA

推荐改个国内源,速度快得多。

sudo apt-get install nvidia-cuda-toolkit

系统会自动帮你装好所有东西的。

安装完之后重启电脑,测试一下:

talesyuan@TalesYuan:~$ nvcc --versionnvcc: NVIDIA (R) Cuda compiler driverCopyright (c) 2005-2015 NVIDIA CorporationBuilt on Tue_Aug_11_14:27:32_CDT_2015Cuda compilation tools, release 7.5, V7.5.17


talesyuan@TalesYuan:~$ nvidia-smiTue Aug  1 23:07:20 2017       +-----------------------------------------------------------------------------+| NVIDIA-SMI 375.66                 Driver Version: 375.66                    ||-------------------------------+----------------------+----------------------+| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC || Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. ||===============================+======================+======================||   0  GeForce GTX 1070    Off  | 0000:01:00.0      On |                  N/A ||  0%   43C    P8    10W / 180W |    383MiB /  8112MiB |      0%      Default |+-------------------------------+----------------------+----------------------++-----------------------------------------------------------------------------+| Processes:                                                       GPU Memory ||  GPU       PID  Type  Process name                               Usage      ||=============================================================================||    0      1023    G   /usr/lib/xorg/Xorg                             222MiB ||    0      1731    G   compiz                                         158MiB |+-----------------------------------------------------------------------------+


3、用Anaconda安装其他组件

conda install tensorflow-gpu

conda会自动帮你装好cudatoolkit和cuDNN匹配版本

同样的方法还可以装上openblas,theano,pytorch,keras,等等。

装好之后重启一下,做个测试,看看GPU是否可用。

测试来自:blog.csdn.net/weixin_35

def is_gpu_available(cuda_only=True):  """  code from https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/platform/test.py  Returns whether TensorFlow can access a GPU.  Args:    cuda_only: limit the search to CUDA gpus.  Returns:    True iff a gpu device of the requested kind is available.  """  from tensorflow.python.client import device_lib as _device_lib  if cuda_only:    return any((x.device_type == 'GPU')               for x in _device_lib.list_local_devices())  else:    return any((x.device_type == 'GPU' or x.device_type == 'SYCL')               for x in _device_lib.list_local_devices())def get_available_gpus():    """    code from http://stackoverflow.com/questions/38559755/how-to-get-current-available-gpus-in-tensorflow    """    from tensorflow.python.client import device_lib as _device_lib    local_device_protos = _device_lib.list_local_devices()    return [x.name for x in local_device_protos if x.device_type == 'GPU']print(is_gpu_available())print(get_available_gpus())


-----------------------------------------------

基本上半小时搞定,还是美滋滋的。再装一次的话估计20分钟就能搞定了。

有时候也许真的需要去官网慢悠悠下源代码自己编译设置环境变量,比如需要某个特定版本的特性,或者为了最大限度发挥性能,等等。但更多的时候,对于许多人来说,先run起来比什么都重要。

-----------------------------------------------

欢迎讨论。


知乎:https://zhuanlan.zhihu.com/p/28251161

网易:http://talesyuan.blog.163.com/blog/static/92004608201771105713249/

阅读全文
0 0
原创粉丝点击