Getting Started With NVIDIA GPU, Anaconda, TensorFlow and Keras on Arch Linux

Miguel Morales
Jan 24, 2017 · 4 min read


This is actually a pretty simple setup. First, we will install NVIDIA drivers and CUDA, then we will install Anaconda, TensorFlow binaries for GPUs, and Keras.

Install NVIDIA drivers

Let’s first install the drivers and cuda:

yaourt -S nvidia nvidia-utils cuda

Now, you need to go to NVIDIA’s website and download the cuDNN tarball. Just place the file on your “Downloads” folder.

Next, we install the package with:

yaourt -S cudnn

This should install all NVIDIA dependencies. Let’s go now and install Anaconda.

yaourt -S anaconda
# add a pointer to anaconda's binaries to your path and load it on your open session
echo "export PATH="/opt/anaconda/bin:$PATH"" ~/.bash_profile
source ~/.bash_profile

At this point you can check your installation with anaconda --version && conda --version.

Let’s create an environment and install TensorFlow and Keras:

conda create -n deep-learning
source activate deep-learning
# at the time of writing this is the lastest binary for GPUs
# go to
# and grab the equivalent "linux, gpu, python 3.5"
pip3 install --upgrade $TF_BINARY_URL
pip3 install ipython

Now, you should be able to enter on an interactive Python session and load TensorFlow. Your output should look as below:

(deep-learning) [mimoralea@hash ~]$ ipython
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul 2 2016, 17:53:06)
Type "copyright", "credits" or "license" for more information.

Great, now install Keras, configure it and test it.

pip3 install keras
mkdir ~/.keras
vi ~/.keras/keras.json

Add the keras config with these values:

"image_dim_ordering": "tf",
"epsilon": 1e-07,
"backend": "tensorflow",
"floatx": "float32"

Finally, test the end to end installation:

(deep-learning) [mimoralea@hash ~]$ ipython
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul 2 2016, 17:53:06)
Type "copyright", "credits" or "license" for more information.

Did you see “Using TensorFlow backend.”? That was Keras right there. Well done!

Let’s do a quick test:

First get out of your environement, update some packages and enable your environment again:

source deactivate
conda update conda
conda update anaconda
conda install nomkl numpy scipy scikit-learn numexpr
conda update mkl
source activate deep-learning

Now, let’s get that script running, you’ll like this, I promise.

# get into /tmp to garbage our work afterwards
cd /tmp
mkdir results
# download the style transfer script
# you need these packages to run this particular sample

Now, download a couple of images that you like on the same folder. Call it myimage.jpg for example. I added this one:

Image for post
Image for post

Also, download a couple of the most famous paintings of all time. Call it mystyle.jpg (or whatever you want, really). I actually got a pic of a painting my wife authored. Bonus point, you know… ;)

Image for post
Image for post

Now, the magic command:

python myimage.jpg mystyle.jpg results/myresult
ls -l results/

There you should see all the intermediate images that resulted from it. 100th image looks ok, though I would probably leave it for a little longer to get a better result.

Image for post
Image for post

You can also create a gif:

convert -delay 10 -loop 0 `ls -v *.png` animated.gif
Image for post
Image for post

For a point of comparison, you can see here the result return:

Image for post
Image for post

I like theirs better, but ours is not that bad!! You just have to play with the settings for a little longer.

Here is a sample of how the same picture looks with another style:

Image for post
Image for post

Not bad, right? You can see the chunks of the oil painting transferred into this photo. This is pretty amazing.

Alright, enjoy!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store