Setting up a Keras+TensorFlow environment with Conda and Docker

1 minute read

Setting up a Deep Learning environment is not a trivial task. Given the strong dependencies among libraries, just installing Keras or TensorFlow in the machine is not a recommended practice. There are, however, several alternatives to get a clean Deep Learning environment.

Two popular solutions are to use Conda environments or Docker instances.

Installing TensorFlow with Conda

A full introduction to Conda and Conda environments can be found in Anaconda’s [web site][https://conda.io/docs/user-guide/tasks/manage-environments.html]. For the purpose of this brief tutorial, we just need to [install Anaconda][https://www.anaconda.com/distribution/] and create a new environment to host TensorFlow and related software. The creation of new environment with conda is straitforward, just type

conda create --name tensorflow

That command will create a conda environment named tensorflow, to get into the newly created environment just type

source activate tensorflow

which outputs a new prompt indicating the active environment. Any package installed into this environment will remain local to that environment, avoiding conflicts with packages installed in the base system or other environments. To exit the environment type source deactivate'', and to list all the available environments useconda info –envs’’.

Once the environment has been created and activated, it is time to install TensorFlow and related packages. It can be done with either pip or conda. My personal choice is conda because it handles dependencies, which makes our lives much easier. First, we should install the basic Machine Learning Python packages:

conda install numpy pandas matplotlib

If the computer does not have a GPU, install the plain ``tensorflow’’ package:

conda install tensorflow keras 

Otherwise, if your computer has a GPU, it is highly recommended to install the package ``tensorflow-gpu’’

conda install tensorflow-gpu keras

The host ipython interpreter uses to make trouble when working in a conda environent, so a good practice is to install it in the environment:

conda install ipython

Another important package that is going to be needed when working with CNNs is Pillow.

conda install pillow

Finally, if you want to use Jupyter within the environment, you shoud know that it does not recognize conda environments by default, so it would be unable to find TensowFlow. This problem can be solved installing a Jupiter plug-in.

conda install nb_conda

Installing TensorFlow with Docker

Testing the installation

Updated: