December 09, 2019

Installing your own TensorFlow/Kears + FastAI on Ubuntu

Follow-up to Things to do before the 1st lectures from Rudo's blog

How to make your own Keras/FastAI ML-capable machine using Ubuntu

Install the Anaconda-version of Python

Navigate to https://docs.anaconda.com/anaconda/install/ to find the links to download your own Anaconda. For Ubuntu (19.10), choose Installing on Linux as shown in the figure below.

Anaconda download web page












Next, click on Anaconda installer for Linux to start the download for the Python 3.7 version. Having downloaded, presumably to the directory ~/Downloads, navigate there with a termial. Then you should perhaps make the file executable, i.e., in the terminal, type

ternimal image

chmod u+x Anaconda3-2019.10-Linux-x86_64.sh

Then in the same terminal, you can execute the installer

./Anaconda3-2019.10-Linux-x86_64.sh

This will install Anaconda into a directory of your choice in your $HOME space. Feel free to change the installation directory. At the end, the installer will ask if you want to allow it to activate anaconda automatically. Say yes to this.

Next, edit your .bashrc file in your home directory and add "conda deactivate" after the lines which the installer added as shown here

.bashrc change

Save the change and restart your terminal. You should now have a working Python installation based on Anaconda.

Note that such an installation may overwrite a previous python installation, so please be careful to make sure this is really what you want.t

Activate your new anaconda installation as

conda activate

and you should see

screenshot






Make conda environments to avoid version clashes

You will rarely need Keras and FastAI to work simultaneously. And the python packages they need may have clashing versions. In order to avoid this, we found it useful to define "environments" as follows

Tensorflow/Kears:

conda create -n TF anaconda

FastAI:

conda create -n FastAI anaconda

When you type this in a terminal, you are being asked to install some Python packages. Simply say yes/accept.

Installing Tensorflow+Keras

Open a terminal, then start the "TF" environment by typing

conda activate TF

You will see that the command prompt is now prepended with the name of the environment, i.e. (TF).

terminal

Next, let's install Tensorflow.

In the same terminal with the TF environment, type

conda install -c conda-forge tensorflow

(see https://anaconda.org/conda-forge/tensorflow for other possibilities). This installs Tensorflow. If you are having a GPU in your system, then replacing tensorflow with tensorflow-gpu will install the required GPU compatible codes.

Installing Keras

Similarly, install Keras via

conda install -c conda-forge keras

(see https://anaconda.org/conda-forge/keras for other possibilities). Keras is now installed.

There are other ways to install the combination, but they can lead to other requirements to run the code. If you follow the way we did it here, the dependencies are set in the way that we are using for the jupyter notebooks to run.

Installing FastAI

This installation is actually simpler. As before, remember to activate the correct environment, i.e.

conda activate FastAI

If you stick to the names "TF" and "FastAI" for the course, then you are compatible with what we are doing. Hopefully, this makes it easier to avoid any mistakes. OK, now let's install FastAI!

conda install -c fastai fastai

(see https://anaconda.org/fastai/fastai).

Testing the installation for Keras

Let's see if everything worked as advertised. Start a jupyter notebook in the TF environment,

conda activate TF
jupyter notebook &

Then in the Jupyter notebook, navigate to our course material and load, e.g., Keras-MNIST.ipynb. As usual with Jupyter notebooks, evaluate the first cell (via SHIFT-ENTER if using the keyboard). If everything works well, you will get

Jupyter

and "Using Tensoflow backend" is telling you that Keras has correctly identified how to use Tensorflow.

Testing for a correct FastAI installation

As before, start the jupyter notebook in the correct (FastAI) environment, i.e.

conda activate FastAI
jupyter notebook &

Now use the notebook to open a FastAI code, i.e. FastAI-lesson1-pets.ipynb. if the following lines execute correctly, your FastAI installation works well!

FastAI

And that's really it! Except it's not. Both Keras and FastAI make use of some further Python packages that you might need to install as well. Here is a, perhaps incomplete, list: mathplotlib, sklearn, ...


- No comments Not publicly viewable


Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.

December 2019

Mo Tu We Th Fr Sa Su
Nov |  Today  | Jan
                  1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31               

Search this blog

Tags

Galleries

Most recent comments

  • Please note that this link to download is now obsolete. Attendees for the 2021 MPAGS/CYU course shou… by Rudo Roemer on this entry
  • To load Tensorflow and PyTorch (and Keras) modules on ORAC may you may have to module load a few mor… by Daniel Paget on this entry
  • That's cool. Perhaps you want to show people during class next week how to run on Kaggle? by Rudo Roemer on this entry
  • Regarding possible alternatives to benefit form a GPU, I have personally used Kaggle, by Google, its… by Juan on this entry
  • Hello to you all, I was just trying to make the programs run in my VirtualBox with Ubuntu 18.04 inst… by Malaquias Correa on this entry

Blog archive

Loading…
Not signed in
Sign in

Powered by BlogBuilder
© MMXXI