NVIDIA requirements to run TensorFlow with GPU support
- CUDA® Toolkit 8.0. For details, see NVIDIA’s documentation. Ensure that you append the relevant Cuda pathnames to the
LD_LIBRARY_PATHenvironment variable as described in the NVIDIA documentation.
- The NVIDIA drivers associated with CUDA Toolkit 8.0.
- cuDNN v5.1. For details, see NVIDIA’s documentation. Ensure that you create the
CUDA_HOMEenvironment variable as described in the NVIDIA documentation.
- GPU card with CUDA Compute Capability 3.0 or higher. See NVIDIA documentation for a list of supported GPU cards.
- The libcupti-dev library, which is the NVIDIA CUDA Profile Tools Interface. This library provides advanced profiling support. To install this library, issue the following command:
sudo apt-get install libcupti-dev
sudo apt-get install python-pip python-dev # for Python 2.7
Install TensorFlow in python virtual environment (Highly Recommended)
1. Install python virtualenv
sudo pip install virtualenv
2. Create a virtualenv environment (Restart Terminal before doing this)
mkdir ~/tensorflow virtualenv --system-site-packages ~/tensorflow
3. Activate the virtualenv environment
source ~/tensorflow/bin/activate # bash, sh, ksh, or zsh
The preceding source command should change your prompt to the following:
4. Install TensorFlow GPU in the active virtualenv environment:
pip install --upgrade tensorflow-gpu # for Python 2.7 and GPU
5. Once setup is done you can activate using step 3 and When you are done using TensorFlow, you may deactivate the environment by invoking the
deactivate function as follows:
Install TensorFlow in Native (Not Recommended because of Protobuf issue):
pip install tensorflow-gpu # Python 2.7; GPU support
OR (select version from here)
sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.2.1-cp27-none-linux_x86_64.whl
Test your installation:
python #invoke python from shell import tensorflow as tf #should run without any errors
Reason for installing in Python Virtual Enviroment:
If you are using Nvidia digits then there is a possiblity considering ubuntu 16.04 comes with protobuf 2.6.1 for C++, which might result in errors looking for protobuf 3.3.0. Now you may do troubleshoot as provided below, which will install protobuf 3.3.0 and be able to launch digit with tensorflow then also for caffe based support it will get protobuf 2.6.1 which is protobuf version of c++ compiler not python one. And for some reason you decide to build protobuf 3.3.0 from source you might break your ubuntu as gtk uses protobuf 2.6.1 and so your opencv setup will also not work and some other things will break too.
So for above case senario one might not want to have tensorflow active in digits and thus this virtualenv helps.
For example if you want tensorflow to run you can run from activating virtualenv as given in steps and launch digit from that shell which will give you digits with tensorflow and when its creating problem then you can run digits without tensorflow by deactivating virtual enviroment or using native shell.
If your error is something like below:
>>> import tensorflow Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in from tensorflow.python import * File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 52, in from tensorflow.core.framework.graph_pb2 import * File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/graph_pb2.py", line 16, in from tensorflow.core.framework import node_def_pb2 as tensorflow_dot_core_dot_framework_dot_node__def__pb2 File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/node_def_pb2.py", line 16, in from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2 File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/attr_value_pb2.py", line 16, in from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2 File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/tensor_pb2.py", line 16, in from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2 File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/resource_handle_pb2.py", line 22, in serialized_pb=_b('\n/tensorflow/core/framework/resource_handle.proto\x12\ntensorflow\"m\n\x0eResourceHandle\x12\x0e\n\x06\x64\x65vice\x18\x01 \x01(\t\x12\x11\n\tcontainer\x18\x02 \x01(\t\x12\x0c\n\x04name\x18\x03 \x01(\t\x12\x11\n\thash_code\x18\x04 \x01(\x04\x12\x17\n\x0fmaybe_type_name\x18\x05 \x01(\tB4\n\x18org.tensorflow.frameworkB\x13ResourceHandleProtoP\x01\xf8\x01\x01\x62\x06proto3') TypeError: __init__() got an unexpected keyword argument 'syntax'
Then here is the solution:
This is because of protobuf version conflict:
For me i had python-protobuf v2.6.1 installed from apt-get package manager and while installing tensorflow, it installed protobuf v3.3.0 from pip manager.
To check version of protobuf from aptitude
aptitude versions python-protobuf
To check version of protobuf from pip
pip show protobuf
So uninstall both:
sudo pip uninstall protobuf sudo apt-get remove python-protobuf
and reinstall using pip manager as follows:
sudo pip install protobuf
Now run the python import test again to verify if everything works or not.