Lab 2: Rotations
Introduction
In this lab, you'll be creating a classifier to determine whether an image is rotated (not-rotated, left, right, or 180 degrees). This could be useful, for example, in a photo viewer to automatically rotate images that are not right-side-up.
The key to this lab is that properly labeled data is not provided.
You'll need to be preparing the data.
Prepare data
Use the same data as was used for lab 1 (download).
The data has valid, train, and test folders.
In order to have the most training data, train on the data in both the train and test folders.
Use the data in the valid folder for validation.
Problems:
- the data is categorized into giraffe and rhino classes, which isn't useful
for this lab.
- all the data is right-side-up. There's no 90, 180, or 270 degree rotated data to train on.
A solution is to:
Useful methods when preparing data:
Train model
Now that you have your data, you can train a model. Use an existing pretrained model (like resnet34 or squeezenet1_1).
See how low you can get the validation loss.
Get it to below 0.16.
Test model
What is the validation accuracy associated with the validation loss you achieved?
Which images in the validation set is the classifier least sure about? (You may find plot_top_losses useful—see fast.ai book chapter 2).
Suggestions
Instead of pre-rotating each image, create a transform that will randomly both do the rotation and change the label (y).
Thus, your dataloader can just load all the unrotated images, and the transform will do the rotation on the fly as part of data augmentation.
Note that this is a difficult problem.
Turn this into a regression problem where you are predicting the numeric degrees of rotation given a rotated image.
In this case, you'll want to support rotating with increments of less than 90 degrees.
You'll need:
- a custom loss function (since a y of 1 and a y-hat of 359 should yield fairly low loss). Or,
instead, generate 2 y's instead of 1 (sin and cos of the angle). In that case, you can just
use the standard MSE.
- to use the DataBlock API to generate a dataloaders that have a RegressionBlock rather than CategoryBlock as the type of y.
There may be other issues you'll need to solve as well.
Note that this is a difficult problem.
This completes the lab.
Submit instructions
- Make sure that the output of all cells is up-to-date.
- Rename your notebook:
- Click on notebook name at the top of the window.
- Rename to "CS152Sp21Lab2 FirstName1/FirstName2" (using the correct lab number, along with your two first names).
I need this naming so I can easily navigate through the large number of shared docs I will have by the end of the semester.
- Choose File/Save
- Share your notebook with me:
- Click on the Share button at the top-right of your notebook.
- Enter rhodes@g.hmc.edu as the email address.
- Click the pencil icon and select Can comment.
- Click on Done.
- Enter the URL of your colab notebook in this submittal form.
Do not copy the URL from the address bar (which may contain an authuser parameter and which I will not be able to open).
Instead, click Share and Copy link to obtain the correct link.
Enter your names in alphabetical order.
- At this point, you and I will go back and forth until the lab is approved.
- I will provide inline comments as I evaluate the submission (Google should notify you of these comments via email).
- You will then need to address those comments. Please do not resolve or delete the comments. I will use them as a record of our conversation. You can respond to them ("Fixed" perhaps).
- Once you have addressed all the comments in this round, fill out the submittal form again.
- Once I am completely satisifed with your lab, I will add a LGTM (Looks Good to Me) comment
- At that point, setup an office hour appointment with me. Ill meet with you and your partner and we'll have a short discussiona about the lab. Both of you should be able to answer questions about any part of the lab.
'