Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.




We used a pre-trained Multi-Task Cascaded Convolutional Neural Network (facenet-pytorch MTCNN) and trained a PCA-SVM pipeline to detect faces in images and then classify them to see whether people in those images are wearing masks.

Fall 2020 COMP562 Project at UNC Chapel Hill


We used the Face Mask Detection dataset on Kaggle:


1. Without mask:
Without mask
2. Mask worn incorrectly:
Mask worn incorrectly
3: With mask:
With mask


You will require Python 3 along with the following dependencies installed:

  1. numpy
  2. pandas
  3. os (standard Python library)
  4. re (standard Python library)
  5. xml.etree.ElementTree (standard Python library)
  6. scikit-learn
  7. matplotlib
  8. opencv-python (referred to as cv2 in the code, link is for CPU-only package)
  9. scipy
  10. pickle (standard Python library)
  11. pytorch
  12. facenet-pytorch

You will also require Jupyter Notebook

The application code is in the notebook in the repo's root directory: comp562-face-mask-detector.ipynb

Clone the GitHub repository, and open the notebook using Jupyter Notebook. To use just the app, simply run the last cell in the notebook. We have provided our trained PCA-SVM classifier model as a saved pickle object, face_mask_detect_model.pkl, that will get automatically loaded when you run the last cell, if it is kept in the same directory as the comp562-face-mask-detector.ipynb notebook.

If you would also like to train the model, or see how everything works, go in the order from first cell to last!

Please show your love, and leave a like if this helped!


If the app is classifying wrongly, try facing the camera head-on and move closer to the camera. Make sure light is falling onto your face to illuminate it enough.


  1. The original MTCNN research paper:

  2. Face Mask Detection Dataset on Kaggle:

  3. Working of MTCNN:

  4. How to use MTCNN in facenet-pytorch:

  5. For learning how to code up a PCA-SVM pipeline:

  6. For handling the Face-Mask-Detection dataset and creating the data and labels arrays:


Fall 2020 COMP562 Project at UNC Chapel Hill






No releases published


No packages published