===== Python and PyTorch Development ===== This page is based on the one of [[https://cw.fel.cvut.cz/b191/courses/be5b33rpz/labs/python_development|RPZ course]]. * The BRUTE uses python version 3.6 * Use the [[https://cw.felk.cvut.cz/forum/forum-1639.html|forum]] to discuss any Python issues. * If you want to use an IDE, there is a professional PyCharm licence available at [[https://download.cvut.cz|https://download.cvut.cz]] (but feel free to use [[https://www.xkcd.com/378/|butterflies]] instead). * If you have experience with MATLAB programming, you can start by [[https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html|Numpy for MATLAB users]]. ===== 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 [[https://gitlab.fel.cvut.cz/mishkdmy/mpv-python-assignment-templates|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 [[https://gitlab.fel.cvut.cz/mishkdmy/mpv-python-assignment-templates|git repository]] * If you don't know how to use git: [[https://git-scm.com/book/en/v2|Pro Git book]], [[https://try.github.io/]], duckduck, google, ... * 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 [[https://gitlab.fel.cvut.cz/|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.** ===== Setup recommended by Dmytro ===== This setup is recommended by Dmytro Mishkin\\ 1. Install [[https://docs.conda.io/en/latest/miniconda.html|Miniconda]], Python version 3.X.\\ 2. Run **conda** CLI.\\ 3. For Linux users run git clone https://gitlab.fel.cvut.cz/mishkdmy/mpv-python-assignment-templates cd mpv-python-assignment-templates/conda_env_yaml conda env create -f environment-cpu.yml 3* For Windows users: git clone https://gitlab.fel.cvut.cz/mishkdmy/mpv-python-assignment-templates conda create --name mpv-assignments-cpu-only python=3.6 conda activate mpv-assignments-cpu-only conda install pytorch torchvision cpuonly -c pytorch pip install kornia tqdm notebook matplotlib opencv-contrib-python seaborn tensorboard tensorboardX conda install -c conda-forge widgetsnbextension conda install -c conda-forge ipywidgets 4. a) Activate the environment with conda activate mpv-assignments-cpu-only and work in the **python** interactive interpreter.\\ 5. b) Use the IDE of your choice (IntelliJ PyCharm, of course) and set the interpreter of your project to the **python** executable/binary in your environment's path. Run your scripts using PyCharm's //configurations//.[[https://docs.anaconda.com/anaconda/user-guide/tasks/integration/python-path/|How to find the path to your environment's interpreter?]]\\ ==== 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. - Git clone or download the assignment templates from the [[https://gitlab.fel.cvut.cz/mishkdmy/mpv-python-assignment-templates/tree/master|repository]] - Go to https://colab.research.google.com/ - Click File -> Upload notebook and upload the notebook for the the relevant assignment - Click of the files icon (in gray ellipse on the screenshot) and then on "Upload" - {{:courses:mpv:labs:colab1.png?400|}} - Upload relevant assignment .py together with all relevant input data such as images. - In the beginning of the first cell add !pip install kornia - 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 - If you need to use GPU, go to Edit->Notebook settings. 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)