Actually I didn't touch the training part. I only create a new prediction function.
The original prediction functions have some problem to run:
demo.py depends on a lot of external data, which is actually not necessary.
test.py uses a discarded model, which is different from the final one.
The new prediction function only needs the model design and the pretrained model data. You don't need to train the model to test it.
After you install all dependencies, say Numpy, Tensorflow, Keras, OpenCV.
-
Download pre-trained Deep Image Matting Model to "models" folder
-
Run the prediction function
$ python test-new.py -i "test/image.png" -b "test/background.png"
I have put 2 images there. You may replace it at your will.
I used to think to port the prediction function to web by using Tensorflow.js or Keras.js. But I found it was hard to do so for the model used some custom layers, which are not supported by Tensorflow.js or Keras.js. Also, the pretrained model file is bigger than 300M.
If anyone finds a way to do so, please let me know.
At first, the model supports photos with a fixed size only. Secondly, as an amature photographer, I tested some photos and foud the results are not always good. I prefer to use commercial photo tools, such as Photoshop, to do manually.
I am afraid I don't think so, especially for professional photographers. Later, maybe 3D camera will be a revolutionary technology to solve this problem.
=================================== The following are original readme of foamliu/Deep-Image-Matting.
This repository is to reproduce Deep Image Matting.
Follow the instruction to contact author for the dataset.
Go to MSCOCO to download:
Go to PASCAL VOC to download:
- VOC challenge 2007 training/validation data
Download VGG16 into models folder.
Extract training images:
$ python pre-process.py
$ python train.py
If you want to visualize during training, run in your terminal:
$ tensorboard --logdir path_to_current_dir/logs
Download pre-trained Deep Image Matting Model to "models" folder then run:
$ python demo.py
Image/Trimap | Output/GT | New BG/Compose |
---|---|---|