Image features exercise

Complete and hand in this completed worksheet (including its outputs and any supporting code outside of the worksheet) with your assignment submission. For more details see the assignments page on the course website.

We have seen that we can achieve reasonable performance on an image classification task by training a linear classifier on the pixels of the input image. In this exercise we will show that we can improve our classification performance by training linear classifiers not on raw pixels but on features that are computed from the raw pixels.

All of your work for this exercise will be done in this notebook.


In [1]:
import random
import numpy as np
from cs231n.data_utils import load_CIFAR10
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['figure.figsize'] = (10.0, 8.0) # set default size of plots
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'

# for auto-reloading extenrnal modules
# see http://stackoverflow.com/questions/1907993/autoreload-of-modules-in-ipython
%load_ext autoreload
%autoreload 2

Load data

Similar to previous exercises, we will load CIFAR-10 data from disk.


In [2]:
from cs231n.features import color_histogram_hsv, hog_feature

def get_CIFAR10_data(num_training=49000, num_validation=1000, num_test=1000):
  # Load the raw CIFAR-10 data
  cifar10_dir = 'cs231n/datasets/cifar-10-batches-py'
  X_train, y_train, X_test, y_test = load_CIFAR10(cifar10_dir)
  
  # Subsample the data
  mask = range(num_training, num_training + num_validation)
  X_val = X_train[mask]
  y_val = y_train[mask]
  mask = range(num_training)
  X_train = X_train[mask]
  y_train = y_train[mask]
  mask = range(num_test)
  X_test = X_test[mask]
  y_test = y_test[mask]

  return X_train, y_train, X_val, y_val, X_test, y_test

X_train, y_train, X_val, y_val, X_test, y_test = get_CIFAR10_data()

Extract Features

For each image we will compute a Histogram of Oriented Gradients (HOG) as well as a color histogram using the hue channel in HSV color space. We form our final feature vector for each image by concatenating the HOG and color histogram feature vectors.

Roughly speaking, HOG should capture the texture of the image while ignoring color information, and the color histogram represents the color of the input image while ignoring texture. As a result, we expect that using both together ought to work better than using either alone. Verifying this assumption would be a good thing to try for the bonus section.

The hog_feature and color_histogram_hsv functions both operate on a single image and return a feature vector for that image. The extract_features function takes a set of images and a list of feature functions and evaluates each feature function on each image, storing the results in a matrix where each column is the concatenation of all feature vectors for a single image.


In [3]:
from cs231n.features import *

num_color_bins = 10 # Number of bins in the color histogram
feature_fns = [hog_feature, lambda img: color_histogram_hsv(img, nbin=num_color_bins)]
X_train_feats = extract_features(X_train, feature_fns, verbose=True)
X_val_feats = extract_features(X_val, feature_fns)
X_test_feats = extract_features(X_test, feature_fns)

# Preprocessing: Subtract the mean feature
mean_feat = np.mean(X_train_feats, axis=0, keepdims=True)
X_train_feats -= mean_feat
X_val_feats -= mean_feat
X_test_feats -= mean_feat

# Preprocessing: Divide by standard deviation. This ensures that each feature
# has roughly the same scale.
std_feat = np.std(X_train_feats, axis=0, keepdims=True)
X_train_feats /= std_feat
X_val_feats /= std_feat
X_test_feats /= std_feat

# Preprocessing: Add a bias dimension
X_train_feats = np.hstack([X_train_feats, np.ones((X_train_feats.shape[0], 1))])
X_val_feats = np.hstack([X_val_feats, np.ones((X_val_feats.shape[0], 1))])
X_test_feats = np.hstack([X_test_feats, np.ones((X_test_feats.shape[0], 1))])


Done extracting features for 1000 / 49000 images
Done extracting features for 2000 / 49000 images
Done extracting features for 3000 / 49000 images
Done extracting features for 4000 / 49000 images
Done extracting features for 5000 / 49000 images
Done extracting features for 6000 / 49000 images
Done extracting features for 7000 / 49000 images
Done extracting features for 8000 / 49000 images
Done extracting features for 9000 / 49000 images
Done extracting features for 10000 / 49000 images
Done extracting features for 11000 / 49000 images
Done extracting features for 12000 / 49000 images
Done extracting features for 13000 / 49000 images
Done extracting features for 14000 / 49000 images
Done extracting features for 15000 / 49000 images
Done extracting features for 16000 / 49000 images
Done extracting features for 17000 / 49000 images
Done extracting features for 18000 / 49000 images
Done extracting features for 19000 / 49000 images
Done extracting features for 20000 / 49000 images
Done extracting features for 21000 / 49000 images
Done extracting features for 22000 / 49000 images
Done extracting features for 23000 / 49000 images
Done extracting features for 24000 / 49000 images
Done extracting features for 25000 / 49000 images
Done extracting features for 26000 / 49000 images
Done extracting features for 27000 / 49000 images
Done extracting features for 28000 / 49000 images
Done extracting features for 29000 / 49000 images
Done extracting features for 30000 / 49000 images
Done extracting features for 31000 / 49000 images
Done extracting features for 32000 / 49000 images
Done extracting features for 33000 / 49000 images
Done extracting features for 34000 / 49000 images
Done extracting features for 35000 / 49000 images
Done extracting features for 36000 / 49000 images
Done extracting features for 37000 / 49000 images
Done extracting features for 38000 / 49000 images
Done extracting features for 39000 / 49000 images
Done extracting features for 40000 / 49000 images
Done extracting features for 41000 / 49000 images
Done extracting features for 42000 / 49000 images
Done extracting features for 43000 / 49000 images
Done extracting features for 44000 / 49000 images
Done extracting features for 45000 / 49000 images
Done extracting features for 46000 / 49000 images
Done extracting features for 47000 / 49000 images
Done extracting features for 48000 / 49000 images

Train SVM on features

Using the multiclass SVM code developed earlier in the assignment, train SVMs on top of the features extracted above; this should achieve better results than training SVMs directly on top of raw pixels.

Number of Bins Validation Accuracy Learning Rate Regularization Strength Test Accuracy
10 0.426000 8.000000e-07 5.000000e+04
50 0.440000 8.000000e-07 5.000000e+04 0.428
50 0.441000 3.000000e-07 1.000000e+05 0.428
100 0.440000 2.000000e-07 8.000000e+04 0.414
150 0.428000 8.000000e-07 2.000000e+04 0.388

lr 3.000000e-07 reg 1.000000e+05 train accuracy: 0.426041 val accuracy: 0.441000


In [4]:
# Use the validation set to tune the learning rate and regularization strength

from cs231n.classifiers.linear_classifier import LinearSVM

learning_rates = [1e-7, 2e-7, 3e-7, 5e-5, 8e-7]
regularization_strengths = [1e4, 2e4, 3e4, 4e4, 5e4, 6e4, 7e4, 8e4, 7e5]

results = {}
best_val = -1
best_svm = None

################################################################################
# TODO:                                                                        #
# Use the validation set to set the learning rate and regularization strength. #
# This should be identical to the validation that you did for the SVM; save    #
# the best trained classifer in best_svm. You might also want to play          #
# with different numbers of bins in the color histogram. If you are careful    #
# you should be able to get accuracy of near 0.44 on the validation set.       #
################################################################################
for lr in learning_rates:
    for rs in regularization_strengths:
        svm = LinearSVM()
        svm.train(X_train_feats, y_train, learning_rate = lr, reg = rs, num_iters = 2000)
        train_accuracy = np.mean(y_train == svm.predict(X_train_feats))
        val_accuracy = np.mean(y_val == svm.predict(X_val_feats))
        results[(lr, rs)] = (train_accuracy, val_accuracy)
        if val_accuracy > best_val:
            best_val = val_accuracy
            best_svm = svm
################################################################################
#                              END OF YOUR CODE                                #
################################################################################

# Print out results.
for lr, reg in sorted(results):
    train_accuracy, val_accuracy = results[(lr, reg)]
    print 'lr %e reg %e train accuracy: %f val accuracy: %f' % (
                lr, reg, train_accuracy, val_accuracy)
    
print 'best validation accuracy achieved during cross-validation: %f' % best_val


cs231n/classifiers/linear_svm.py:95: RuntimeWarning: overflow encountered in double_scalars
  loss += 0.5 * reg * np.sum(W * W)
cs231n/classifiers/linear_svm.py:95: RuntimeWarning: overflow encountered in multiply
  loss += 0.5 * reg * np.sum(W * W)
cs231n/classifiers/linear_svm.py:130: RuntimeWarning: overflow encountered in multiply
  dW += reg*W
cs231n/classifiers/linear_svm.py:84: RuntimeWarning: invalid value encountered in subtract
  margin = scores - correct_class_score[:, None] + 1 # (500, 10)
cs231n/classifiers/linear_svm.py:90: RuntimeWarning: invalid value encountered in less
  margin[margin < 0] = 0
cs231n/classifiers/linear_svm.py:111: RuntimeWarning: invalid value encountered in greater
  binary[binary > 0] = 1 # (500, 10)
lr 1.000000e-07 reg 1.000000e+04 train accuracy: 0.157714 val accuracy: 0.160000
lr 1.000000e-07 reg 2.000000e+04 train accuracy: 0.310367 val accuracy: 0.285000
lr 1.000000e-07 reg 3.000000e+04 train accuracy: 0.409510 val accuracy: 0.411000
lr 1.000000e-07 reg 4.000000e+04 train accuracy: 0.417408 val accuracy: 0.437000
lr 1.000000e-07 reg 5.000000e+04 train accuracy: 0.414959 val accuracy: 0.419000
lr 1.000000e-07 reg 6.000000e+04 train accuracy: 0.415714 val accuracy: 0.417000
lr 1.000000e-07 reg 7.000000e+04 train accuracy: 0.415204 val accuracy: 0.419000
lr 1.000000e-07 reg 8.000000e+04 train accuracy: 0.419388 val accuracy: 0.418000
lr 1.000000e-07 reg 7.000000e+05 train accuracy: 0.414918 val accuracy: 0.421000
lr 2.000000e-07 reg 1.000000e+04 train accuracy: 0.380041 val accuracy: 0.372000
lr 2.000000e-07 reg 2.000000e+04 train accuracy: 0.414469 val accuracy: 0.421000
lr 2.000000e-07 reg 3.000000e+04 train accuracy: 0.416163 val accuracy: 0.414000
lr 2.000000e-07 reg 4.000000e+04 train accuracy: 0.414612 val accuracy: 0.420000
lr 2.000000e-07 reg 5.000000e+04 train accuracy: 0.414082 val accuracy: 0.415000
lr 2.000000e-07 reg 6.000000e+04 train accuracy: 0.416327 val accuracy: 0.419000
lr 2.000000e-07 reg 7.000000e+04 train accuracy: 0.413510 val accuracy: 0.421000
lr 2.000000e-07 reg 8.000000e+04 train accuracy: 0.417673 val accuracy: 0.421000
lr 2.000000e-07 reg 7.000000e+05 train accuracy: 0.403694 val accuracy: 0.413000
lr 3.000000e-07 reg 1.000000e+04 train accuracy: 0.411959 val accuracy: 0.416000
lr 3.000000e-07 reg 2.000000e+04 train accuracy: 0.416061 val accuracy: 0.419000
lr 3.000000e-07 reg 3.000000e+04 train accuracy: 0.413143 val accuracy: 0.417000
lr 3.000000e-07 reg 4.000000e+04 train accuracy: 0.411714 val accuracy: 0.412000
lr 3.000000e-07 reg 5.000000e+04 train accuracy: 0.414898 val accuracy: 0.419000
lr 3.000000e-07 reg 6.000000e+04 train accuracy: 0.416776 val accuracy: 0.425000
lr 3.000000e-07 reg 7.000000e+04 train accuracy: 0.411102 val accuracy: 0.406000
lr 3.000000e-07 reg 8.000000e+04 train accuracy: 0.413367 val accuracy: 0.419000
lr 3.000000e-07 reg 7.000000e+05 train accuracy: 0.388918 val accuracy: 0.374000
lr 8.000000e-07 reg 1.000000e+04 train accuracy: 0.414327 val accuracy: 0.422000
lr 8.000000e-07 reg 2.000000e+04 train accuracy: 0.411531 val accuracy: 0.404000
lr 8.000000e-07 reg 3.000000e+04 train accuracy: 0.409204 val accuracy: 0.416000
lr 8.000000e-07 reg 4.000000e+04 train accuracy: 0.414755 val accuracy: 0.412000
lr 8.000000e-07 reg 5.000000e+04 train accuracy: 0.412204 val accuracy: 0.404000
lr 8.000000e-07 reg 6.000000e+04 train accuracy: 0.409265 val accuracy: 0.408000
lr 8.000000e-07 reg 7.000000e+04 train accuracy: 0.399755 val accuracy: 0.403000
lr 8.000000e-07 reg 8.000000e+04 train accuracy: 0.409837 val accuracy: 0.418000
lr 8.000000e-07 reg 7.000000e+05 train accuracy: 0.364449 val accuracy: 0.344000
lr 5.000000e-05 reg 1.000000e+04 train accuracy: 0.384367 val accuracy: 0.383000
lr 5.000000e-05 reg 2.000000e+04 train accuracy: 0.303000 val accuracy: 0.318000
lr 5.000000e-05 reg 3.000000e+04 train accuracy: 0.257918 val accuracy: 0.289000
lr 5.000000e-05 reg 4.000000e+04 train accuracy: 0.098531 val accuracy: 0.100000
lr 5.000000e-05 reg 5.000000e+04 train accuracy: 0.100265 val accuracy: 0.087000
lr 5.000000e-05 reg 6.000000e+04 train accuracy: 0.100265 val accuracy: 0.087000
lr 5.000000e-05 reg 7.000000e+04 train accuracy: 0.100265 val accuracy: 0.087000
lr 5.000000e-05 reg 8.000000e+04 train accuracy: 0.100265 val accuracy: 0.087000
lr 5.000000e-05 reg 7.000000e+05 train accuracy: 0.100265 val accuracy: 0.087000
best validation accuracy achieved during cross-validation: 0.437000

In [5]:
# Evaluate your trained SVM on the test set
y_test_pred = best_svm.predict(X_test_feats)
test_accuracy = np.mean(y_test == y_test_pred)
print test_accuracy


0.418

In [6]:
# An important way to gain intuition about how an algorithm works is to
# visualize the mistakes that it makes. In this visualization, we show examples
# of images that are misclassified by our current system. The first column
# shows images that our system labeled as "plane" but whose true label is
# something other than "plane".

examples_per_class = 8
classes = ['plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
for cls, cls_name in enumerate(classes):
    idxs = np.where((y_test != cls) & (y_test_pred == cls))[0]
    idxs = np.random.choice(idxs, examples_per_class, replace=False)
    for i, idx in enumerate(idxs):
        plt.subplot(examples_per_class, len(classes), i * len(classes) + cls + 1)
        plt.imshow(X_test[idx].astype('uint8'))
        plt.axis('off')
        if i == 0:
            plt.title(cls_name)
plt.show()


Inline question 1:

Describe the misclassification results that you see. Do they make sense?

Neural Network on image features

Earlier in this assigment we saw that training a two-layer neural network on raw pixels achieved better classification performance than linear classifiers on raw pixels. In this notebook we have seen that linear classifiers on image features outperform linear classifiers on raw pixels.

For completeness, we should also try training a neural network on image features. This approach should outperform all previous approaches: you should easily be able to achieve over 55% classification accuracy on the test set; our best model achieves about 60% classification accuracy.


In [7]:
print X_train_feats.shape


(49000, 155)
Learning Rate Regularization Rate Validation Accuracy Test Accuracy
0.1 0.0001 0.544 0.534
0.1 0.000215443469003 0.544 0.538
0.1 0.000464158883361 0.542 0.534
0.1 0.001 0.537 0.535
0.1 0.00215443469003 0.536 0.533
0.1 0.00464158883361 0.529 0.533
0.1 0.01 0.524 0.522
0.1 0.0215443469003 0.508 0.508
0.1 0.0464158883361 0.51 0.489
0.1 0.1 0.434 0.446
0.215443469003 0.0001 0.594 0.58
0.215443469003 0.000215443469003 0.604 0.578
0.215443469003 0.000464158883361 0.601 0.58
0.215443469003 0.001 0.593 0.586
0.215443469003 0.00215443469003 0.597 0.569
0.215443469003 0.00464158883361 0.579 0.56
0.215443469003 0.01 0.554 0.539
0.215443469003 0.0215443469003 0.515 0.517
0.215443469003 0.0464158883361 0.508 0.491
0.215443469003 0.1 0.441 0.446
0.464158883361 0.0001 0.595 0.599
0.464158883361 0.000215443469003 0.601 0.597
0.464158883361 0.000464158883361 0.594 0.6
0.464158883361 0.001 0.616 0.596
0.464158883361 0.00215443469003 0.609 0.601
0.464158883361 0.00464158883361 0.603 0.575
0.464158883361 0.01 0.573 0.551
0.464158883361 0.0215443469003 0.525 0.517
0.464158883361 0.0464158883361 0.502 0.503
0.464158883361 0.1 0.44 0.447
1.0 0.0001 0.568 0.566
1.0 0.000215443469003 0.588 0.589
1.0 0.000464158883361 0.591 0.571
1.0 0.001 0.61 0.587
1.0 0.00215443469003 0.614 0.603
1.0 0.00464158883361 0.62 0.587
1.0 0.01 0.574 0.557
1.0 0.0215443469003 0.521 0.517
1.0 0.0464158883361 0.498 0.492
1.0 0.1 0.433 0.441
2.15443469003 0.0001 0.547 0.559
2.15443469003 0.000215443469003 0.571 0.564
2.15443469003 0.000464158883361 0.563 0.578
2.15443469003 0.001 0.6 0.592
2.15443469003 0.00215443469003 0.615 0.613
2.15443469003 0.00464158883361 0.611 0.6
2.15443469003 0.01 0.578 0.558
2.15443469003 0.0215443469003 0.525 0.511
2.15443469003 0.0464158883361 0.491 0.485
2.15443469003 0.1 0.449 0.454
4.64158883361 0.0001 0.087 0.103
4.64158883361 0.000215443469003 0.087 0.103
4.64158883361 0.000464158883361 0.087 0.103
4.64158883361 0.001 0.087 0.103
4.64158883361 0.00215443469003 0.087 0.103
4.64158883361 0.00464158883361 0.087 0.103
4.64158883361 0.01 0.087 0.103
4.64158883361 0.0215443469003 0.087 0.103
4.64158883361 0.0464158883361 0.087 0.103
4.64158883361 0.1 0.087 0.103
10.0 0.0001 0.087 0.103
10.0 0.000215443469003 0.087 0.103
10.0 0.000464158883361 0.087 0.103
10.0 0.001 0.087 0.103
10.0 0.00215443469003 0.087 0.103
10.0 0.00464158883361 0.087 0.103
10.0 0.01 0.087 0.103
10.0 0.0215443469003 0.087 0.103
10.0 0.0464158883361 0.087 0.103
10.0 0.1 0.087 0.103
21.5443469003 0.0001 0.087 0.103
21.5443469003 0.000215443469003 0.087 0.103
21.5443469003 0.000464158883361 0.087 0.103
21.5443469003 0.001 0.087 0.103
21.5443469003 0.00215443469003 0.087 0.103
21.5443469003 0.00464158883361 0.087 0.103
21.5443469003 0.01 0.087 0.103
21.5443469003 0.0215443469003 0.087 0.103
21.5443469003 0.0464158883361 0.087 0.103
21.5443469003 0.1 0.087 0.103
46.4158883361 0.0001 0.087 0.103
46.4158883361 0.000215443469003 0.087 0.103
46.4158883361 0.000464158883361 0.087 0.103
46.4158883361 0.001 0.087 0.103
46.4158883361 0.00215443469003 0.087 0.103
46.4158883361 0.00464158883361 0.087 0.103
46.4158883361 0.01 0.087 0.103
46.4158883361 0.0215443469003 0.087 0.103
46.4158883361 0.0464158883361 0.087 0.103
46.4158883361 0.1 0.087 0.103
100.0 0.0001 0.087 0.103
100.0 0.000215443469003 0.087 0.103
100.0 0.000464158883361 0.087 0.103
100.0 0.001 0.087 0.103
100.0 0.00215443469003 0.087 0.103
100.0 0.00464158883361 0.087 0.103
100.0 0.01 0.087 0.103
100.0 0.0215443469003 0.087 0.103
100.0 0.0464158883361 0.087 0.103
100.0 0.1 0.087 0.103

In [8]:
from cs231n.classifiers.neural_net import TwoLayerNet

input_dim = X_train_feats.shape[1]
hidden_dim = 500
num_classes = 10

best_net = None
best_val_acc = 0.0
best_hidden_size = None
best_learning_rate = None
best_regularization_strength = None
################################################################################
# TODO: Train a two-layer neural network on image features. You may want to    #
# cross-validate various parameters as in previous sections. Store your best   #
# model in the best_net variable.                                              #
################################################################################
learning_rates = np.logspace(-1, 2, 10)
regularization_strengths = np.logspace(-4, -1, 10)

print '| Learning Rate| Regularization Rate | Validation Accuracy | Test Accuracy |'
print '| --- | --- | --- | --- |'
for learning_rate in learning_rates:
    for regularization_strength in regularization_strengths:
        net = TwoLayerNet(input_dim, hidden_dim, num_classes)

        # Train the network
        stats = net.train(X_train_feats, y_train, X_val_feats, y_val,
                    num_iters=5000, batch_size=500,
                    learning_rate=learning_rate, learning_rate_decay=0.95,
                    reg=regularization_strength, verbose=False)

        # Predict on the validation set
        val_acc = (net.predict(X_val_feats) == y_val).mean()
        test_acc = (net.predict(X_test_feats) == y_test).mean()
        if best_val_acc < val_acc:
            best_val_acc = val_acc
            best_net = net
            best_learning_rate = learning_rate
            best_regularization_strength = regularization_strength
        print '|', learning_rate, '|', regularization_strength,'|', val_acc,'|',test_acc, '|'
################################################################################
#                              END OF YOUR CODE                                #
################################################################################


| Learning Rate| Regularization Rate | Validation Accuracy | Test Accuracy |
| --- | --- | --- | --- |
| 0.1 | 0.0001 | 0.537 | 0.541 |
| 0.1 | 0.000215443469003 | 0.538 | 0.538 |
| 0.1 | 0.000464158883361 | 0.544 | 0.543 |
| 0.1 | 0.001 | 0.537 | 0.536 |
| 0.1 | 0.00215443469003 | 0.538 | 0.539 |
| 0.1 | 0.00464158883361 | 0.529 | 0.532 |
| 0.1 | 0.01 | 0.525 | 0.525 |
| 0.1 | 0.0215443469003 | 0.515 | 0.514 |
| 0.1 | 0.0464158883361 | 0.503 | 0.488 |
| 0.1 | 0.1 | 0.435 | 0.453 |
| 0.215443469003 | 0.0001 | 0.589 | 0.576 |
| 0.215443469003 | 0.000215443469003 | 0.595 | 0.585 |
| 0.215443469003 | 0.000464158883361 | 0.594 | 0.578 |
| 0.215443469003 | 0.001 | 0.602 | 0.576 |
| 0.215443469003 | 0.00215443469003 | 0.592 | 0.573 |
| 0.215443469003 | 0.00464158883361 | 0.587 | 0.549 |
| 0.215443469003 | 0.01 | 0.55 | 0.54 |
| 0.215443469003 | 0.0215443469003 | 0.515 | 0.512 |
| 0.215443469003 | 0.0464158883361 | 0.502 | 0.497 |
| 0.215443469003 | 0.1 | 0.435 | 0.447 |
| 0.464158883361 | 0.0001 | 0.595 | 0.596 |
| 0.464158883361 | 0.000215443469003 | 0.612 | 0.598 |
| 0.464158883361 | 0.000464158883361 | 0.592 | 0.61 |
| 0.464158883361 | 0.001 | 0.604 | 0.597 |
| 0.464158883361 | 0.00215443469003 | 0.622 | 0.596 |
| 0.464158883361 | 0.00464158883361 | 0.598 | 0.586 |
| 0.464158883361 | 0.01 | 0.575 | 0.545 |
| 0.464158883361 | 0.0215443469003 | 0.514 | 0.508 |
| 0.464158883361 | 0.0464158883361 | 0.502 | 0.487 |
| 0.464158883361 | 0.1 | 0.444 | 0.443 |
| 1.0 | 0.0001 | 0.57 | 0.572 |
| 1.0 | 0.000215443469003 | 0.586 | 0.578 |
| 1.0 | 0.000464158883361 | 0.601 | 0.584 |
| 1.0 | 0.001 | 0.599 | 0.575 |
| 1.0 | 0.00215443469003 | 0.619 | 0.604 |
| 1.0 | 0.00464158883361 | 0.611 | 0.596 |
| 1.0 | 0.01 | 0.583 | 0.556 |
| 1.0 | 0.0215443469003 | 0.526 | 0.51 |
| 1.0 | 0.0464158883361 | 0.509 | 0.488 |
| 1.0 | 0.1 | 0.449 | 0.44 |
| 2.15443469003 | 0.0001 | 0.575 | 0.565 |
| 2.15443469003 | 0.000215443469003 | 0.575 | 0.562 |
| 2.15443469003 | 0.000464158883361 | 0.588 | 0.575 |
| 2.15443469003 | 0.001 | 0.598 | 0.597 |
| 2.15443469003 | 0.00215443469003 | 0.613 | 0.588 |
| 2.15443469003 | 0.00464158883361 | 0.619 | 0.597 |
| 2.15443469003 | 0.01 | 0.578 | 0.547 |
| 2.15443469003 | 0.0215443469003 | 0.527 | 0.515 |
| 2.15443469003 | 0.0464158883361 | 0.494 | 0.497 |
| 2.15443469003 | 0.1 | 0.438 | 0.432 |
cs231n/classifiers/neural_net.py:100: RuntimeWarning: divide by zero encountered in log
  data_loss_per_input = -np.log(probability[np.arange(N), y])
cs231n/classifiers/neural_net.py:99: RuntimeWarning: overflow encountered in exp
  probability = np.exp(scores)/ np.sum(np.exp(scores), axis = 1)[:, None]
cs231n/classifiers/neural_net.py:99: RuntimeWarning: invalid value encountered in divide
  probability = np.exp(scores)/ np.sum(np.exp(scores), axis = 1)[:, None]
cs231n/classifiers/neural_net.py:77: RuntimeWarning: invalid value encountered in greater
  f = lambda x : x * ( x > 0)
cs231n/classifiers/neural_net.py:135: RuntimeWarning: invalid value encountered in greater
  relu_mask = (np.dot(X, W1) + b1 > 0)
cs231n/classifiers/neural_net.py:250: RuntimeWarning: invalid value encountered in greater
  f = lambda x : x * ( x > 0)
| 4.64158883361 | 0.0001 | 0.087 | 0.103 |
| 4.64158883361 | 0.000215443469003 | 0.087 | 0.103 |
| 4.64158883361 | 0.000464158883361 | 0.087 | 0.103 |
| 4.64158883361 | 0.001 | 0.087 | 0.103 |
| 4.64158883361 | 0.00215443469003 | 0.087 | 0.103 |
| 4.64158883361 | 0.00464158883361 | 0.087 | 0.103 |
| 4.64158883361 | 0.01 | 0.087 | 0.103 |
| 4.64158883361 | 0.0215443469003 | 0.087 | 0.103 |
| 4.64158883361 | 0.0464158883361 | 0.087 | 0.103 |
| 4.64158883361 | 0.1 | 0.087 | 0.103 |
| 10.0 | 0.0001 | 0.087 | 0.103 |
| 10.0 | 0.000215443469003 | 0.087 | 0.103 |
| 10.0 | 0.000464158883361 | 0.087 | 0.103 |
| 10.0 | 0.001 | 0.087 | 0.103 |
| 10.0 | 0.00215443469003 | 0.087 | 0.103 |
| 10.0 | 0.00464158883361 | 0.087 | 0.103 |
| 10.0 | 0.01 | 0.087 | 0.103 |
| 10.0 | 0.0215443469003 | 0.087 | 0.103 |
| 10.0 | 0.0464158883361 | 0.087 | 0.103 |
| 10.0 | 0.1 | 0.087 | 0.103 |
| 21.5443469003 | 0.0001 | 0.087 | 0.103 |
| 21.5443469003 | 0.000215443469003 | 0.087 | 0.103 |
| 21.5443469003 | 0.000464158883361 | 0.087 | 0.103 |
| 21.5443469003 | 0.001 | 0.087 | 0.103 |
| 21.5443469003 | 0.00215443469003 | 0.087 | 0.103 |
| 21.5443469003 | 0.00464158883361 | 0.087 | 0.103 |
| 21.5443469003 | 0.01 | 0.087 | 0.103 |
| 21.5443469003 | 0.0215443469003 | 0.087 | 0.103 |
| 21.5443469003 | 0.0464158883361 | 0.087 | 0.103 |
| 21.5443469003 | 0.1 | 0.087 | 0.103 |
| 46.4158883361 | 0.0001 | 0.087 | 0.103 |
| 46.4158883361 | 0.000215443469003 | 0.087 | 0.103 |
| 46.4158883361 | 0.000464158883361 | 0.087 | 0.103 |
| 46.4158883361 | 0.001 | 0.087 | 0.103 |
| 46.4158883361 | 0.00215443469003 | 0.087 | 0.103 |
| 46.4158883361 | 0.00464158883361 | 0.087 | 0.103 |
| 46.4158883361 | 0.01 | 0.087 | 0.103 |
| 46.4158883361 | 0.0215443469003 | 0.087 | 0.103 |
| 46.4158883361 | 0.0464158883361 | 0.087 | 0.103 |
| 46.4158883361 | 0.1 | 0.087 | 0.103 |
| 100.0 | 0.0001 | 0.087 | 0.103 |
| 100.0 | 0.000215443469003 | 0.087 | 0.103 |
| 100.0 | 0.000464158883361 | 0.087 | 0.103 |
| 100.0 | 0.001 | 0.087 | 0.103 |
| 100.0 | 0.00215443469003 | 0.087 | 0.103 |
| 100.0 | 0.00464158883361 | 0.087 | 0.103 |
| 100.0 | 0.01 | 0.087 | 0.103 |
| 100.0 | 0.0215443469003 | 0.087 | 0.103 |
| 100.0 | 0.0464158883361 | 0.087 | 0.103 |
| 100.0 | 0.1 | 0.087 | 0.103 |

In [10]:
# Run your neural net classifier on the test set. You should be able to
# get more than 55% accuracy.

test_acc = (best_net.predict(X_test_feats) == y_test).mean()
print test_acc


0.596

Bonus: Design your own features!

You have seen that simple image features can improve classification performance. So far we have tried HOG and color histograms, but other types of features may be able to achieve even better classification performance.

For bonus points, design and implement a new type of feature and use it for image classification on CIFAR-10. Explain how your feature works and why you expect it to be useful for image classification. Implement it in this notebook, cross-validate any hyperparameters, and compare its performance to the HOG + Color histogram baseline.

Bonus: Do something extra!

Use the material and code we have presented in this assignment to do something interesting. Was there another question we should have asked? Did any cool ideas pop into your head as you were working on the assignment? This is your chance to show off!