Introducing TensorFlow on Ubuntu + Python 2.7

0. What is TensorFlow?

Machine learning library provided by Google @ shuhei_f's What is TensorFlow is easy to understand.

1. Ubuntu preparation

Prepare Ubuntu with Build Ubuntu environment with Vagrant + VirtualBox.

2. Check the environment

Ubuntu 15.04 / Python 2.7.9

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=15.04
DISTRIB_CODENAME=vivid
DISTRIB_DESCRIPTION="Ubuntu 15.04"

$ python --version
Python 2.7.9

3. Proxy settings (if necessary)

$ export http_proxy="$USERNAME:$PASSWORD@$HOST:$PORT"
$ export https_proxy="$USERNAME:$PASSWORD@$HOST:$PORT"

4. Install pip (if not included)

$ curl -kL https://raw.github.com/pypa/pip/master/contrib/get-pip.py | sudo python

5. Install virtualenv (if not included)

$ sudo pip install virtualenv

6. Creating an environment for TensorFlow

$ mkdir ~/tensorflow
$ virtualenv --system-site-packages ~/tensorflow
$ cd ~/tensorflow
$ source bin/activate

7. Install TensorFlow

(tensorflow)$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl

If you get the following error, it means that "python-dev" is not included. Install with sudo apt-get install python-dev.

(Omitted)
    SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.
    
    ----------------------------------------
Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-ZZhjh_/numpy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-UmWBtU-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-ZZhjh_/numpy

8. Checking the operation of TensorFlow

hello-tf.py


import tensorflow as tf
import multiprocessing as mp
 
core_num = mp.cpu_count()
config = tf.ConfigProto(
    inter_op_parallelism_threads=core_num,
    intra_op_parallelism_threads=core_num )
sess = tf.Session(config=config)
 
hello = tf.constant('hello, tensorflow!')
print sess.run(hello)
 
a = tf.constant(10)
b = tf.constant(32)
print sess.run(a+b)

(tensorflow)$ python hello-tf.py
I tensorflow/core/common_runtime/local_device.cc:25] Local device intra op parallelism threads: 2
I tensorflow/core/common_runtime/local_session.cc:45] Local session inter op parallelism threads: 2
hello, tensorflow!
42
  1. TensorBoard

Port forwarding settings

Vagrantfile


config.vm.network :forwarded_port, host: 6006, guest: 6006
$ vagrant reload

Launch TensorBoard

$ tensorboard --logdir=[log_dir]
Starting TensorBoard on port 6006
(You can navigate to http://localhost:6006)

reference

Pip installation became easier before I knew it I tried running Hello World with TensorFlow & its explanation

Recommended Posts

Introducing TensorFlow on Ubuntu + Python 2.7
Install TensorFlow on Ubuntu
build Python on Ubuntu
Install Python 3.3 on Ubuntu 12.04
Set up Python 3.4 on Ubuntu
Use matplotlib on Ubuntu 12 & Python
Put Python 3.x on Ubuntu
Run Tensorflow 2.x on Python 3.7
Install OpenCV on Ubuntu + python
Install CUDA10.1 + cuDNN7.6.5 + tensorflow-2.3.0 on Ubuntu 18.04
Install Python 3.8 on Ubuntu 18.04 (OS standard)
Python 3.4 pyvenv fails on Ubuntu 14.04 LTS
Building a Python environment on Ubuntu
Preparing python using vscode on ubuntu
Run TensorFlow Docker Image on Python3
Install Python 3.9 on Ubuntu 20.04 (OS standard?)
Install confluent-kafka for Python on Ubuntu
Install Python 2.7 on Ubuntu 20.04 (OS standard?)
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
OpenCV3 & Python3 environment construction on Ubuntu
Python on Windows
twitter on python3
Build Python3 and OpenCV environment on Ubuntu 18.04
Python virtual environment and packages on Ubuntu
Introducing MAMP + Python + SQLAlchemy (Mysql-Python) on Mac
Shebang on Ubuntu 20.04
Steps to install Python environment on Ubuntu
I installed TensorFlow (GPU version) on Ubuntu
Created Ubuntu, Python, OpenCV environment on Docker
python on mac
Python on Windbg
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
[Python] Japanese localization of matplotlib on Ubuntu
Build python environment with pyenv on EC2 (ubuntu)
Build Python3.5 + matplotlib environment on Ubuntu 12 using Anaconda
Install python package in personal environment on Ubuntu
[Procedure memo] Install Python3 + OpenSSL locally on Ubuntu
Python development on Ubuntu on AWS EC2 (using JupyterLab)
How to run MeCab on Ubuntu 18.04 LTS Python
[Venv] Create a python virtual environment on Ubuntu
Notes for using TensorFlow on Bash on Ubuntu on Windows
At the time of python update on ubuntu
Installing TensorFlow on Windows Easy for Python beginners
Install MongoDB on Ubuntu 16.04 and operate via python
TensorFlow: Run data learned in Python on Android
Install Tensorflow on Mac
Python conda on cygwin
Install python on WSL
PyOpenGL setup on Python 3
Install Python on Pidora.
Install Scrapy on python3
Install Python on Mac
Install PySide2 on Ubuntu
Install JModelica on Ubuntu
Installing pandas on python2.6
python basic on windows ②
Install python on windows
Introducing Python 2.7 to CentOS 6.6
Install Python 2.7.3 on CentOS 5.4
Build TensorFlow on Windows
TensorFlow API memo (Python)