Passer au contenu principal

Course software for introductory deep learning

In the practicals, we will use only a small dataset and we will need only little computation power and memory ressources. You can therefore do the practicals on various computing platforms:platforms. However, since the participants may use various types of computers and softwares, we recommend to use the UNIL JupyterLab to do the practicals. 

  • LaptopJupyterLab: Working on the cloud is convenient because the installation of the Python and R packages is already done and you will be working with a Jupyter Notebook style even if you use R.

  • Laptop: This is good if you want to work directly on your laptop, but you will need to install the required libraries on your laptop.

  • JupyterLab:Warning: WorkingWe will give general instructions on how to install the cloudlibraries on your laptop but it is convenientsometimes becausetricky to find the installationright involveslibrary only copyversions and pastewe ofwill anot listbe ofable commands.to Thenhelp you will be working with athe Jupyterinstallation. Notebook                                                                                                                                                                                                     style even if you use R.

  • Curnagl: This is efficient if you are used to work on a cluster or if you intend to use one in the future to work on large projects. If you do not have an account to access the UNIL cluster Curnagl, please contact us at least a week before the course so that we can give you a temporary account. Note that it is also possible to use JupyterLab on Curnagl: see https://wiki.unil.ch/ci/books/high-performance-computing-hpc/page/jupyterlab-on-the-curnagl-cluster

The installation should take about 15 minutes. If you have difficulties during the installation, we can help you so please contact us before the course or come at the installation day.

Laptop

You may need to install development tools including a C and Fortran compiler (e.g. Xcode on Mac, gcc and gfortran on Linux, Visual Studio on Windows).

Python installation

Here are some instructions for installing Keras with TensorFlow at the backend (for Python3), and other libraries, on your laptop. You need Python >= 3.8.

For Linux

All the required libraries are listed here (see the comment below if you want to install the latest required libraries):

https://c4science.ch/source/DL_INTRO/browse/master/requirements.txt

You may copy/paste this list of libraries in a text editor and name the file "requirements.txt" or use Git:

git clone https://c4science.ch/source/DL_INTRO.git

If you dont have git, you can download it from: https://git-scm.com/downloads

We will use a terminal to install the libraries.

Let us create a virtual environment. Open  your terminal and type:

python3 -m venv mlcourse

source mlcourse/bin/activate

pip3 install -r DL_INTRO/requirements.txt

To check that Tensorflow was installed:

python3 -c "import tensorflow; print(tensorflow.version.VERSION)"

There might be a warning message (see above) and the output should be something like "2.9.2".

You can terminate the current session:

deactivate

exit

TO DO THE PRACTICALS (today or another day):

You can use any Python IDE (e.g. Jupyter Notebook or PyCharm), but you need to launch it after activating the virtual environment. For example, for Jupyter Notebook:

source mlcourse/bin/activate

jupyter notebook

COMMENT: To install the latest versions of the required libraries, you can type the following commands instead of "pip3 install -r DL_INTRO/requirements.txt":

python3 -m venv mlcourse

source mlcourse/bin/activate

pip3 install tensorflow scikit-learn==1.2.2 scikeras eli5 pandas matplotlib notebook keras-tuner

deactivate

exit

For Mac

If you use Anaconda or miniconda, then you should either use the instructions below with the native macos python3, or use the conda environment installation as specified here: https://developer.apple.com/metal/tensorflow-plugin/

To install the latest versions of the required libraries:

python3 -m venv mlcourse

source mlcourse/bin/activate

pip3 install tensorflow-macos scikit-learn==1.2.2 scikeras eli5 pandas matplotlib notebook keras-tuner

If you receive an error message such as:

ERROR: Could not find a version that satisfies the requirement tensorflow-macos (from versions: none)
ERROR: No matching distribution found for tensorflow-macos

Then, try the following command:

SYSTEM_VERSION_COMPAT=0 pip3 install tensorflow-macos scikit-learn==1.2.2 scikeras eli5 pandas matplotlib notebook keras-tuner

If you have a Mac with M1 or more recent chip (if you are not sure have a look at "About this Mac"), you can also install the tensorflow-metal library to accelerate training on Mac GPUs (but this is not necessary for the course):

pip3 install tensorflow-metal

To check that Tensorflow was installed:

python3 -c "import tensorflow; print(tensorflow.version.VERSION)"

There might be a warning message (see above) and the output should be something like "2.9.2".

You can terminate the current session:

deactivate

exit

TO DO THE PRACTICALS (today or another day):

You can use any Python IDE (e.g. Jupyter Notebook or PyCharm), but you need to launch it after activating the virtual environment. For example, for Jupyter Notebook:

source mlcourse/bin/activate

jupyter notebook

For Windows

If you do not have Python installed, you can use either Conda: https://docs.conda.io/en/latest/miniconda.html (see the instructions here: https://conda.io/projects/conda/en/latest/user-guide/install/windows.html) or Python official installer: https://www.python.org/downloads/windows/ 

All the required libraries are listed here (see the comment below if you want to install the latest required libraries):

https://c4science.ch/source/DL_INTRO/browse/master/requirements.txt

You may copy/paste this list of libraries in a text editor and name the file "requirements.txt" or use Git:

git clone https://c4science.ch/source/DL_INTRO.git

If you dont have git, you can download it from: https://git-scm.com/downloads

We will use a terminal to install the libraries.

Let us create a virtual environment. Open  your terminal and type:

python -m venv mlcourse

mlcourse\Scripts\activate.bat

pip3 install -r DL_INTRO/requirements.txt

To check that Tensorflow was installed:

python -c "import tensorflow; print(tensorflow.version.VERSION)"

There might be a warning message (see above) and the output should be something like "2.9.2".

You can terminate the current session:

deactivate

TO DO THE PRACTICALS (today or another day):

You can use any Python IDE (e.g. Jupyter Notebook or PyCharm), but you need to launch it after activating the virtual environment. For example, for Jupyter Notebook:

mlcourse\Scripts\activate.bat

jupyter notebook

COMMENT: To install the latest versions of the required libraries, you can type the following commands instead of "pip3 install -r DL_INTRO/requirements.txt":

python -m venv mlcourse

mlcourse\Scripts\activate.bat

pip3 install tensorflow scikit-learn==1.2.2 scikeras eli5 pandas matplotlib notebook keras-tuner

deactivate

R installation

Here are some instructions for installing Keras with TensorFlow at the backend, and other libraries, on your laptop. The R keras is actually an interface to the Python Keras. In simple terms, this means that the keras R package allows you to enjoy the benefit of R programming while having access to the capabilities of the Python Keras package.

You need R >= 4.0 and Python >= 3.8. 

REMARK: The R libraries will be installed in your home directory. To allow it, you must answer yes to the questions:

Would you like to use a personal library instead? (yes/No/cancel) yes

Would you like to create a personal library to install packages into? (yes/No/cancel) yes

And select Switzerland for the CRAN mirror.

For Mac and Linux

Run the following commands on your terminal:

cd ~

ls .virtualenvs

# Create this directory only if you receive an error message saying that this directory does not exist
mkdir .virtualenvs

Then

cd ~/.virtualenvs

python3 -m venv mlcourse

source mlcourse/bin/activate

pip3 install tensorflow-macos==2.9.2 scikit-learn==1.2.2 scikeras eli5 pandas matplotlib notebook keras-tuner

Run R in your terminal and type

install.packages("reticulate")

install.packages("ggplot2")

install.packages("ggfortify")

library(keras)

library(tensorflow)

To check that Keras was properly installed:

is_keras_available(version = NULL)

There might be a warning message (see above) and the output should be something like "TRUE".

You can terminate the current R session:

q()

Save workspace image? [y/n/c]: n

TO DO THE PRACTICALS (today or another day):

On your terminal:

cd ~/.virtualenvs

source mlcourse/bin/activate

cd ~/THE_FOLDER_WHERE_YOU_WANT_TO_DO_THE_PRACTICALS

 

Then you can either run R in your terminal or launch RStudio from your terminal:

R

# or

open -na Rstudio

For windows

If you do not have Python installed, you can use either Conda: https://docs.conda.io/en/latest/miniconda.html (see the instructions here: https://conda.io/projects/conda/en/latest/user-guide/install/windows.html).

Run the following commands:

install.packages("keras")

library(keras)

library(tensorflow)

install_tensorflow(method="conda", envname="r-reticulate", version="2.9.2")

install.packages("ggplot2")
install.packages("ggfortify")

You should name the environment 'r-reticulate' as otherwise it wont be able to find it. To test the correct installation, type:

tf$constant("Hello Tensorflow!")

You should obtain messages such as "Loaded Tensorflow version 2.9.2" and "tf.Tensor(b'Hello Tensorflow!', shape=(), dtype=string)".

You can terminate the current R session:

q()

Save workspace image? [y/n/c]: n

TO DO THE PRACTICALS (today or another day):

Simply run R in your terminal or launch RStudio.

JupyterLab

Here are some instructions for installing Keras with TensorFlow at the backend, and other libraries, on the JupyterLab of the EPFL.

Go to the webpage: https://noto.epfl.ch/

Use your Switch AAI login: University of Lausanne

Enter the login and password associated to your Switch edu-ID (and NOT your UNIL credentials).

Select Git / Clone a Repository (at the top of the window) and enter the following URL:

https://c4science.ch/source/DL_INTRO.git

Python installation

Click on the Terminal square button in the Other panel (at the bottom of the page).

Let us create a virtual environment. Type (or copy/paste):

my_venvs_create mlcourse

Press return.

Then type and run the following commands:

my_venvs_activate mlcourse

pip install -r DL_INTRO/requirements.txt

my_kernels_create Deep_Learning "Deep Learning"

my_venvs_deactivate

You may receive some error message concerning incompatible versions between libraries. Do not worry, it should still work. The installation is complete !

Select File / Log out to close the Jupyter session.

TO DO THE PRACTICALS (today or another day):

Log into the JupyterLab, double click on the "my_notebooks" folder (left pannel) and then click on the "Deep Learning" square button in the Notebook panel.

To execute this command, click on "Run the selected cells and advance" (the right arrow), or SHIFT + RETURN.

When using TensorFlow, you may receive a warning

2022-09-22 11:01:12.232756: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2022-09-22 11:01:12.232856: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

You should not worry. By default, TensorFlow is trying to use GPUs and since there are no GPUs, it writes a warning and decides to use CPUs (which is enough for our course).

When you have finished the practicals, select File / Log out.

R installation

Click on the R square button in the Notebook panel, and type (or copy/paste) in the first cell:

install.packages("keras")

To execute this command, click on "Run the selected cells and advance" (the right arrow), or SHIFT + RETURN.

Then type and run the following commands in the cells:

library(keras)

library(tensorflow)

install_tensorflow(method="virtualenv", envname="r-tensorflow", version="2.9.2")

install.packages("ggplot2")

install.packages("ggfortify")

The installation is complete !

Select File / Log out to close the Jupyter session.

TO DO THE PRACTICALS (today or another day):

Log into the JupyterLab, double click on the "my_notebooks" folder (left pannel) and then click on the R square button in the Notebook panel.

When using TensorFlow, you may receive a warning

2022-09-22 11:01:12.232756: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2022-09-22 11:01:12.232856: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

You should not worry. By default, TensorFlow is trying to use GPUs and since there are no GPUs, it writes a warning and decides to use CPUs (which is enough for our course).

When you have finished the practicals, select File / Log out.

Curnagl

For the practicals, it will be convenient to be able to copy/paste text from a web page to the terminal on Curnagl. So please make sure you can do it before the course. You also need to make sure that your terminal has a X server.

For Mac users, download and install XQuartz (X server): https://www.xquartz.org/

For Windows users, download and install MobaXterm terminal (which includes a X server). Click on the "Installer edition" button on the following webpage: https://mobaxterm.mobatek.net/download-home-edition.html

For Linux users, you do not need to install anything.

When testing if TensorFlow was properly installed (see below) you may receive a warning

2022-03-16 12:15:00.564218: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /dcsrsoft/spack/hetre/v1.2/spack/opt/spack/linux-rhel8-zen2/gcc-9.3.0/python-3.8.8-tb3aceqq5wzx4kr5m7s5m4kzh4kxi3ex/lib:/dcsrsoft/spack/hetre/v1.2/spack/opt/spack/linux-rhel8-zen2/gcc-9.3.0/tcl-8.6.11-aonlmtcje4sgqf6gc4d56cnp3mbbhvnj/lib:/dcsrsoft/spack/hetre/v1.2/spack/opt/spack/linux-rhel8-zen2/gcc-9.3.0/tk-8.6.11-2gb36lqwohtzopr52c62hajn4tq7sf6m/lib:/dcsrsoft/spack/hetre/v1.2/spack/opt/spack/linux-rhel8-zen/gcc-8.3.1/gcc-9.3.0-nwqdwvso3jf3fgygezygmtty6hvydale/lib64:/dcsrsoft/spack/hetre/v1.2/spack/opt/spack/linux-rhel8-zen/gcc-8.3.1/gcc-9.3.0-nwqdwvso3jf3fgygezygmtty6hvydale/lib
2022-03-16 12:15:00.564262: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

You should not worry. By default, TensorFlow is trying to use GPUs and since there are no GPUs, it writes a warning and decides to use CPUs (which is enough for our course).

Python installation

Here are some instructions for installing Keras with TensorFlow at the backend (for Python3), and other libraries, on the UNIL cluster called Curnagl. Open a terminal on your laptop and type (if you are located outside the UNIL you will need to activate the UNIL VPN):

ssh -Y < my unil username >@curnagl.dcsr.unil.ch

Here and in what follows we added the brackets < > to emphasize the username, but you should not write them in the command. Enter your UNIL password.

For Windows users with the MobaXterm terminal: Launch MobaXterm, click on Start local terminal and type the command ssh -Y < my unil username >@curnagl.dcsr.unil.ch. Enter your UNIL password. Then you should be on Curnagl. Alternatively, launch MobaXterm, click on the session icon and then click on the SSH icon. Fill in: remote host = curnagl.dcsr.unil.ch, specify username = < my unil username >. Finally, click ok, enter your password. If you have the question "do you want to save password ?" Say No if your are not sure. Then you should be on Curnagl.

See also the documentation: https://wiki.unil.ch/ci/books/high-performance-computing-hpc/page/ssh-connection-to-dcsr-cluster

cd /work/TRAINING/UNIL/CTR/rfabbret/cuso_hpc_2023

mkdir < my unil username >

cd < my unil username >

For convenience, you will install the libraries from the frontal node to do the practicals. Note however that it is normally recommended to install libraries from the interactive partition by using (Sinteractive -m 4G -c 1).

git clone https://c4science.ch/source/DL_INTRO.git

module load gcc python/3.9.13

python -m venv mlcourse

source mlcourse/bin/activate

pip install -r DL_INTRO/requirements.txt

To check that TensorFlow was installed:

python -c 'import tensorflow; print(tensorflow.version.VERSION)'

There might be a warning message (see above) and the output should be something like "2.8.0".

You can terminate the current session:

deactivate

exit

TO DO THE PRACTICALS (today or another day):

ssh -Y < my unil username >@curnagl.dcsr.unil.ch

cd /work/TRAINING/UNIL/CTR/rfabbret/cuso_hpc_2023/< my unil username >

For convenience, you will work directly on the frontal node to do the practicals. Note however that it is normally not allowed to work directly on the frontal node, and you should use (Sinteractive -m 4G -c 1).

module load gcc python/3.9.13

source mlcourse/bin/activate

python

R installation

Here are some instructions for installing Keras with TensorFlow at the backend, and other libraries, on the UNIL cluster called Curnagl. The R keras is actually an interface to the Python Keras. In simple terms, this means that the keras R package allows you to enjoy the benefit of R programming while having access to the capabilities of the Python Keras package. Open a terminal on your laptop and type (if you are located outside the UNIL you will need to activate the UNIL VPN):

ssh -Y < my unil username >@curnagl.dcsr.unil.ch

Here and in what follows we added the brackets < > to emphasize the username, but you should not write them in the command. Enter your UNIL password.

For Windows users with the MobaXterm terminal: Launch MobaXterm, click on Start local terminal and type the command ssh -Y < my unil username >@curnagl.dcsr.unil.ch. Enter your UNIL password. Then you should be on Curnagl. Alternatively, launch MobaXterm, click on the session icon and then click on the SSH icon. Fill in: remote host = curnagl.dcsr.unil.ch, specify username = < my unil username >. Finally, click ok, enter your password. If you have the question “do you want to save password ?” Say No if your are not sure. Then you should be on Curnagl.

See also the documentation: https://wiki.unil.ch/ci/books/high-performance-computing-hpc/page/ssh-connection-to-dcsr-cluster

cd /work/TRAINING/UNIL/CTR/rfabbret/cours_hpc/

mkdir < my unil username >

cd < my unil username >

For convenience, you will install the libraries from the frontal node to do the practicals. Note however that it is normally recommended to install libraries from the interactive partition by using (Sinteractive -m 4G -c 1).

module load gcc python/3.9.13 r/4.2.1

R

REMARK: The R libraries will be installed in your home directory. To allow it, you must answer yes to the questions:

Would you like to use a personal library instead? (yes/No/cancel) yes

Would you like to create a personal library to install packages into? (yes/No/cancel) yes

And select Switzerland for the CRAN mirror.

install.packages("keras")

library(keras)

library(tensorflow)

install_tensorflow(method="virtualenv", envname="r-tensorflow", version="2.5.0")

install.packages("ggplot2")

install.packages("ggfortify")

To check that Keras was properly installed:

is_keras_available(version = NULL)

There might be a warning message (see above) and the output should be something like "TRUE".

You can terminate the current R session:

q()

Save workspace image? [y/n/c]: n

TO DO THE PRACTICALS (today or another day):

ssh -Y < my unil username >@curnagl.dcsr.unil.ch

cd /work/TRAINING/UNIL/CTR/rfabbret/cours_hpc/< my unil username >

For convenience, you will work directly on the frontal node to do the practicals. Note however that it is normally not allowed to work directly on the frontal node, and you should use (Sinteractive -m 4G -c 1).

module load gcc python/3.9.13 r/4.2.1

R