git clone https://github.com/shi510/portrait-tf2
cd portrait-tf2
mkdir data
Download Portrait Dataset
See https://github.com/anilsathyan7/Portrait-Segmentation for details.
Extract the downloaded file to data folder.
You have these files.
data/img_uint8.npy
data/msk_uint8.npy
data/test_uint8.npy
data/test_xtrain.npy
data/test_ytrain.npy
This step trains 2 times.
First, It trains a portrait model from scratch.
Second, It do quantization-aware-training (QTA).
Then, It generates an 8-bit integer quantized model (tflite file).
For Linux, export PYTHONPATH=$(pwd)
For Windows, $env:PYTHONPATH=$pwd
python train/main.py
You can find the pretrained file here android_example/portrait/src/main/assets.
Open the android_example with android studio.
Build and Install to your phone.
You can accelerate your model with Qualcomm Hexagon DSP.
See https://www.tensorflow.org/lite/performance/hexagon_delegate.
Download Hexagon libary from the above link.
Then, put that libary to the directory, app\src\main\jniLibs\arm64-v8a.
app/src/main/jniLibs/arm64-v8a/libhexagon_nn_skel.so
app/src/main/jniLibs/arm64-v8a/libhexagon_nn_skel_v65.so
app/src/main/jniLibs/arm64-v8a/libhexagon_nn_skel_v66.so
Rebuild your android project and Install it.