Exercise:Learning color features with Sparse Autoencoders
Learning color features with Sparse Autoencoders
In this exercise, you will implement a linear decoder (with the sparse autoencoder) to learn features on color images from the STL10 dataset. These features will be used in an later exercise on convolution and pooling for classifying STL10 images.
In the file linear_decoder_exercise.zip we have provided some starter code. You should write your code at the places indicated "YOUR CODE HERE" in the files.
For this exercise, you will need to copy and modify sparseAutoencoderCost.m from the sparse autoencoder exercise.
The following additional files are required for this exercise:
- Sampled 8x8 patches from the STL10 dataset (stl10_patches_100k.zip)
- Starter Code (linear_decoder_exercise.zip)
You will also need:
- sparseAutoencoderCost.m (and related functions) from Exercise:Sparse Autoencoder
If you have not completed the exercise listed above, we strongly suggest you complete it first.
Learning from color image patches
In all the exercises so far, you have been working only with grayscale images. In this exercise, you will get the opportunity to work with RGB color images for the first time.
Conveniently, the fact that an image has three color channels (RGB), rather than a single gray channel, presents little difficulty for the sparse autoencoder. You can just combine the intensities from all the color channels for the pixels into one long vector, as if you were working with a grayscale image with 3x the number of pixels as the original image.
Step 0: Initialization
In this step, we initialize some parameters used in the exercise.
Step 1: Modify your sparse autoencoder to use a linear decoder
Copy sparseAutoencoder.m to the directory for this exercise and rename it to sparseAutoencoderLinear.m. Rename the function sparseAutoencoderCost in the file to sparseAutoencoderLinearCost, and modify it to use a linear decoder. In particular, you should change the cost and gradients returned to reflect the change from a sigmoid to a linear decoder. After making this change, check your gradient to ensure that they are correct.
Step 2: Learn features on small patches
You will now use your sparse autoencoder to learn features on a set of 100 000 small 8x8 patches sampled from the larger 96x96 STL10 images (The STL10 dataset comprises 5000 test and 8000 train 96x96 labelled color images belonging to one of ten classes: airplane, bird, car, cat, deer, dog, horse, monkey, ship, truck).
The code provided in this step trains your sparse autoencoder for 400 iterations with the default parameters initialized in step 0. This should take around 45 minutes. Your sparse autoencoder should learn features which when visualized, look like edges and opponent colors, as in the figure below.
If your parameters are improperly tuned (the default parameters should work), or if your implementation of the autoencoder is buggy, you might get one of the following images instead:
The learned features will be saved to STL10Features.mat, which will be used in the later exercise on convolution and pooling.