Warning
This page is located in archive.

Python and PyTorch Development

This page is based on the one of RPZ course.

  • The BRUTE uses python version 3.10
  • Use the forum to discuss any Python issues.
  • If you have experience with MATLAB programming, you can start by Numpy for MATLAB users.

The evaluation server has the following packages installed:

  • python (3.10.6)
  • numpy (1.21.5)
  • matplotlib (3.5.2)
  • torch (1.12.1+cpu)
  • torchvision (0.13.1+cpu)
  • kornia (0.6.10)
  • kornia_moons (0.2.3)
  • opencv-python (4.7.0.68)
  • Pillow (9.2.0)

Common Issues and Solutions

  • Not working with correct shapes of input/output data: Shapes of all input/output data are defined in the docstring of individual methods. Note, that all templates in assignment already output result of a proper shape. Please strictly stick to the prescribed shapes.
    • If you want to use i.e. np array <1xn> as (n,), you can use np.squeeze() in the beginning of the method.
    • For returning data in certain shape, you can use np.expand_dims() or np.at_leastXd() (where X is the number of dimmensions).
  • The template does not specify something correctly or differs from the assignment text
    • You are probably using an old version of the template. As noted in the git repository readme: Keep in mind that the assignments and the assignment templates will be updated during the semester. Always pull the current template version before starting to work on an assignment!

Assignment Templates

  • All assignment templates are stored in a git repository
  • Follow the instruction in the repository README
  • Make sure to get the current template version before starting to work on an assignment
  • Make sure not to push the repository with your solutions to any public remote (=plagiarism), you can use FEE GitLab for private remote repo.
  • Each assignment template contains a Jupyter notebook (.ipynb) that you can use to testrun the assignment functions you implement. This notebook will not be checked by the BRUTE.

This setup is recommended by Dmytro Mishkin
1. Install Miniconda, Python version 3.X.
2. Run conda CLI.
3. Run

git clone https://gitlab.fel.cvut.cz/mishkdmy/mpv-python-assignment-templates
conda create --name mpv-assignments-cpu-only python=3.10
conda activate mpv-assignments-cpu-only
pip3 install torch==1.12.1+cpu torchvision==0.13.1+cpu torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cpu
pip3 install kornia==0.6.10 tqdm notebook matplotlib opencv-contrib-python==4.7.0.68 seaborn tensorboard tensorboardX ipywidgets widgetsnbextension
pip3 install kornia_moons --no-deps

For MacOS on Apple Silicon run

git clone https://gitlab.fel.cvut.cz/mishkdmy/mpv-python-assignment-templates
conda create --name mpv-assignments-cpu-only python=3.10
conda activate mpv-assignments-cpu-only
conda install -c apple tensorflow-deps
pip3 install tensorflow-macos tensorflow-metal
pip3 install torch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cpu
pip3 install kornia==0.6.10 tqdm notebook matplotlib opencv-contrib-python==4.7.0.68 seaborn tensorboard tensorboardX ipywidgets widgetsnbextension
pip3 install kornia_moons --no-deps

For the GPU setup, if you have CUDA-capable GPU (if needed - change CUDA version in command). To find out your CUDA version, run nvidia-smi. You will see something like:

Mon Feb 20 16:49:46 2023       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.39       Driver Version: 460.39       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 108...  On   | 00000000:01:00.0 Off |                  N/A |
| 25%   44C    P8    18W / 250W |      1MiB / 11178MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 108...  On   | 00000000:06:00.0 Off |                  N/A |
|ERR!   54C    P0   ERR! / 250W |      1MiB / 11178MiB |     75%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+
In the example above, the CUDA version is 11.2, so you should use –extra-index-url https://download.pytorch.org/whl/cu112.

git clone https://gitlab.fel.cvut.cz/mishkdmy/mpv-python-assignment-templates
conda create --name mpv-assignments-gpu python=3.10
conda activate mpv-assignments-gpu
pip3 install torch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu112
pip3 install kornia==0.6.10 tqdm notebook matplotlib opencv-contrib-python==4.7.0.68 seaborn tensorboard tensorboardX ipywidgets widgetsnbextension
pip3 install kornia_moons --no-deps
See in more details about Pytorch install on official page.

4. a) Activate the environment with

conda activate mpv-assignments-cpu-only
and work in the python interactive interpreter.

PyCharm jupyter environment is buggy and not recommended. You still can use IDE to edit .py files though. It's best to use jupyter-notebook, google colab or jupyter-lab to work with jupyter notebooks, especially interactive ones (as in Correspondences and Tracking blocks.

Running the assignments in Google Colab

It is possible to do all the work in cloud Google Colab without installing anything. You would need to have Google account though.

  1. Git clone or download the assignment templates from the repository
  2. Click File → Upload notebook and upload the notebook for the the relevant assignment
  3. Click of the files icon (in gray ellipse on the screenshot) and then on “Upload”
  4. Upload relevant assignment .py together with all relevant input data such as images.
  5. In the beginning of the first cell add
     !pip install kornia==0.6.10
  6. Work in Google Colab as if you were in Jupyter notebook. In the end of the session download the functions you developed with File → Download
  7. If you need to use GPU, go to Runtime →Change runtime type. Select Hardware accelerator to be GPU. Note, that you are limited to 6 hours of GPU use per day (this info might be obsolete, as Google policy on free GPUs may change)
courses/mpv/labs/general_info.txt · Last modified: 2024/02/12 15:57 (external edit)