In this tutorial, we’ll guide you through the essential steps of building a TensorFlow and a PyTorch working enrivonment on your local machine. For the course we'll be using TensorFlow, but PyTorch is also a very popular framework that you might encounter in the future.
Note: The process is time-consuming/complex for starters, so please prepare an external power supply if necessary. For reference, an official instruction is here: https://www.tensorflow.org/install/.
Anaconda is a data science platform using Python. It also provides a Python package manager that lets you install, update and remove packages.
cmd. In the window, type
pythonand hit Enter. If you see the following python interpreter, which indicates it is an Anaconda interpreter, then it is finished. Type
exit()to quit Python.
pythondoesn't work (in which case the system doesn't find this command), or the interpreter is not the Anaconda iterpreter (in which case you've installed Python before and Anaconda is not specified as your default Python), you may choose one of the following three:
You can use
conda list in the command window to see all the packages you’ve installed.
We are going to create a virtual environment on this Anaconda platform, and install necessary modules. A virtual environment is a named, isolated, working copy of Python that maintains its own files, directories and paths so that you can work with specific versions of libraries or Python itself without affecting other Python projects. Virtual environments make it easy to cleanly separate different projects and avoid problems with different dependencies and version requirements across components. The conda command is the preferred interface for managing installations and virtual environments with the Anaconda Python distribution. (managing conda environments.)
conda create -n dlWorks python=3.5. If you wish, you can replace the name that we chose for the virtual environment “dlWorks” with the name of your choice. The reason we use python 3.5 version is because TensorFlow runs on python version 3.5.
activate dlWorksto activate the virtual enrivonment. (For Linux users, type
source activate dlWorks) Your command prompt will contain the name of your environment, as in the cmd window below. (The name for this environment is ‘gpu’ rather than 'dlWorks' in this case)
conda install pandas numpy scipy pillow matplotlib scikit-learnin the command window.
Compute Unified Device Architecture (CUDA) is a parallel computing platform and programming model created by NVIDIA. It harnesses the full power of graphics processing units (GPUs) for deep learning purposes.
cuDNN is a GPU-accelerated library for deep learning.
Note 1: This step requires you to create an NVIDIA account.
Note 2: For this step, if you're familiar with PATH environment variable setup, you can follow the official instructions provided after you login with your account. The following is a more understandable way.
Note: If this step goes wrong, you can still install the rest, but when you initiate TensorFlow you will probably see a message: Couldn't open CUDA library cudnn.so.x. The computation speed might be compromised.
TensorFlow is an open source deep learning framework created and maintained by Google Brain Team. It is the most popular deep learning framework nowadays.
For windows users:
pip install --ignore-installed --upgrade tensorflow
pip install --ignore-installed --upgrade tensorflow-gpu
For Ubuntu users:
pip install --ignore-installed --upgrade \ https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.3.0-cp35-cp35m-linux_x86_64.whl
pip install --ignore-installed --upgrade \ https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp35-cp35m-linux_x86_64.whl
Note: Always try to activate your virtual environment.
python, and then type:
>>>import tensorflow as tf >>>a = tf.constant('Hello TensorFlow!') >>>with tf.Session() as sess: ... print(sess.run(a)) # If you see the following output, then you're all set! b'Hello TensorFlow!'
PyTorch is another deep learning framework for Python. Its predecessor is Torch which relys on Lua. Compared to TensorFlow, Pytorch has its own advantages such as dynamic network design.
To install PyTorch, go to the official website http://pytorch.org/ and follow the install instructions. That’s it!
ECBM E4040 Neural Networks and Deep Learning, 2017.