In last week’s blog, I wrote about the installation process of TensorFlow on a PC. In this blog, I will continue my tutorial on TensorFlow installation.
Step 3: Installing TensorFlow
At the time of writing, there are two supported ways of installing TensorFlow:
- Native pip
While native pip installs TensorFlow directly onto your computer, Anaconda allows you to create a virtual environment and install TensorFlow into that environment. The benefit of this is to help you avoid unwanted interference with other packages. However, if you do chose to use Anaconda, you will not be able to access the TensorFlow package globally (from any directory on your computer). The following chart compares the two different installation methods:
|Interference with other Python Installations||Possible||No|
|Access to TensorFlow globally (from any directory)||Yes||No|
An additional option would be building from source code, but for the purpose of this blog, I will not go into details about it.
Installing with native pip
To install TensorFlow with native pip, simply open up Command Line Tools by pressing Win+R and then enter “cmd” in the textbook, and hit enter. Run the following command if you are installing TensorFlow without GPU support.
C:\> pip3 install --upgrade tensorflow
If you want to use CUDA to accelerate your applications, install TensorFlow with GPU support using the following command:
C:\> pip3 install --upgrade tensorflow-gpu
Then, we’re done!
Installing with Anaconda
First of all, you will need to install Anaconda to your PC through their website. Be sure to install the x86-64 version or it would not work with TensorFlow. Once you have followed the instructions from Anaconda and installed the virtual environment, create a folder and navigate to it using the windows Command Line Tools with the “cd” command. To create a virtual environment called TensorFlow, using the following command:
C:> conda create -n tensorflow pip python=3.5
Because you will be installing TensorFlow in a virtual environment, you need to activate the environment first:
C:> activate tensorflow
If you have successfully activated the virtual environment, Command Line Tools display should reflect this:
The “(tensorflow)” tells you that you are now in the virtual environment called tensorflow.
If you have decided to install TensorFlow without GPU support, execute the following command (note that you don’t need to type “(tensorflow)C:>”):
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow
Similarly, if you have decided to install TensorFlow with GPU support, please run the following command:
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow-gpu
Step 4: Testing TensorFlow Installation
It is important to test your TensorFlow installation. If you installed TensorFlow with Anaconda, be sure to navigate to the directory in which you created the virtual environment and activate it with the following command:
Type “python” and hit enter. If you see the following, you have entered the python interpreter:
Entering the following and hit enter:
import tensorflow as tf
Wait for a few seconds and if the windows updates with a new line of “>>>”, that means you have successfully imported the TensorFlow model.
Thanks for reading this tutorial! In my next blog, I will most likely write about my experience with training a CNN object detector using TensorFlow’s Object Detection API. See you next week!
Installing TensorFlow on Windows Contents. Google, 9 Mar. 2018, http://www.tensorflow.org/install/install_windows. Accessed 1 Apr. 2018.
TensorFlow. TensorFlow. Wikimedia Commons, en.wikipedia.org/wiki/TensorFlow#/media/File:TensorFlowLogo.svg. Accessed 1 Apr. 2018.