In this project, you’ll combine your knowledge of computer vision techniques and deep learning architectures to build a facial keypoint detection system. Facial keypoints include points around the eyes, nose, and mouth on a face and are used in many applications. These applicatoions include: facial tracking, facial pose recognition, facial filters, and emotion recognition. Your completed code should be able to look at any image, detect faces, and predict the locations of facial keypoints on each face; examples of these keypoints are displayed below.
The project will be broken up into a few main parts in three Python notebooks, only Notebooks 2 and 3 (and the models.py
file) will be graded:
Notebook 1 : Loading and Visualizing the Facial Keypoint Data
Notebook 2 : Defining and Training a Convolutional Neural Network (CNN) to Predict Facial Keypoints
Notebook 3 : Facial Keypoint Detection Using Haar Cascades and the Trained CNN from Part 2
All of the starting code and resources you'll need to compete this project are in this Github repository. Before you can get started coding, you'll have to make sure that you have all the libraries and dependencies required to support this project.
Note that this project does not require the use of GPU, so this repo does not include instructions for GPU setup.
- Clone the repository, and navigate to the downloaded folder. This may take a minute or two to clone due to the included image data.
git clone https://github.com/cezannec/P1_Facial_Keypoints.git
cd P1_Facial_Keypoints
-
Create (and activate) a new environment, named
ai
with Python 3.6 and thenumpy
andpandas
packages for data loading and transformation. If prompted to proceed with the install(Proceed [y]/n)
type y.- Linux or Mac:
conda create -n ai python=3.6 numpy pandas source activate ai
- Windows:
conda create --name ai python=3.6 numpy pandas activate ai
At this point your command line should look something like:
(ai) <User>:P1_Facial_Keypoints <user>$
. The(ai)
indicates that your environment has been activated, and you can proceed with further package installations. -
Install PyTorch and torchvision.
- Linux or Mac:
conda install pytorch torchvision -c pytorch
-
Install a few required pip packages, which are specified in the requirements text file (including OpenCV).
pip install -r requirements.txt
All of the data you'll need to train a neural network is in the P1_Facial_Keypoints repo, in the subdirectory data
. In this folder are training and tests set of image/keypoint data, and their respective csv files. This will be further explored in Notebook 1: Loading and Visualizing Data, and you're encouraged to look trough these folders on your own, too.
- Navigate back to the repo. (Also, your source environment should still be activated at this point)
cd
cd P1_Facial_Keypoints
- Open the directory of notebooks, using the below command. You'll see all of the project files appear in your local environment; open the first notebook and follow the instructions.
jupyter notebook
NOTE: While some code has already been implemented to get you started, you will need to implement additional functionality and answer all of the questions included in the notebook. Unless requested, it's suggested that you do not modify code that has already been included.
Your project will be reviewed against the project rubric. Review this rubric thoroughly, and self-evaluate your project before submission. All criteria found in the rubric must meet specifications for you to pass.
When you are ready to submit your project, collect all of your project files -- all executed notebooks, and python files -- and compress them into a single zip archive for upload.
Alternatively, your submission could consist of only the GitHub link to your repository with all of the completed files.
Criteria | Meets Specifications |
---|---|
Define a CNN in models.py . |
Define a convolutional neural network with at least one convolutional layer, i.e. self.conv1 = nn.Conv2d(1, 32, 5). The network should take in a grayscale, square image. |
Criteria | Meets Specifications |
---|---|
Select a loss function and optimizer for training the model. | The loss and optimization functions should be appropriate for keypoint detection, which is a regression problem. |
Criteria | Meets Specifications |
---|---|
Train your model. | Train your CNN after defining its loss and optimization functions. You are encouraged, but not required, to visualize the loss over time/epochs by printing it out occasionally and/or plotting the loss over time. Save your best trained model. |
Criteria | Meets Specifications |
---|---|
All questions about model, training, and loss choices are answered. | After training, all 3 questions in notebook 2 about model architecture, choice of loss function, and choice of batch_size and epoch parameters are answered. |
Criteria | Meets Specifications |
---|---|
Apply a learned convolutional kernel to an image and see its effects. | Your CNN "learns" to recognize features and this step requires that you extract at least one convolutional filter fro the trained model, apply it to an image, and see what effect this filter has on the image. |
Criteria | Meets Specifications |
---|---|
After visualizing a convolution kernel, applied to an image, answer: what do you think it detects? | This answer should be informed by how the filtered image (from the step above) looks. |
Criteria | Meets Specifications |
---|---|
Use a haar cascade face detector to detect faces in a given image. | The submission successfully employs OpenCV's face detection. |
Criteria | Meets Specifications |
---|---|
Turn each detected image of a face into an appropriate input Tensor. | You should transform ay face into a suqare grayscale image and then a Tensor for your model to take it as input. |
Criteria | Meets Specifications |
---|---|
Predict and display the keypoints on each detected face. | After face detection with a Haar cascade and face pre-processing, apply your trained model to each detected face, and display the predicted keypoints on each face in the image. |
For testers:
Please answer the following questions, as I'm aiming to improve and add to this project:
-
How could this project be improved?
-
Where were the instructions most confusing?
-
Would you like the ability to overlay simple graphics on a face -- i.e sunglasses on detected eye keypoints?
-
Would you like to learn how to group faces by pose (facing left/right/etc) using unsupervised clustering like k-means?
Thank you so much for your time!