This homework won’t ask you to implement anything serious, just run some tests and make some graphs. The goal is to get you to think about feature extraction and feature spaces by interacting with them. For lecture 24, there were a large number of trained models. Let’s take the 50 epoch resnet model and the rbf kernel SVM trained with its feature vector and do some experiments.
The trained model is here.
The trained SVM pickle is here.
You can reload them as in the code used in lecture 24. (but example code will be given for this homework, so continue reading)
You will also need some example digits. The first twenty test images from digits are here. Their classes are (7 2 1 0 4 1 4 9 5 9 0 6 9 0 1 5 9 7 3 4).
The first twenty training images are here, with classes (5 0 4 1 9 2 1 3 1 4 3 5 3 6 1 7 2 8 6 9).
The example code loads any two digits and slowly morphs the first into the second, by sampling in decreasing part from the first and increasing from the second.
print("Loading data")
first = np.array(Image.open(args.first))/255.0
second = np.array(Image.open(args.second))/255.0
# Make a blending of the images in 101 steps, from fully first to fully second
blends = []
for i in range(101):
alpha = (100 - i) / 100
blend = first * alpha + second * (1 - alpha)
blends.append(blend)
data = np.array(blends)This homework asks for answers to two open-ended questions and for several figures. The first question should be done before loading any numbers.
(20 points) Before loading any numbers (or reading ahead), how do you think the SVM and residual network will classify the blended digits? Will they guess wildly when presented an image that is an equal blend of two different digits? Explain, in a few sentences.
(20 points) Load a few pairs of digits to see if your intuition is correct or incorrect. If your supposition was correct, how could you verify your thought process? If your supposition was incorrect, where do you think you erred?
(20 points) Choose two different digits in either the training or the testing set and get their blended results. Plot the scores from the SVM and the DNN for the two correct classes (with score on the y axis and blend step on the x axis). You will need to modify the code to see all of the correct values. SVM scores are given by svm.decision_function and the DNN scores come from the model directly, in this code:
# SVM Classification
svm_classes = svm.predict(features)
svm_y_hat = svm.decision_function(features)
print(f"SVM scores {svm_y_hat}")
print(f"SVM classes {svm_classes}")
# DNN classification
y_hat = model(data)
classes = torch.argmax(y_hat, dim=1)