0%

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

1
2
3
4
5
6
7
8
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

1
2
3
4
5
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

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

Jupyter notebook with tensorflow

install tensorflow kernel

1
2
3
4
5
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

1
2
cd workspace/anjian
jupyter notebook

create a notebook with tensorflow kernel

png

Demo

disable info

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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.