Skip to content

Latest commit

 

History

History
 
 

FaceMaskOverlay

Using Facial Landmarks for Overlaying Faces with Medical Masks

This repository contains the code for Using Facial Landmarks for Overlaying Faces with Masks blog post.

Most of the code is based on the HRNet-Facial-Landmark-Detection repository, huge thanks to them.

Quick start

Environment

This code is developed using Python 3.6 and PyTorch 1.0.0 on Ubuntu 16.04 with NVIDIA GPU. Other platforms or GPUs are not fully tested.

Installation

  1. Create virtual environment:

You'll need to install virtualenv package if you don't have it:

pip install virtualenv
virtualenv -p python3.6 venv
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. You will also need the pre-trained weights, which you can take from here HR18-300W.pth:
wget -O HR18-300W.pth https://pscm7q.by.files.1drv.com/y4m1ndEsUHxWtszPoyHY2BQ2Zdvh0-dgYW_5dtTcxX_YFP8p5YYADNSndm3tAj2f-U4aMPMuS6-VyMvWaCYaO2otLab4XWblhouZkbuIgzr3ZGem6A2b1Lm6Kb3WrYQL_m3D2hj8Y3ulD06kXpvsvsoN-YlmXd9NK12snBfQxrgQf7OVXYsP1xWJEZfN_1CKdLPl1xYNaNvCeQik5LiCnmB9g

Run Demo

To run the demo, you need to execute the following command in your terminal:

python3 overlay_with_mask.py --cfg experiments/300w/face_alignment_300w_hrnet_w18.yaml --landmark_model HR18-300W.pth --mask_image masks/anti_covid.png

Try out different masks from the masks folder or use yours, but don't forget to annotate them first.

AI Courses by OpenCV

Want to become an expert in AI? AI Courses by OpenCV is a great place to start.