- 27th Jan 2024
- 15:32 pm
This post provides a solution for Neural Networks assignment to be completed using the Caltech 101 Silhouettes Dataset. Please note that this is a sample solution provided by our Python Tutors on Neural Networks and the Caltech 101 Silhouettes Dataset. They can help you learn the concepts involved and solve your assignment over a call. You can check the below options that you want to choose to get an A grade in your Python Coursework
- Option 1 - To download the complete solution for this assignment free of cost - Please visit our Python Assignment Sample Solution page. The solution is available and posted on our website and is available free of cost for all students. You need to talk to our experts for a customized solution as per your requirements
- Option 2 - Reach out to our Python Tutors to get online tutoring related to this assignment and get your doubts cleared
- Option 3 - You can check the partial question/ solution for this Neural Networks assignment in this blog below
ANN Assignment Question
Assignment Goal – improve precision and recall rates across all classes! - The Caltech 101 dataset (http://www.vision.caltech.edu/Image_Datasets/Caltech101/) contains images of objects from 101 different classes. It is a dataset that has adopted widespread use for evaluating recognition and classification algorithms. In this assignment you will use a modification of this dataset (Caltech 101 silhouettes, https://people.cs.umass.edu/~marlin/data.shtml) to train a neural network classifier to recognise silhouettes as belonging to one of 24 classes (all those from the 101 classes that have more than 80 sample images and excluding class 2 (faces) because it is very like class 3 (also faces)).
You have been given a python script (on moodle) that loads the data and trains a neural network with the binary images using the default ANN parameters. You will see from the classification report that the ANN has a training score of 100% and a test score of 86%. This implies the ANN is overfitting the training data. You are required to try various approaches to increase the test score (and most likely reduce the training score). You should also look at the individual class precision and recall scores in each class. For example class 4 and 82 have particularly poor scores for these important performance indicators. Can you address this?
- Methodology: The approach you take to this assignment should be based in your own independent research and based on questions that you ask me but here are some things that you must try:
- Play around with the parameters of the neural network (in this case it’s a MLP, multi-layer perceptron). Look at the scikit learn documentation on this classifier and the examples and see what the different parameters can do for you.
- Find other features you could use with the ANN, what feature vectors could you use? Maybe the ANN is overfitting because there are too many featues (28x28). What happens if you reduce the image size? Can you use other summary features in the feature vector. These could either replace or augment the image pixels themselves.
For this assignment, you can use OpenCV and Python’s Scikit-learn and Scikit image as you see fit.
Partial Solution for the Assignment
import numpy as np
from sklearn import metrics
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.preprocessing import scale
from scipy.io import loadmat
caltech101 = loadmat('caltech101_silhouettes_28.mat')
X = caltech101['X']
Y = caltech101['Y']
Y = Y.flatten()
unique, counts = np.unique(Y, return_counts=True)
classes = np.isin(Y, unique[(counts > 80) & (unique != 2)])
data = X[classes]
target = Y[classes]
images = np.reshape(data, (len(target), 28, 28))
data = scale(data.astype(float))
X_train, X_test, y_train, y_test, images_train, images_test = train_test_split(data, target, images, test_size=0.25, random_state=42)
# Create the SVM model with an RBF kernel
svm = SVC(kernel='rbf', random_state=42)
# Define the parameter grid for GridSearchCV
param_grid = {'C': [0.1, 1, 10, 100],
'gamma': [0.001, 0.01, 0.1, 1]}
# Perform the grid search with cross-validation
grid_search = GridSearchCV(svm, param_grid, cv=5)
grid_search.fit(X_train, y_train)
# Get the best parameters
best_params = grid_search.best_params_
print("Best parameters: ", best_params)
# Perform the training using the best parameters
svm_best = SVC(kernel='rbf', random_state=42, **best_params)
svm_best.fit(X_train, y_train)
# Start evaluating
print("Training set score: %f" % svm_best.score(X_train, y_train))
print("Test set score: %f" % svm_best.score(X_test, y_test))
About The Author
Meet the author Dr. Amanda Rodriguez. Dr. Rodriguez holds a Ph.D. in Computer Vision and Machine Learning, bringing a wealth of expertise to this comprehensive assignment guide. With a commitment to advancing knowledge in the field, she skillfully navigates the complexities of neural networks and the intricate Caltech 101 Silhouettes Dataset, providing students with a robust learning experience.