This page is located in archive. Go to the latest version of this course pages. Go the latest version of this page.

Quick links: Schedule | Forum | BRUTE | Lectures | Labs

Labs How To

Basic info

If you are new to CTU, see the checklist for visiting students.


There is a discussion forum administered for this course that can be used to solicit help for the assignments. It is monitored by the lab assistants and it is the preferred form of communication for getting assistance for the assignments since all students can see the question and answer threads. If you find an error in the assignment or it is unclear/ambiguous, please write on the forum.

We also ask you to write remarks about lectures (typos, questions).

Python, IDEs

You will implement the labs in python. The assignment templates are prepared in python 3.7. The first lab will need python with standard packages (numpy, matplotlib).

For the case you are not too sure about your Python/NumPy skills, have a look here: http://cs231n.github.io/python-numpy-tutorial/.

We recommend using an IDE for python development. There is a professional PyCharm license available to the university https://download.cvut.cz. However, it could be somewhat slow (running on java and has many features).

We recommend Visual Studio Code. It is very easy to setup and convenient to work with. Follow these basic instructions and Wizards from within VS:

Jupyter / IPython (VS Code)

Recommended configuration (user settings)

"jupyter.interactiveWindow.textEditor.magicCommandsAsComments": true

Then in an IPython file you can use magic commands in comments, which are skipped if executed as script and take effect when executed interactively:

import matplotlib
import matplotlib.pyplot as plt

#!%load_ext autoreload
#!autoreload 2
#!%matplotlib inline

Jupyter Notebooks

Here's some lines of code useful in Jupyter notebooks.

   """ Resize the notbook to full width, to fit more code and images """
   from IPython.core.display import display, HTML
   display(HTML("<style>.container { width:100% !important; }</style>"))
   """ some basic packages and settings to show images inline """
   import numpy as np
   import importlib
   %matplotlib inline
   import matplotlib.pyplot as plt
   """ automatically reload included modules (need to run import command to trigger reloading) """
   %load_ext autoreload
   %autoreload 2
   """ Controls for figure sizes to change """
   plt.rcParams['figure.dpi'] = 200
   plt.rcParams['figure.figsize'] = [16, 8]
   plt.rcParams.update({'errorbar.capsize': 1})

If you need to debug an exception in Jupyter notebook, there is a %debug command that opens a console to see local variables and navigate call stack.

Google Colab

An easy way to try something with deep learning is Google Colab. Take a look at intro colab space. It has tensorflow and pytorch installed and you also get GPU acceleration. But it is harder to work with a bigger project with classes, debug, etc.

Remote Servers

See student GPU servers at the department.

  1. Follow the rules instructed there.
  2. All servers have configurable environment module system Lmod.
  3. ml spider torch shows all available versions of pytorch, check also 'ml spider torchvision'.
  4. Load the module e.g. with
     ml torchvision/0.11.1-foss-2021a-CUDA-11.3.1 
    (“loads” pytorch, python of the right versions and all other dependencies).
  5. Check which GPU is available with nvidia-smi or gpu-status script
  6. Run using this GPU:
     export CUDA_VISIBLE_DEVICES=3; python train.py --lr 0.001
  7. With VS code you can execute scripts or jupyter notebooks transparently from inside the IDE.
    However, VScode tends to keep the connection active even after you turn off your computer. As the GPU memory is expensive, login to the server regularly and check if your processes still occupy some GPUs. You may call pkill -f ipykernel to kill these processes.
  8. For a more convenient work with servers you can setup passwordless access, mount the file system and save you module configuration (see below).


To not have to type your password each time you login, you can configure authentication on the server used pre-shared keys. You can do so using ssh-keygen and ssh-add.
This instruction for linux seems ok.


If you want to copy some data there and back to the server, it is convenient to mount your working directory on the server to your filesystem using sshfs. This tool works at first, but may be failing in certain cases, when you change network access point, sleep / wake computer, etc. I use the following settings:

sshfs -o defer_permissions,reconnect,ServerAliveInterval=120,ServerAliveCountMax=3,follow_symlinks,compression=yes -o kernel_cache,entry_timeout=5,sync_read shekhovt@cantor.felk.cvut.cz:/~ ~/cantor 

Lmod Configuration in Bash Profile

You can configure the system environment you get when login to the server (see Controlling Modules During Login ). For this, create on the server ~/.bash_profile standardly containing

# .bash_profile

if [ -f ~/.bashrc ]; then
source ~/.bashrc
and '~/.bashrc' where you put your configurations, e.g.
module restore

The command module restore there loads in the modules configuration previously saved with module save. This configuration should (theoretically) work even for non-interactive shell, such as when you configure Pycharm to run your code there.

Lmod Configuration for VS Code (Wrapping Python)

For this method we create a bash script in the project's folder, which will setup the environment and only then will call python. Let's give it the name python_ml, it has to be an executable. The contents should be e.g.

#!/bin/bash -l
# setup the environment
ml purge
ml matplotlib/3.5.2-foss-2022a
ml torchvision/0.15.0-rc1-foss-2022a-CUDA-11.7.0
# call python (from the PATH as configured by the above), passing all arguments to it
python "$@"

  • In VS Code hit F1 and find 'Python:Select Interpreter' by starting typing. Use '+Enter Interpreter path → Browse →' and pick this script from your project folder. Whenever asked later (e.g. to run a jupyter notebook) select the same.
  • Changes made to the environment inside this script get in effect on the next execution of the program. However, for the static analysis to pick up the new environment, a restart of VS code may be needed and possibly a restart of VS Code server.
  • VS Code Server is a daemon executing on the server. To restart it from VS Code use F1→“Kill VS Code Server on Host…”.
  • Let us know if you encounter some problems, perhaps some additional settings are required
courses/bev033dle/labs/0_howto/start.txt · Last modified: 2023/05/25 14:54 by sochmjan