Need help with hair-segmentation?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

197 Stars 63 Forks MIT License 33 Commits 2 Opened issues


hair segmentation in mobile device

Services available


Need anything else?

Contributors list

No Data

Hair Segmentation Realtime using Keras

The architecture was inspired by Real-time deep hair matting on mobile devices

Build Status


python 3.6 tensorflow-gpu==1.13.1, opencv-python==, Keras==2.2.4, numpy==1.16.4, scikit-image==0.15.0

install environment in conda:

conda env create -f environment.yml


Download data CelebAMask-HQ and use preprocess in ./data/pre-process-data-CelebAMask-HQ.ipynb to create dataset

Data structure training

├── my-data
│   ├── train
│   │   ├──image
│   │   │   ├── 1.jpg
│   │   │   ├── 2.jpg
│   │   │   ├── 3.jpg
│   │   ├──mask
│   │   │   ├── 1.jpg
│   │   │   ├── 2.jpg
│   │   │   ├── 3.jpg
│   ├── val
│   ├── test

Train model

```shell script python [--datadir PATH_FOLDER] [--batchsize BATCHSIZE] [epochs EPOCHS] [--lr LEARNING_RATE] []

optional arguments: --datadir: path to folder dataset, default ./data --batchsize: batch size training, default 4 --epochs: number of eposchs, default 5 --lr: learning rate, default 1e-4 --imagesize: size image input, default (224, 224) --usepretrained: use pretrained, default false --pathmodel: directory is saved checkpoint, default ./checkpoints --device: device training model, default 0 (GPU:0), 1(GPU:1), -1(CPU)

Evaluate model

shell script

Run pretrain model

```shell script


python ``` You will see the predicted results of test image in test/data


original result

original result

original result

Convert to Tensorflow Lite

  • Convert
    shell script
    # Convert Model to Mobile
    - Show shape model tflite
    shell script
    # Shape input and output shape model tflite 
    ## About Keras

Keras is a minimalist, highly modular neural networks library, written in Python and capable of running on top of either TensorFlow or Theano. It was developed with a focus on enabling fast experimentation. Being able to go from idea to result with the least possible delay is key to doing good research.

Use Keras if you need a deep learning library that:

allows for easy and fast prototyping (through total modularity, minimalism, and extensibility). supports both convolutional networks and recurrent networks, as well as combinations of the two. supports arbitrary connectivity schemes (including multi-input and multi-output training). runs seamlessly on CPU and GPU. Read the documentation

Keras is compatible with: Python 3.6.


  • [x] Implement model using Keras
  • [x] Convert model to Tensorflow Lite
  • [ ] Implement model to Android (


Copyright (c) 2019 Thang Tran Van

Licensed under the MIT License. You may not use this file except in compliance with the License

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.