Installation | Prepare Datasets | Pretrained Models | Train on P3M-10k | Test | Inference
Requirements:
- Python 3.7.7+ with Numpy and scikit-image
- Pytorch (version>=1.7.1)
- Torchvision (version 0.8.2)
-
Clone this repository
git clone https://github.com/ViTAE-Transformer/P3M-Net.git
; -
Go into the repository
cd P3M-Net
; -
Create conda environment and activate
conda create -n p3m python=3.7.7
,conda activate p3m
; -
Install dependencies, install pytorch and torchvision separately if you need
pip install -r requirements.txt
,conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.2 -c pytorch
.
Our code has been tested with Python 3.7.7, Pytorch 1.7.1, Torchvision 0.8.2, CUDA 10.2 on Ubuntu 18.04.
Dataset | Dataset Link |
Dataset Link |
Dataset Release Agreement |
---|---|---|---|
P3M-10k | Link | Link (pw: cied) | Agreement (MIT License) |
- Download the datasets P3M-10k from the above links and unzip to the folders
P3M_DATASET_ROOT_PATH
, set up the configuratures in the filecore/config.py
. Please make sure that you have checked out and agreed to the agreements.
After dataset preparation, the structure of the complete datasets should be like the following.
P3M-10k
├── train
├── blurred_image
├── mask (alpha mattes)
├── fg_blurred
├── bg
├── facemask
├── validation
├── P3M-500-P
├── blurred_image
├── mask
├── trimap
├── facemask
├── P3M-500-NP
├── original_image
├── mask
├── trimap
- If you want to test on RWP Test set, please download the original images and alpha mattes at this link.
After datasets preparation, the structure of the complete datasets should be like the following.
RealWorldPortrait-636
├── image
├── alpha
├── ...
Here we provide the model P3M-Net(ViTAE-S) that is trained on P3M-10k for testing.
Model | Google Drive | Baidu Wangpan(百度网盘) |
---|---|---|
P3M-Net(ViTAE-S) | Link | Link (pw: hxxy) |
Here we provide the pretrained models of all backbones for training.
Model | Google Drive | Baidu Wangpan(百度网盘) |
---|---|---|
pretrained models | Link | Link (pw:gxn9) |
-
Download P3M-10k dataset in root
P3M_DATASET_ROOT_PATH
(set up incore/config.py
); -
Download the pretrained models of all backbones in the previous section, and set up the output folder
REPOSITORY_ROOT_PATH
incore/config.py
. The folder structure should be like the following,
[REPOSITORY_ROOT_PATH]
├── logs
├── models
├── pretrained
├── r34mp_pretrained_imagenet.pth.tar
├── swin_pretrained_epoch_299.pth
├── vitae_pretrained_ckpt.pth.tar
├── trained
-
Set up parameters in
scripts/train.sh
, specify config filecfg
, name for the runnickname
, etc. Run the file:chmod +x scripts/train.sh
./scripts/train.sh
Set up parameters in scripts/test.sh
, specify config file cfg
, name for the run nickname
, etc. Run the file:
`chmod +x scripts/test.sh`
`./scripts/test.sh`
Test using provided model
-
Download provided model on P3M-10k as shown in the previous section, unzip to the folder
models/pretrained/
; -
Download P3M-10k dataset in root
P3M_DATASET_ROOT_PATH
(set up incore/config.py
); -
Setup parameters in
scripts/test_dataset.sh
, choosedataset=P3M10K
, andvalset=P3M_500_NP
orvalset=P3M_500_P
depends on which validation set you want to use, run the file:chmod +x scripts/test_dataset.sh
./scripts/test_dataset.sh
-
The results of the alpha matte will be saved in folder
args.test_result_dir
. Note that there may be some slight differences of the evaluation results with the ones reported in the paper due to some packages versions differences and the testing strategy.
-
Download provided model on P3M-10k as shown in the previous section, unzip to the folder
models/pretrained/
; -
Download RWP dataset in root
RWP_TEST_SET_ROOT_PATH
(set up incore/config.py
). Download link is here; -
Setup parameters in
scripts/test_dataset.sh
, choosedataset=RWP
andvalset=RWP
, run the file:chmod +x scripts/test_dataset.sh
./scripts/test_dataset.sh
-
The results of the alpha matte will be saved in folder
args.test_result_dir
. Note that there may be some slight differences of the evaluation results with the ones reported in the paper due to some packages versions differences and the testing strategy.
-
Download provided model on P3M-10k as shown in the previous section, unzip to the folder
models/pretrained/
; -
Download images in root
SAMPLES_ROOT_PATH/original
(set up in config.py) -
Set up parameters in
scripts/test_samples.sh
, and run the file:chmod +x samples/original/*
chmod +x scripts/test_samples.sh
./scripts/test_samples.sh
-
The results of the alpha matte will be saved in folder
SAMPLES_RESULT_ALPHA_PATH
(set up in config.py). The color results will be saved in folderSAMPLES_RESULT_COLOR_PATH
(set up in config.py). Note that there may be some slight differences of the evaluation results with the ones reported in the paper due to some packages versions differences and the testing strategy.
Here we provide the procedure of testing on sample images by our pretrained P3M-Net(ViTAE-S) model:
-
Setup environment following this instruction page;
-
Insert the path
REPOSITORY_ROOT_PATH
in the filecore/config.py
; -
Download the pretrained P3M-Net(ViTAE-S) model from here (Google Drive | Baidu Wangpan (pw: hxxy))) and unzip to the folder
models/pretrained/
; -
Save your sample images in folder
samples/original/.
; -
Setup parameters in the file
scripts/test_samples.sh
and run by:chmod +x scripts/test_samples.sh
scripts/test_samples.sh
; -
The results of alpha matte and transparent color image will be saved in folder
samples/result_alpha/.
andsamples/result_color/.
.
We show some sample images, the predicted alpha mattes, and their transparent results as below. We use the pretrained P3M-Net(ViTAE-S) model from section P3M-Net and Variants with `RESIZE` test strategy.