This is the multi-page printable view of this section. Click here to print.
Projects
1 - PA2 - Digit Recogniztion with Neural Networks
Partners
This assignment may be completed individually or in pairs. If you are doing this in pairs, you must notify me at the beginning of the project. My expectation for pairs is that both members are actively involved, and take full responsibility for all aspects of the project. In other words, I expect that you are either sitting or virtually together to work, and not that you are splitting up tasks to be completed separately. If both members of the group are not able to fully explain the code to me, then this does not meet this expectation.
Learning Objectives
After completing this activity, students should be able to:
- Build a simple Neural Network in Keras
- Implement a classifier that codes output in one-hot encoding
- Evaluate different network architectures
- Analyze and plot computational cost versus accuracy
Implementation
You will need to build 2 Keras models: m1_dense.py and m2_dense.py. The two models must use different hyperparameters. The hyperparameters that you should explore are:
- number of nodes
- number of layers
- activitation functions employed
For each model, you will justify the hyperparameters selected and why you think this will perform well. Justification involves generating supportive evidence from running your model (and not speculation). For example, plots of the training/validation loss and/or accuracy comparing the impact of adding nodes and/or layers. Above all, for each model, you must make an argument (with supporting evidence) that you are not overfitting.
Support Files
- keras_model_template.py – Template file for each of your Keras models
- keras_pre.py – A template for your preprocessing class. This function is responsible for recoding and reshaping your data as required for your model. You will need a preprocessing file for each of the 2 models you create (named m1_pre.py, m2_pre.py).
- keras_test_digit_model.py – Unit test program (same as used by Gradescope). Your programs MUST work when called from this program.
- MNIST_X_train.npy – training data stored as a numpy array
- MNIST_y_train.npy – training data labels stored as a numpy array
- MNIST_X_test.npy – test data stored as a numpy array
- MNIST_y_test.npy – test data labels stored as a numpy array
Compare Model Performance on Test Data
Run your two models on the test data and create:
- a single plot that compares their accuracy (call this Plot_1)
- a table (call this Table_1) that shows for each model the:
- number of parameters
- accuracy
Submission
You will need to submit the following files to gradescope:
- for your best performing model, save an h5 model file and name it cs445_mnist_dense_best.h5. You will need to include the pre-processing model with it (named cs445_mnist_dense_best_pre.py).
- the source code for both models (m1_dense.py, m1_pre.py, m2_dense.py, m2_pre.py)
- a PDF (named cs445_mnist_dense_summary.pdf )which contains
- Plot_1
- Table_1
- Description of each model (w/hyperparameters) and justification for this model
Grading
Project Part | Weight |
---|---|
Overall Readability/Style | 10% |
Dense Model 1 | 30% |
Dense Model 2 | 30% |
Compare/Contrast Models | 25% |
Model Performance/Scoreboard | 5% |
2 - PA3 - Digit Recogniztion with Convolutional Neural Networks
Partners
This assignment may be completed individually or in pairs. If you are doing this in pairs, you must notify me at the beginning of the project. My expectation for pairs is that both members are actively involved, and take full responsibility for all aspects of the project. In other words, I expect that you are either sitting or virtually together to work, and not that you are splitting up tasks to be completed separately. If both members of the group are not able to fully explain the code to me, then this does not meet this expectation.
Learning Objectives
After completing this activity, students should be able to:
- Build a NN that utilizes both convolution and dense layers
- Implement a classifier that codes output in one-hot encoding
- Evaluate different network architectures
- Analyze and plot computational cost versus accuracy
Implementation
You will need to build 2 Keras models: m3_cnn.py and m4_cnn.py. Both models must utlize convolution and one should include image augmentation. Examples of both of these techniques are provided in the lecture slides.
The two models must use different hyperparameters. The hyperparameters that you should explore are:
- number of convolutional kernels, including varying their size and number
- number of convolutional layers
- number of maxpool layers and dropout layers between convolutional layers
- the effects of adding image segmentation to reduce overfitting
- number of nodes in the dense
- activitation functions employed
For each model, you will justify the hyperparameters selected and why you think this will perform well. Justification involves generating supportive evidence from running your model (and not speculation). For example, plots of the training/validation loss and/or accuracy comparing the impact of adding nodes and/or layers. Above all, for each model, you must make an argument (with supporting evidence) that you are not overfitting.
Support Files
- keras_pre.py – A template for your preprocessing class. This function is responsible for recoding and reshaping your data as required for your model. You will need a preprocessing file for each of the 2 models you create (named m3_pre.py, m4_pre.py).
- keras_test_digit_model.py – Unit test program (same as used by Gradescope). Your programs MUST work when called from this program.
- MNIST_X_train.npy – training data stored as a numpy array
- MNIST_y_train.npy – training data labels stored as a numpy array
- MNIST_X_test.npy – test data stored as a numpy array
- MNIST_y_test.npy – test data labels stored as a numpy array
Compare Model Performance on Test Data
Run your two models on the test data and create:
- a single plot that compares their accuracies (call this Plot_1)
- a table (call this Table_1) that shows for each model the:
- number of parameters
- number of dropout layers
- number of maxpooling layers
- a flag indicating if image augmentation was utilized
- accuracy
Submission
You will need to submit the following files to gradescope:
- for your best performing model, save an h5 model file and name it cs445_mnist_cnn_best.h5. You will need to include the pre-processing model with it (named appropriately).
- the source code for both models and both preprocessing files (m3_cnn.py, m3_pre.py, m4_cnn.py, m4_pre.py)
- a PDF which contains
- Plot_1
- Table_1
- Description of each model (w/hyperparameters) and justification for this model
Grading
Project Part | Weight |
---|---|
Overall Readability/Style | 10% |
CNN Model 3 | 30% |
CNN Model 4 | 30% |
Compare/Contrast Models | 25% |
Model Performance/Scoreboard | 5% |
3 - PA4 KMeans - Image Color Reduction
Learning Objectives
This is an individual assignment. After completing this activity, students should be able to:
- utilize K-Means to perform image compression
- utilize the silhouette measure to evaluate cluster quality
- utilize entropy to perforn an external measure of cluster quality
Introduction
K-Means is arguably the most utilized clustering algorithin in data science. In this assignment, you will utilize K-Means in a somewhat unconventional setting, which is to perform image compression.
Clustering Colors
Images are represented with bitmaps, where each pixel has 3 integer values (red, green, blue). The domain of each integer is 0-255. While much faster algorithms exist for performing image compression, in this assignment you will utilize K-Means to do this. The main concept here is that you will be projecting each pixel’s color coordinates into a 3-D space. This embedding projects colors that are similar to each other as neighbors within this space. The goal of this assignment is reduce the number of colors that are utilized in an image. This will be accomplished by clustering the color points and then replacing the colors in the image with the centroid from their assigned cluster.
Compress the Color Space
Utilize k-means (you can use the Scikit-learn methods) on 3 images (2 of mine and 1 of your own (call this image_3). For your own image, make sure the image size is not too large (you can reduce the number of pixels in your image by using Mac’s Preview or by using MS Window’s Paint (although I have not used this utility). You can download this starter code which will accepts an image file path and a value of k on the command line. The starter code reads the image into an array and reshapes it for you. For image_1 and image_3, perform the following:
- Perform clustering with the following values of k: 2, 5, 20. Make sure your k-means object sets the init parameter to random and sets n_init to 1. Replace the colors in the picture with the cluster centroid values and save the image.
- For each image produced above (the 3 plus the original), plot these images in a PDF for submission. Clearly label which k value is used for each image.
- Run K-Means 10 times for k = 15. Plot the RSS value (inertia) for each of these runs. Briefly explain why these values vary from run to run.
For image_2, perform clustering with k=2 and k=3. Include the PDF these 3 images (original,results form k=2 and results from k=3). Answer the following question(s) in your PDF writeup:
- When k=2, are the original colors found in the image? Explain what happen in this case.
- Do you think this picture was created via a photograph or computer generated. Justify your answer with 1 or 2 sentences.
Computing the Silhouette
Information on the silhouette can be found in the class slides, Wikipedia, or the textbook (section 7.5.2, the last subsection entitled The Silhouette Coefficient). Using your own code (and not scikit-learn), compute the silhouette coefficient. Since this process involves a lot of distance computations, you can compute the distance matrix using the pairwise_distances method in the sklearns.metric module. Here is a short example:
from sklearn.metrics import pairwise_distances
dist = pairwise_distances(X, metric='euclidean')
Use numpy functions for computing the min and mean values to speed up your code. Because the distance matrix can be quite large for high resolution photos, you only need to compute the silhouette on the PennySmallerPhoto.jpg photo. For this section, reduce the colors in the PennySmallerPhoto.jpg photo as before using k=2, k=5, k=10, and k=25. For each clustsering, compute the mean silhouette coefficient for each value of k and construct either a table and plot of these values (k on the x-axis, mean silhouette coefficient on the y axis).
Rubric
Support Files
- imgCompKMeans.py – Starter file for coding
- image_1.jpg – image 1
- image_2.jpg – image 2
- PennySmallerPhoto.jpg – Penny image
Submission
Submit the following to Gradescope.
- imgCompKMeans.py (make sure your name is in the FILE). This file should include an option -sil for computing the silhouette.
- cs445_kmeansimg_summary.pdf a PDF containins the items int he rubrics (RSS Plot, Image results, 2 questions answered from the bottom of the Compress color space section)
Grading
Item | Description | Points |
---|---|---|
RSS Plot | Report contains RSS Plot for image_1 and image_2 and comments on the variance between the 10 runs of K-means. | 25% |
Image Results | The original image and the resulting image from the color compression for each value of k are shown for all 3 images (the two I supplied and yours). | 20% |
Image 2 Questions | The two questions are answered in the PDF | 15% |
Silhouette Code | Code computes the mean silhouette correctly. PDF contains images the color reduced output from the PennySmallerPhoto.jpg photo and the mean silhouette coefficients in a table and a plot. | 40% |