A shape recogniser with features and a tiny CNN
The problem
Recognise simple shapes (bars, crosses, squares, triangles and circles) drawn at different positions and sizes in small images, first with hand-made features and nearest neighbours, then with a small convolutional network.
Requirements
- Generate at least 200 labelled 12 x 12 images of five shapes with random positions, sizes and noise, split into training and test sets
- Implement a 1-NN baseline on raw pixels and report its test accuracy
- Implement HOG-style orientation-histogram features per cell and classify with k-NN
- Implement the forward pass of a small CNN (convolution, ReLU, max pooling, dense layer) and train it, or train the dense layer on fixed edge kernels
- Report accuracy and a confusion matrix for every method
Technologies
- Python
- k-nearest neighbours
- Gradient-orientation histograms
- Convolutional networks
Step by step
- Write the shape generator and look at a sample of each class as text.
- Build the raw-pixel baseline and record its accuracy.
- Add gradient-orientation features and compare the accuracy with the baseline.
- Build the CNN forward pass and check every output shape by hand.
- Train the CNN (or its final layer) with gradient descent and compare all three methods.
- Study the misclassified images and explain what each method gets wrong.
Expected result
Three working classifiers for the same task, with a comparison that shows why features and convolutions beat raw pixels.
How it is evaluated
- The training and test sets never share images
- Feature-based k-NN beats the raw-pixel baseline on the test set
- The CNN's shapes and parameter counts are checked and documented
- Results are reported with accuracy and a confusion matrix for each method
Ways to improve it
- Add rotated shapes and test which method copes best
- Use bounding-box regression to also locate the shape
- Rebuild the CNN in PyTorch on your own computer and train it fully