In the following article we are going to take a look at how we can install TensorFlow on Ubuntu (16.04/18.04). TensorFlow is a code library for machine learning across a range of tasks. It was developed by Google in 2015 to meet its needs in systems capable of building and training neural networks to detect and decipher patterns and correlations, analogous to the learning and reasoning used by humans.
TensorFlow is the Deep Learning platform most important in the world. This development open-source Google has positioned itself as a leading tool in the sector of the Deep Learning. It also has comprehensive libraries and community resources that allow anyone to create machine learning programs.
TensorFlow is an open source software library for numerical computing It was released under the Apache 2.0 open source license and uses data flow charts. The nodes in the graphs represent mathematical operations, while the edges of the graphs represent the multidimensional data matrices (tensioners) communicated between them.
Unlike other numerical libraries intended to be used in Deep Learning as Theano, this one in question was designed for use in both research and development. It can also run on a single CPU, multiple CPUs, as well as mobile devices and large-scale distributed systems of hundreds of machines.
If we want to install TensorFlow, it can be installed in the whole system, in a virtual Python environment, such as a Docker container and others. The most common and easiest way to install TensorFlow is perhaps through a virtual Python environment, where multiple environments can be easily created and managed. This is the option that we will see in the following lines.
Install TensorFlow on Ubuntu
The next installation process I am going to do on an Ubuntu 18.04 system. Once this is clarified, to start installing TensorFlow, you just have to follow the following steps:
Install Python
Since using Python is the fastest and easiest way to run TensorFlow, let's install it. Default, Python 3 comes with the Ubuntu repositories, so its installation should not be a problem.
For know what version of Python is installed on Ubuntu, in a terminal (Ctrl + Alt + T) you just have to execute the command:
python3 -V
As you can see, on my computer I have Python 3.6.9, and for this example I will create a virtual environment using the venv module. For install python3-venv package that enables venv module, in the same terminal we are going to execute the following commands:
sudo apt update; sudo apt install python3-venv
This should enable the Python virtual environment.
Start Python Virtual Environment
Now that we know the version of Python installed, let's continue creating a directory for TensorFlow. In the same terminal we will only have to execute the command:
mkdir ~/TensorFlow
Then we go to move to the directory we just created:
cd ~/TensorFlow
From within this directory, we will create Python virtual environment typing:
python3 -m venv venv
After creating it we only have to activate it:
source venv/bin/activate
TensorFlow requires that the Python package configuration tools be version 41.0.0 or higher. We will execute Pip as follows to make sure it is updated to the latest version:
pip install -U setuptools
Install TensorFlow
Now that the environment is created and activated, we can only begin the installation. For install current version, what includes support for GPU cards with CUDA (Ubuntu and Windows), in the terminal we will have to use pip typing:
pip install tensorflow
There are also smaller CPU-only package available:
pip install tensorflow-cpu
For update TensorFlow to the latest version, must add the –upgrade flag to the commands:
pip install --upgrade pip pip install --upgrade tensorflow
After the installation, to verify that TensorFlow is installed we can execute the following command:
python -c 'import tensorflow as tf; print(tf.__version__)'
This command should display the version of TensorFlow installed. For see tutorials of different kinds about TensorFlow, we can go to the project website.
Disable Python Environment
When we're done with the Python environment, you just have to execute the deactivate command:
deactivate
Then we only have to delete the created TensorFlow directory, and this should delete the Python environment that we created to run TensorFlow. For more information on how to use TensorFlow, you can visit the tutorial that they published on their website or on the developer website of Google.