In this tutorial, we will guide you through the steps of building an Anaconda-based working environment with TensorFlow and PyTorch on your local computer/machine. For E4040 course we will be using TensorFlow, but PyTorch is also a very popular framework that you might encounter in the future. Please follow these steps carefully in order to do your assignments. Note that the assignments will be based on particular versions of Tensorflow and Python, which may not be the latest versions (downloadable by default from public websites).
The installation process is time-consuming and complex, so please use an external power supply for your computer. For reference, the official installation instructions for TensorFlow are provided here: https://www.tensorflow.org/install/. Note that versions of tools used in the official instructions may not be the same as versions of tools required for E4040 assignments, so you are advised to follow our installation steps carefully.
Anaconda is the most popular Python data science platform. It provides a Python package manager that lets you install, update and remove packages.
pythonand hit Enter. You should see the following text (or similar text mentioning Anaconda): "(base) C:\Users\zoran>python Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32". This would indicate that you are using the desired Anaconda-installation of Python. Type
exit()to quit Python.
cmd. In the window, type
pythonand hit Enter. If you see the following python interpreter, which indicates that it is the Anaconda interpreter, then it is finished. Type
exit()to quit Python.
pythoninstruction doesn't work (in which case the system can not find this command), or the interpreter is not the Anaconda interpreter (in which case you have installed Python before Anaconda installation and Anaconda is not specified as your default Python), you may try one of the following:
conda listin the command window to see the list of all packages which you have installed. The most important packages for the begining are Python (3.7 version comes with Anaconda 3) and Jupyterlab (which contains Jupyter Notebook.
A useful link for information about Anaconda: https://docs.anaconda.com/anaconda/.
We are going to create a virtual environment on the Anaconda (conda) platform, and install necessary
modules/packages/tools into that virtual environment. A virtual environment is a named,
isolated, working copy of Python and other packages, which maintains its own files,
directories and paths so that you can work with specific versions of software libraries and Python versions without
affecting other projects.
Virtual environments make it easy to cleanly separate different projects and avoid problems with tool
dependencies and tool version requirements across software components.
conda command is the preferred interface for managing
installations and virtual environments with the Anaconda Python distribution
(getting started with conda).
condacommand is to first open an "Anaconda Prompt (Anaconda 3)", which looks similar to an ordinary command window. When Anaconda Prompt is opened at first, its prompt should be showing something like "(base) c:Users/userName". At this point, create a new directory where you will do experimentation with deep learning models; a good choice for the directory would be C:\Users\userName\Documents\AnacondaProjects. From the Anaconda Prompt window, navigate to C:\Users\userName\Documents\AnacondaProjects. In the Anaconda Prompt window, type
conda create -n envTF113 python=3.6(the name "envTF113" stands for environment based on TensorFlow 1.13). Anaconda 3 comes with Python 3.7 but the tensorflow version which will be used with course E4040 in 2019 is not compatible with it, so please stick with python 3.6 for now. If you wish, you can replace the name that we chose for the virtual environment "envTF113" with the name of your choice. Type
conda env listto see the list of all environments that you created within your conda, one of them should be "envTF113".
activate envTF113to activate the virtual environment (for Linux/macOS users, type
source activate envTF113). Your command prompt will change to the name of your environment, and would appear as "(envTF113) :~ $".
conda install pandas numpy scipy pillow matplotlib scikit-learnin the command window.
Many tool packages can be installed inside one environment. Two most common installation tools/methods are
and most packages can be installed with either of these tools (the choice between "conda" and "pip" may not be obvious).
In this tutorial, we explicitly state what to use (conda or pip), but if you need some particular tools, you will have to examine what is the recommended method to load them.
pip freeze. For instructions on how to manage conda environments, see manage-environments.
This step should not be done for computers without GPUs.
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.
This step should not be done for computers without GPUs.
cuDNN is a GPU-accelerated library for deep learning https://developer.nvidia.com/cudnn.
This step requires you to create an NVIDIA account.
If you are familiar with the PATH environment variable setup, you can follow the official instructions provided after you login into the NVIDIA account. Proper PATH setup would make it possible for your computer to automatically locate cuDNN *.dll files.
The alternative (manual) installation instructions are here:
TensorFlow is an open source deep learning framework created and maintained by Google Brain Team https://www.tensorflow.org .
TensorFlow is a rapidly evolving deep learning framework, and new versions are released frequently. As of August of 2019, TensorFlow 2.0 has been released, which incorporates new features, but also deprecates many interesting features which exist in prior versions. For 2019, course E4040 formal assignments will use TensorFlow version 1.13.1, so please be careful and install the correct version into your anaconda virtual environment (we suggest "envTF13"). You can additionally install the latest version of TensorFlow into some other conda virtual environment following the official guide. Later in E4040 course, we will demonstrate one of the key features of TensorFlow version 2.0 - the so called "eager execution". For running your assignments, you will also be asked to use a Google Cloud (gcp) instance, for which the instuctions are shown in another instruction manual; the same version of TensorFlow should be used both on your local mahine and in the cloud.
Note: Always activate your virtual environment (our suggestion is "envTF113").
TensorFlow 1.13 installation for windows machines:
pip install --ignore-installed --upgrade tensorflow==1.13.1
pip install --ignore-installed --upgrade tensorflow-gpu==1.13.1
TensorFlow 1.13 installation for Ubuntu machines:
pip install --ignore-installed --upgrade \ https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.13.1-cp36-cp36m-linux_x86_64.whl
pip install --ignore-installed --upgrade \ https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.13.1-cp36-cp36m-linux_x86_64.whl
TensorFlow 1.13 installation for macOS machines:
pip install --ignore-installed --upgrade \ https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.13.1-py3-none-any.whl
Verify TensorFlow installation:
python, and then type (make sure that there are several spaces in front of "print"):
For TensorFlow 2.0, type the following instead (remember to use a different virtual environment for TensorFlow 2.0):
>>>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!'
>>>import tensorflow as tf >>>a = tf.constant('Hello TensorFlow!') >>>print(a) # If you see the following output, then you're all set! b'Hello TensorFlow!'
Jupyter is a web-based Python programming environment, allowing you to edit code, display output results and plots, and show animations. You can even create a finely written report in Jupyter notebook, since it supports Latex grammar. For course assignments, we will require you to use Jupyter to do your work and demonstrate the results.
Jupyter Notebook installation (into conda/Anaconda environment):
Install JupyterLab: JupyterLab provides a web-based user interface which helps with organization of Jupyter projects, including Jupyter notebooks, text editors, terminals, etc.
Note: Make sure that you install it inside your virtual environment (suggested "envTF113"). Jupyterlab package comes distributed with Anaconda 3, but to make it available inside your virtual environment, you need to type
conda install -c conda-forge jupyterlab
Jupyter Notebook is installed by default with JupyterLab. One can then either directly start Jupyter Notebook (*.ipynb) files, or start JupyterLab to open Jupyter Notebook files indirectly ("*.ipynb" comes from the five letters of the older name of Jupyter notebook = ipython notebook).
Open Jupyter Notebook: In your virtual environment, type:
jupyter notebook or
Though JupyterLab can help in better managament of Jupyter projects, it is simpler to use jupyter notebook directly. We leave for you if you wish to explore JupyterLab features by yourself (see this website).
As the figure below shows, first
activate your virtual environment,
jupyter notebook to start Jupyter notebook - it will open inside your browser.
Now, You can view your Jupyter notebooks inside your browser (Chrome, IE, Safari etc.).
Optional: If you wish to experiment with jupyter notebooks, here are some tutorial links.
PyTorch is another open source machine learning framework for Python, based on Torch. It has been developed by Facebook's artificial-intelligence research group. Compared to TensorFlow, one of PyTorch advantages is the implicit dynamic network design.
PyTorch will not be used in E4040 course.
PyTorch installation: go to the official website http://pytorch.org/ and follow the install instructions, choosing the correct versions of Python and CUDA.
ECBM E4040 Neural Networks and Deep Learning, 2019.