This project parses different parts of the face using semantic segmentation. The Machine
learning model used is U-Net.
The experiments folder contains application of semantic segmentation i.e. to change lip
and hair color. Refer Github code
for browser application to do the same using tensorflow.js and opencv.js.
- Clone the project.
- Install packages required.
- Download the data set
- Run the project.
-
Clone project from GitHub.
Change to the directory face_segmentation. -
Install packages
In order to reproduce the code install the packages-
Manually install packages mentioned in requirements.txt file or use the command.
pip install -r requirements.txt
-
Install packages using setup.py file.
python setup.py install
The --user option directs setup.py to install the package in the user site-packages directory for the running Python. Alternatively, you can use the --home or --prefix option to install your package in a different location (where you have the necessary permissions)
-
-
Download the required data set.
The data set that is used in this project CelebAMask-HQ that is available here. -
Run the project.
See Documentation for the code section for further details.
-
Pre processing
This folder contains-
Code to generate mask from the different label definitions given in the dataset and split the data into train, validation and test set. This is present in preprocessing/load_data.py. To execute this code, within the 'preprocessing' folder enter the below command
python load_data.py
-
Augment data. The code is present in preproprocessing/augment_dataset.py.
-
-
Models
This folder contains the model used in this project namely, U-Net -
train.py
Run the code using the below command
python train.py -m <model_name>
For help on available models
python train.py --help
-
test.py
This file helps in visualizing segmentation for a given test image. Usage is as followspython test.py -v <visualization_method>
for help on usage
python app.py --help
-
experiments
This folder contains the code to change the lip and hair color from the segmentation mask obtained.
Below are the results obtained on the test set for the models trained in the project.
NOTE
The results obtained are system specific. Due to different combinations of the neural network cudnn library versions and NVIDIA driver library versions, the results can be slightly different. To the best of my knowledge, upon reproducing the environment, the ballpark number will be close to the results obtained.
Models | Accuracy (%) | mIoU (%) |
---|---|---|
U Net | 93.13 | 60.90 |