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 the most popular Python data science platform. It provides a Python package manager that lets you install, update and remove packages.
cmd
. In the window, type python
and 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.
python
doesn't work (in which case the system doesn't find this command), or the
interpreter is not the Anaconda interpreter (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:
python
again to test.
conda list
in the command window to see all the packages you’ve installed.
Useful link for further information about Anaconda: https://docs.anaconda.com/anaconda/.
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.
(getting strated with conda.)
conda create -n dlenv python=3.6
. Python has now release 3.7 but tensorflow is not compatible with it, please stick with python 3.6 for now.
If you wish, you can replace
the name that we chose for the virtual environment
'dlenv' with the name of your choice.
activate dlenv
to activate the virtual enrivonment. (For Linux/macOS
users, type source activate dlenv
) Your command prompt will contain the name of your
environment, as in the cmd window below.
conda install pandas numpy scipy pillow matplotlib scikit-learn
in the command window.
Also, remember to conda install jupyter notebook
.
Note: Many tool packages can be installed either using conda
or pip
and the choice may not be obvious. In this tutorial, we explicitly state what to use, but if you need some other tools, you will have to examine how to load.
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 3: 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.
Note:There are newer versions of Tensorflow released, you can install them following official guide, but we suggest you use the same version as your gcp instance.
For windows users:
pip install --ignore-installed --upgrade tensorflow==1.8.0
pip install --ignore-installed --upgrade tensorflow-gpu==1.8.0
For Ubuntu users:
pip install --ignore-installed --upgrade \
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp36-cp36m-linux_x86_64.whl
pip install --ignore-installed --upgrade \
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.8.0-cp36-cp36m-linux_x86_64.whl
For macOS users:
pip install --ignore-installed --upgrade \
https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.8.0-py3-none-any.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!'
activate
your virtual environment, then jupyter notebook
to start Jupyter,
new a Python 3 notebook and type the above commands again to test.
PyTorch is another open source machine learning framework for Python, based on Torch. It is developed by Facebook's artificial-intelligence research group. 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.
ECBM E4040 Neural Networks and Deep Learning, 2017.
Columbia University