Code Monkey home page Code Monkey logo

partialconv-inpainting-pytorch's Introduction

PartialConv-Inpainting-pytorch

Liu, Guilin, Fitsum A. Reda, Kevin J. Shih, Ting-Chun Wang, Andrew Tao, and Bryan Catanzaro. "Image inpainting for irregular holes using partial convolutions." In Proceedings of the European conference on computer vision (ECCV), pp. 85-100. 2018.

Unofficial implementation of Partial Convolution.


Installation

Clone this repo:

git clone https://github.com/xyfJASON/PartialConv-Inpainting-pytorch.git
cd PartialConv-Inpainting-pytorch

Create and activate a conda environment:

conda create -n partialconv python=3.9
conda activate partialconv

Install dependencies:

pip install -r requirements.txt

The code will use pretrained VGG16, which can be downloaded by:

 wget https://download.pytorch.org/models/vgg16-397923af.pth -o ~/.cache/torch/hub/checkpoints/vgg16-397923af.pth

Notes on masks

Please refer to doc.


Training

accelerate-launch train.py [--finetune] [-c CONFIG] [-e EXP_DIR] [--xxx.yyy zzz ...]
  • This repo uses the 🤗 Accelerate library for multi-GPUs/fp16 supports. Please read the documentation on how to launch the scripts on different platforms.

  • Results (logs, checkpoints, tensorboard, etc.) of each run will be saved to EXP_DIR. If EXP_DIR is not specified, they will be saved to runs/exp-{current time}/.

  • To modify some configuration items without creating a new configuration file, you can pass --key value pairs to the script.

For example, to train the model on CelebA-HQ (256x256) using mask images from a specified directory:

# training
python train.py -c ./configs/celebahq-256-maskdir.yaml
# fine-tuning
python train.py --finetune -c ./configs/celebahq-256-maskdir-finetune.yaml --train.pretrained ./runs/exp-xxx/ckpt/step199999/model.pt

Evaluation

To evaluate L1 Error, PSNR and SSIM:

accelerate-launch evaluate.py -c CONFIG \
                              --model_path MODEL_PATH \
                              [--n_eval N_EVAL] \
                              [--micro_batch MICRO_BATCH]
  • This repo uses the 🤗 Accelerate library for multi-GPUs/fp16 supports. Please read the documentation on how to launch the scripts on different platforms.
  • You can adjust the batch size on each device by --micro_batch MICRO_BATCH.
  • All of the metrics are evaluated on the composited output, i.e., pixels outside the masked area are replaced by the ground-truth.

To calculate Inception Score, please sample images following the next section with argument --for_evaluation, and then use tools like torch-fidelity.


Sampling

accelerate-launch sample.py -c CONFIG \
                            --model_path MODEL_PATH \
                            --n_samples N_SAMPLES \
                            --save_dir SAVE_DIR \
                            [--micro_batch MICRO_BATCH] \
                            [--for_evaluation]
  • This repo uses the 🤗 Accelerate library for multi-GPUs/fp16 supports. Please read the documentation on how to launch the scripts on different platforms.
  • You can adjust the batch size on each device by --micro_batch MICRO_BATCH. The sampling speed depends on your system and larger batch size doesn't necessarily result in faster sampling.

Results

CelebA-HQ (256x256)

Quantitative results:

Evaluated on CelebA-HQ test set (2824 images).

Mask type and ratio L1 PSNR SSIM IScore
irregular (0.01, 0.1] 0.0019 39.2560 0.9840 3.6035 ± 0.0927
irregular (0.1, 0.2] 0.0055 33.0008 0.9558 3.5556 ± 0.1290
irregular (0.2, 0.3] 0.0105 29.5313 0.9184 3.4656 ± 0.1437
irregular (0.3, 0.4] 0.0165 26.9910 0.8774 3.3983 ± 0.1238
irregular (0.4, 0.5] 0.0234 25.0421 0.8335 3.2684 ± 0.0665
irregular (0.5, 0.6] 0.0419 21.5027 0.7514 3.0239 ± 0.1464

Visualization:

The content in the masked area doesn't affect the output, which verifies the effectiveness of partial convolution.

partialconv-inpainting-pytorch's People

Contributors

xyfjason avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.