install and use tensorflow on ubuntu 16.04


Guide

version

  • ubuntu 16.04 64 bit
  • cuda driver 384.130
  • tensorflow-gpu 1.4.0 (CUDA 8.0 + cudnn 6.0)
  • tensorflow-gpu 1.5.0+ (CUDA 9.0 + cudnn )
  • python 3.5

install

version:

  • cpu: tensorflow
  • gpu: tensorflow-gpu

commands

workon py3
pip install tensorflow-gpu==1.4 
pip install keras

pip install Pillow scipy sklearn scikit-image ipython

pip list
pip3 list # same results as pip

tips, for virtualenv workon see python virtualenv tutorial

test

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print hello
print(sess.run(hello))

output

Tensor("Const:0", shape=(), dtype=string)
Hello, TensorFlow!

fix errors

error

ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory
ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory

tensorflow-gpu 1.5 use cuda 9.0, so we install tensorflow-gpu 1.4to use cuda 8.0

pip uninstall tensorflow-gpu
pip install tensorflow-gpu==1.4

Jupyter notebook with tensorflow

install tensorflow kernel

workon py3
pip install ipykernel

python -m ipykernel install --user --name=tensorflow
Installed kernelspec tensorflow in /home/kezunlin/.local/share/jupyter/kernels/tensorflow

use tensorflow kernel

cd workspace/anjian
jupyter notebook 

create a notebook with tensorflow kernel

png

Demo

disable info

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
#默认为0:输出所有log信息
#设置为1:进一步屏蔽INFO信息
#设置为2:进一步屏蔽WARNING信息
#设置为3:进一步屏蔽ERROR信息
```bash

### tensorflow errors

error

    Exception ignored in: <bound method BaseSession.__del__ of <tensorflow.python.client.session.Session object at 0x7fd3edd13e10>>

    Traceback (most recent call last):
    File "venv/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 712, in __del__
    TypeError: 'NoneType' object is not callable

fix 
```python
from keras import backend as K
#...
#...
K.clear_session()

Reference

History

  • 20180821: created.

Author: kezunlin
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source kezunlin !
评论
  TOC