Skip to content

Instantly share code, notes, and snippets.

Last active March 15, 2018 20:40
What would you like to do?

Tensorflow GPU Installation Steps

** This gist will/may serve as a guide for people who are trying to do object detection with tensorflow framework mentioned at top **

** I will try to cover all the steps from the start. If i do miss addressing something please let me know **

** All the links that i will mention here are important. Please have a look at them for complete understanding of what you are doing **

** There are some steps where you may encounter missing package errors. You can fix them by simply doing a google search wiht package name and installing them with "pip" **

My Rig

Operating system : Windows 10, Ubuntu 16.04 (Dual-boot) Graphic hardware: 16GB RAM, Nvidia GTX 1070 (8GB Video Memory) Processor: Intel i7-7700HQ Storage: HHD + SSD

My system setup is quite basic for running complex deep learning applications. Better the configuration, lesser will be training time.

Operating System Setup

The reason to dualboot your system and install ubuntu is to stay away from horrible errors that you may encounter while setting up Caffe & Yolo on windows. Although the builds exist, the need to build using source code is a huge pain when working on windows.

I would highly suggest you to follow this link to set up your system. Awesomebytes has written excellent guide to dualboot your machine with ubuntu. Guide Link

-- Credit goes to Awesomebytes

Environment Setup

Tensorflow(GPU) - Ubuntu

Necessary packages

OpenCV & Keras are needed. I installed it by following this awesome guide by Trung Tran Guide Link

After installing OpenCV, try doing this below. If it succeeds and you see this message, you have successfully installed OpenCV.

>>> import cv2
>>> cv2.__version__


Download CUDA 8.0 RC by following this link & selecting appropriate version. CUDA Link

Run the following command & follow prompts

sudo sh

As part of the CUDA environment, you should add the following in the ~/.bashrc file of your home folder.

export CUDA_HOME=/usr/local/cuda-8.0
export PATH

Open a new terminal & check if CUDA is installed

nvcc –version

Download cuDNN 5.0 by following this link & selecting appropriate version. cuDNN Link

We are copying cuDNN files to CUDA folder. Fix paths if some path error pops up.

tar xvzf cudnn-8.0.tgz
cd cudnn
sudo cp include/cudnn.h /usr/local/cuda/include
sudo cp lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

Below is a simplified version of how i did it. Make sure to update everything on your machine by running these 2 commands.

sudo apt-get update
sudo apt-get upgrade


Use this tutorial to install Anaconda in Ubuntu 16.04. Guide Link

After installing Anaconda, type this in terminal

conda create -n tensorflow python=3.5
source activate tensorflow
sudo apt install python3-pip

Install Tensorflow(GPU) using pip inside the environment

pip3 install –upgrade $TF_BINARY_URL

Install Tensorflow directly from source by following this link & instructions respective to Linux. Guide Link

Install Bazel by following the guide here(use JDK 8) Guide Link

Run this command in terminal.

sudo apt-get install python-numpy swig python-dev

Build with Bazel.

bazel build -c opt –config=cuda //tensorflow/cc:tutorials_example_trainer
bazel-bin/tensorflow/cc/tutorials_example_trainer –use_gpu

Make sure Keras uses Tensorflow backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment