Homework 3

starter code data dense data colab notebook

In this homework, we will use all the trick at our disposal to tune a classification network on supertux. We then make this classification network fully convolutional and solve a semantic labeling task (labeling every pixel in the image).

This assignment should be solved individually. No collaboration, sharing of solutions, or exchange of models is allowed. Please, do not directly copy existing code from anywhere other than your previous solutions, or the previous master solution. We will check assignments for duplicates. See below for more details.

Tuning your classifier

In the first part of this homework, you’ll tune your classifier, or the classifier of the master solution 2 to achieve as high an accuracy as possible. You may directly copy any code from your solution or the master solution to homework 2. The goal of this first part is to tune the classifier to an accuracy of $90\%$. This might require several tricks:

We managed to tune our classifier to a $94\%$ accuracy with a training time of 10 GPU minutes. If you manage to reach this accuracy you’ll get 10 extra credits.

Test your model with

python -m grader homework

Relevant Operations

Dense prediction (semantic segmentation)

In the second part of the homework, you’ll make your CNN fully convolutional. Instead of predicting a single output per image, you’ll now predict an output per pixel.

Our current dataset does not support this output, we thus switch to a new dense prediction dataset. Here all images have a $128 \times 96$ resolution, and the labels are of the same size. We have 5 labels here: background, kart, track, bomb/projectile, pickup/nitro. We merged the last two classes, as they already have very few labeled instances. The class distribution for those labels is quite bad. background and track make up $96\%$ of the labeled area! We will address this issue later for evaluation.

To see some examples from the dense dataset run

python -m homework.utils

FCN design

Design your FCN by writing the model in models.py. Make sure to use only convolutional operators, pad all of them correctly and match strided operators with up-convolutions. Use skip and residual connections.

Make sure your FCN handles an arbitrary input resolution and produces an output of the same shape as the input. Use output_padding=1 if needed. Crop the output if it is too large.

Test your model with

python -m grader homework

FCN Training

To train your FCN you’ll need to modify your CNN training code a bit. First, you need to use the DenseSuperTuxDataset. This dataset accepts a data augmentation parameters transform. Most standard data augmentation in torchvision do not directly apply to dense labeling tasks. We thus provide you with a smaller subset of useful augmentations that properly work with a pair of image and label in dense_transforms.py.

You will need to use the same bag of tricks as for classification to make the FCN train well.

Since the training set has a large class imbalance, it is easy to cheat in a pixel-wise accuracy metric. Predicting only track and background gives a $96\%$ accuracy. We additionally measure the Intersection-over-Union evaluation metric. This is a standard semantic segmentation metric that penalizes largely imbalanced predictions. This metric is harder to cheat, as it computes You might need to change the class weights of your torch.nn.CrossEntropyLoss, although our master solution did not require this. You can compute the IoU and accuracy using the ConfusionMatrix class.

Test your model with

python -m grader homework

Relevant Operations

Grading

We will grade your assignment using the following rubric:

Important note: The test set is significantly harder for dense prediction. Please make sure that you overshoot both accuracy measures by $0.05$ to get full credit. Do NOT tune any parameters on the validation set, or your local grading performance might not be predictive of your test performance.

Submission

Once you finished the assignment, create a submission bundle using

python bundle.py homework [YOUR UT ID]

and submit the zip file online. If you want to double-check that your zip file was properly created, you can grade it again

python -m grader [YOUR UT ID].zip

Running your assignment on google colab

You might need a GPU to train your models. You can get a free one on google colab. We provide you with a ipython notebook that can get you started on colab for each homework. Follow the instructions below to use it.

Honor code

This assignment should be solved individually.

What interaction with classmates is allowed?

What interaction is not allowed?

Ways students failed in past years (do not do this):

Installation and setup

Installing python 3

Go to https://www.python.org/downloads/ to download python 3. Alternatively, you can install a python distribution such as Anaconda. Please select python 3 (not python 2).

Installing the dependencies

Install all dependencies using

pip install -r requirements.txt

Note: On some systems, you might be required to use pip3 instead of pip for python 3.

If you’re using conda use

conda env create environment.yml

Manual installation of pytorch

Go to https://pytorch.org/get-started/locally/ then select the stable Pytorch build, your OS, package (pip if you installed python 3 directly, conda if you installed Anaconda), python version, cuda version. Run the provided command. Note that cuda is not required, you can select cuda = None if you don’t have a GPU or don’t want to do GPU training locally. We will provide instruction for doing remote GPU training on Google Colab for free.

Manual installation of the Python Imaging Library (PIL)

The easiest way to install the PIL is through pip/pip3 or conda.

pip install -U Pillow

There are a few important considerations when using PIL. First, make sure that your OS uses libjpeg-turbo and not the slower libjpeg (all modern Ubuntu versions do by default). Second, if you’re frustrated with slow image transformations in PIL use Pillow-SIMD instead:

CC="cc -mavx2" pip install -U --force-reinstall Pillow-SIMD

The CC="cc -mavx2" is only needed if your CPU supports AVX2 instructions. pip will most likely complain a bit about missing dependencies. Install them, either through conda, or your favorite package manager (apt, brew, …).