Face detection in cameras, especially the 'smile' to automatically capture photos was implemented in digital cameras ever since the early 2000s. Owing to the advancements in machine learning, we are now able not just to recognize smiles, but various other expressions to initiate multiple functions in our systems. This project is an exploration detailing the mechanisms used specifically to detect smiles.
Due to the 2-dimensionality of images, it will be humongous to feed each pixel to an input in the training of models. Hence, the principle of convolution is employed to construct a Convoluted Neural Network (CNN) that after reducing the input parameters of an image, it is passed through a fully connected neural network.
The main stages of the algorithm is as follows:
- Pre-process the image to a standard size (28x28 pixels) and color scaling.
- Train the CNN over the dataset.
- Predict the label for the required test set.
The basic layer structure used to construct the CNN is as follows:
Layer | Type | Output Size | Filter |
---|---|---|---|
Input Image | 2-D | 1 x 28 x 28 | |
Convolution | 2-D | 6 x 26 x 26 | 2 x 2, Stride = 1 |
Max Pooling | 2-D | 6 x 13 x 13 | 2 x 2 |
Convolution | 2-D | 16 x 11 x 11 | 2 x 2, Stride = 1 |
Max Pooling | 2-D | 16 x 5 x 5 | 2 x 2 |
Fully Connected-1 | Linear | 120 | |
Fully Connected-2 | Linear | 84 | |
Fully Connected-3 | Linear | 2 |
This project uses the SMILEs data set from Hromada found here
This project uses jupyter notebook to run the file programmed in Python. The installation lines for the libraries which are needed with the above two:
1. pip install numpy
2. pip install pandas
3. pip install matplotlib
4. pip install scikit-learn
5. pip install opencv-python
6. conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia ***
7. pip install imutils
***PyTorch, installation to be followed as per the local system specs here
- Download the dataset and the jupyter notebook locally.
- Update the path to a dataset in the notebook.
- Run through the cells in the notebook in order if you want to train the neural network.
- If only prediction is needed, create a folder with test images tightly cropped to the face (square ratio) and update the folder path.
- Download the model.pt file and update the path
- Run the 'predict' cell to get the prediction.
The Deep Learning with PyTorch playlist on YouTube by John Elder (Codemy.com) provided the necessary knowledge for implementation of the CNN, Hromada for the extensively labeled dataset, and my peers for providing their portraits for the final testing.