Recently TensorFlow has graced us horrible Windows users with a native Windows install! For those of you who, like me, used to run TensorFlow on Windows in the past I'm sure you're aware of the ballache of having to run it in a Linux virtual machine. The real pain for me (other than having to start a VM every time) was the fact that I have a pretty decent graphics card yet running TensorFlow via a VM I could not for the life of me get it to pass-through hence I've had to rely on VM limited CPU usage for running my models. Not. Ideal.
However, now the chaps over at Google have listened and with the official release of TensorFlow 1.0 they've provided a solution that doesn't involve buying a certain laptop with a useless emoji bar and no USB ports...
TensorFlow (both the CPU and GPU enabled version) are now available on Windows under Python 3.5.2. This, however, posed a bit of an issue for me personally as I enjoy being a bit old school and live in the Python 2.7 world (as the majority of Python users do). So I need a way of running/programming in 2.7 whilst also being able to run native TensorFlow (both directly and via Keras) on 3.5.2.
So, after a day of fiddling I've come up with a few steps that I'm sharing which will hopefully get you up and running in no time!
Install Anaconda
- Firstly, I want to be able to run Python 2.7 natively whilst also having Python 3.5.2 available for TensorFlow. It turns out the guys from Continuum (the creators of the Anaconda package) have you covered! Using Anaconda's conda command you can set up virtual environments for separate Python versions, perfect! Go ahead and download Anaconda from their website (Note: it does NOT matter what version of Python you download Anaconda for here! I personally have downloaded the Python 2.7 version as that's the version I'll be using day-to-day when I'm not doing AI/ML work).
- Got your Anaconda version all installed? Good, now go ahead and open up command prompt and run this command (make sure you're running command prompt as administrator, otherwise you might get a permission denied error):
conda create -n python3 python=3.5.2 anaconda
- Now that's all set up, go ahead and type
activate python3
Make sure you're in your python3 environment for the following section, as this is the environment you'll be setting up!
TensorFlow CPU Version
-
This one is easy, however not recommended as CPUs are much slower than GPUs in an ML computation. However, if you enjoy waiting or have another reason not to install the GPU version just type
pip install --upgrade tensorflow
and TensorFlow should be installed
TensorFlow GPU Version
- Shit gets a bit more complicated when you want the GPU version. First, check that you have a GPU card with CUDA Compute Capability 3.0 or higher. If you don't, then bad news for you chap.
- Install the CUDA® Toolkit 8.0
- Install cuDNN v5.1
- Now we've got all the fancy stuff to port our TensorFlow code to our CUDA GPUs. So go ahead and open command prompt and type "activate python3" to get into our virtual environment
-
Now type
pip install --upgrade tensorflow-gpu
and boom, GPU enabled TensorFlow is now rocking on your machine!
Just in case you needed any more encouragement to install the GPU version over the CPU one, I have run tests my two machines comparing the training times (in seconds) between CPU and GPU.
For the CPU tests I did what I used to do on a Windows machine and ran a Ubuntu VM using VMware Workstation 12. For the GPU version I ran natively on Windows using the Tensorflow GPU install.
Both tests used a deep LSTM network to train on timeseries data using the Keras package. Each test was done for 1, 10 and 20 training epochs.
I ran the test on two machines, my Desktop; a custom build Intel i5 16GB RAM Nvidia GeForce GTX 960. And my Laptop; Xiaomi Mi Notebook Air 13 Intel i5 8GB RAM Nvidia GeForce 940MX. Results are graphed below:
Additional step
if you want the awesome Keras framework for TensorFlow, simply type
pip install keras
I'd highly recommend it to save time with writing AI/ML models. Once installed, you might have to switch it from a Theano backend to the TensorFlow backend. You can do this by going to C:\Users\[User]\.keras and editing the keras.json file changing the backend line to
"backend": "tensorflow"
And now you're ready to roll and take over the world! Just make sure to activate your python3 environment and run your models from within that!
Happy tensoring!