ubuntu1404--tensorflow-gpu安装

参考之前博客已经安装过cuda8,cudnn5,Anaconda;可利用Anaconda的conda安装。本机有2个版本的Python,2.7和3.4,选择的是27版本。

1. 查看本机Python版本,以及对应可安装的tensorflow版本,。

1)使用命令:python
Python 2.7.14 |Anaconda, Inc.| (default, Dec  7 2017, 17:05:42)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

2)利用conda查看,使用命令:conda search tensorflow-gpu

Loading channels: done
Name                       Version                   Build  Channel        
tensorflow-gpu             1.0.1                    py27_4  defaults       
tensorflow-gpu             1.0.1                    py35_4  defaults       
tensorflow-gpu             1.0.1                    py36_4  defaults       
tensorflow-gpu             1.1.0               np111py27_0  defaults       
tensorflow-gpu             1.1.0               np111py35_0  defaults       
tensorflow-gpu             1.1.0               np111py36_0  defaults       
tensorflow-gpu             1.1.0               np112py27_0  defaults       
tensorflow-gpu             1.1.0               np112py35_0  defaults       
tensorflow-gpu             1.1.0               np112py36_0  defaults       
tensorflow-gpu             1.2.1           py27cuda7.5cudnn5.1_0  defaults       
tensorflow-gpu             1.2.1           py27cuda7.5cudnn6.0_0  defaults       
tensorflow-gpu             1.2.1           py27cuda8.0cudnn5.1_0  defaults       
tensorflow-gpu             1.2.1           py27cuda8.0cudnn6.0_0  defaults       
tensorflow-gpu             1.2.1           py35cuda7.5cudnn5.1_0  defaults       
tensorflow-gpu             1.2.1           py35cuda7.5cudnn6.0_0  defaults       
tensorflow-gpu             1.2.1           py35cuda8.0cudnn5.1_0  defaults       
tensorflow-gpu             1.2.1           py35cuda8.0cudnn6.0_0  defaults       
tensorflow-gpu             1.2.1           py36cuda7.5cudnn5.1_0  defaults       
tensorflow-gpu             1.2.1           py36cuda7.5cudnn6.0_0  defaults       
tensorflow-gpu             1.2.1           py36cuda8.0cudnn5.1_0  defaults       
tensorflow-gpu             1.2.1           py36cuda8.0cudnn6.0_0  defaults       
tensorflow-gpu             1.3.0                         0  defaults       
tensorflow-gpu             1.4.1                         0  defaults       
tensorflow-gpu             1.5.0                         0  defaults       
tensorflow-gpu             1.6.0                         0  defaults       
tensorflow-gpu             1.7.0                         0  defaults       
tensorflow-gpu             1.8.0                h7b35bdc_0  defaults       
tensorflow-gpu             1.9.0                hf154084_0  defaults

2.根据自己电脑的python版本和cuda以及cudnn版本安装对应版本的tensorflow版本

本机使用命令:conda create -n py27 python=2.7 tensorflow-gpu=1.2.1

Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.4.10
  latest version: 4.5.9

Please update conda by running

    $ conda update -n base conda

 

## Package Plan ##

  environment location: /home/server/anaconda2/envs/py27

  added / updated specs:
    - python=2.7
    - tensorflow-gpu=1.2.1


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    openssl-1.0.2o             |       h14c3975_1         3.4 MB
    libgfortran-ng-7.2.0       |       hdf63c60_3         1.2 MB
    tensorflow-gpu-1.2.1       |py27cuda8.0cudnn6.0_0        90.9 MB
    cudnn-6.0.21               |        cuda8.0_0       178.2 MB
    blas-1.0                   |              mkl           6 KB
    numpy-1.15.0               |   py27h1b885b7_0          36 KB
    pbr-4.2.0                  |           py27_0         116 KB
    markdown-2.6.11            |           py27_0         102 KB
    funcsigs-1.0.2             |           py27_0          20 KB
    libprotobuf-3.5.2          |       h6f1eeef_0         4.2 MB
    mkl-2018.0.3               |                1       198.7 MB
    mkl_random-1.0.1           |   py27h4414c95_1         361 KB
    intel-openmp-2018.0.3      |                0         705 KB
    html5lib-0.9999999         |           py27_0         183 KB
    cudatoolkit-8.0            |                3       322.4 MB
    backports-1.0              |           py27_1           3 KB
    protobuf-3.5.2             |   py27hf484d3e_1         604 KB
    six-1.11.0                 |           py27_1          21 KB
    mkl_fft-1.0.4              |   py27h4414c95_1         147 KB
    backports.weakref-1.0rc1   |           py27_0           7 KB
    numpy-base-1.15.0          |   py27h3dfced4_0         4.1 MB
    mock-2.0.0                 |   py27h0c0c831_0         100 KB
    libgcc-7.2.0               |       h69d50b8_2         304 KB
    bleach-1.5.0               |           py27_0          21 KB
    ------------------------------------------------------------
                                           Total:       805.9 MB

The following NEW packages will be INSTALLED:

    backports:         1.0-py27_1                 
    backports.weakref: 1.0rc1-py27_0              
    blas:              1.0-mkl                    
    bleach:            1.5.0-py27_0               
    ca-certificates:   2018.03.07-0               
    certifi:           2018.4.16-py27_0           
    cudatoolkit:       8.0-3                      
    cudnn:             6.0.21-cuda8.0_0           
    funcsigs:          1.0.2-py27_0               
    html5lib:          0.9999999-py27_0           
    intel-openmp:      2018.0.3-0                 
    libedit:           3.1.20170329-h6b74fdf_2    
    libffi:            3.2.1-hd88cf55_4           
    libgcc:            7.2.0-h69d50b8_2           
    libgcc-ng:         7.2.0-hdf63c60_3           
    libgfortran-ng:    7.2.0-hdf63c60_3           
    libprotobuf:       3.5.2-h6f1eeef_0           
    libstdcxx-ng:      7.2.0-hdf63c60_3           
    markdown:          2.6.11-py27_0              
    mkl:               2018.0.3-1                 
    mkl_fft:           1.0.4-py27h4414c95_1       
    mkl_random:        1.0.1-py27h4414c95_1       
    mock:              2.0.0-py27h0c0c831_0       
    ncurses:           6.1-hf484d3e_0             
    numpy:             1.15.0-py27h1b885b7_0      
    numpy-base:        1.15.0-py27h3dfced4_0      
    openssl:           1.0.2o-h14c3975_1          
    pbr:               4.2.0-py27_0               
    pip:               10.0.1-py27_0              
    protobuf:          3.5.2-py27hf484d3e_1       
    python:            2.7.15-h1571d57_0          
    readline:          7.0-ha6073c6_4             
    setuptools:        39.2.0-py27_0              
    six:               1.11.0-py27_1              
    sqlite:            3.24.0-h84994c4_0          
    tensorflow-gpu:    1.2.1-py27cuda8.0cudnn6.0_0
    tk:                8.6.7-hc745277_3           
    werkzeug:          0.14.1-py27_0              
    wheel:             0.31.1-py27_0              
    zlib:              1.2.11-ha838bed_2          

Proceed ([y]/n)? y


Downloading and Extracting Packages
openssl 1.0.2o: ######################################################## | 100%
libgfortran-ng 7.2.0: ################################################## | 100%
tensorflow-gpu 1.2.1: ################################################## | 100%
cudnn 6.0.21: ########################################################## | 100%
blas 1.0: ############################################################## | 100%
numpy 1.15.0: ########################################################## | 100%
pbr 4.2.0: ############################################################# | 100%
markdown 2.6.11: ####################################################### | 100%
funcsigs 1.0.2: ######################################################## | 100%
libprotobuf 3.5.2: ##################################################### | 100%
mkl 2018.0.3: ########################################################## | 100%
mkl_random 1.0.1: ###################################################### | 100%
intel-openmp 2018.0.3: ################################################# | 100%
html5lib 0.9999999: #################################################### | 100%
cudatoolkit 8.0: ####################################################### | 100%
backports 1.0: ######################################################### | 100%
protobuf 3.5.2: ######################################################## | 100%
six 1.11.0: ############################################################ | 100%
mkl_fft 1.0.4: ######################################################### | 100%
backports.weakref 1.0rc1: ############################################## | 100%
numpy-base 1.15.0: ##################################################### | 100%
mock 2.0.0: ############################################################ | 100%
libgcc 7.2.0: ########################################################## | 100%
bleach 1.5.0: ########################################################## | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use:
# > source activate py27
#
# To deactivate an active environment, use:
# > source deactivate
#

3. 激活对应版本的python

source activate py27

4.使用tensorflow-GPU进行测试

python

Python 2.7.15 |Anaconda, Inc.| (default, May  1 2018, 23:32:55)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.


测试1:

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2018-08-06 08:57:44.027555: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2018-08-06 08:57:44.027601: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2018-08-06 08:57:44.027615: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2018-08-06 08:57:44.027626: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2018-08-06 08:57:44.027641: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
2018-08-06 08:57:44.424004: I tensorflow/core/common_runtime/gpu/gpu_device.cc:940] Found device 0 with properties:
name: GeForce GTX TITAN X
major: 5 minor: 2 memoryClockRate (GHz) 1.076
pciBusID 0000:02:00.0
Total memory: 11.92GiB
Free memory: 11.49GiB
2018-08-06 08:57:44.424043: I tensorflow/core/common_runtime/gpu/gpu_device.cc:961] DMA: 0
2018-08-06 08:57:44.424049: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0:   Y
2018-08-06 08:57:44.424061: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX TITAN X, pci bus id: 0000:02:00.0)
>>> sess.run(hello)
'Hello, TensorFlow!'
>>> a=tf.constant(10)
>>> b=tf.constant(32)
>>> sess.run(a+b)
42
>>> sess.close()

测试2:查看调用的是cpu还是gpu

a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
>>> b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
>>> c = tf.matmul(a, b)
>>> sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
2018-08-06 09:05:09.572178: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX TITAN X, pci bus id: 0000:02:00.0)
Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX TITAN X, pci bus id: 0000:02:00.0
2018-08-06 09:05:09.573227: I tensorflow/core/common_runtime/direct_session.cc:265] Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX TITAN X, pci bus id: 0000:02:00.0

调用的是GPU,测试通过,安装完成。

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值