hikerxu's picture
Upload folder using huggingface_hub
483de47 verified

A newer version of the Gradio SDK is available: 5.6.0

Upgrade

LaMa: Resolution-robust Large Mask Inpainting with Fourier Convolutions

:grapes: [Official Project Page]   :apple:[LaMa Cleaner]

We use the highly organized code lama-cleaner to simplify the demo code for users.

Abstract

Modern image inpainting systems, despite the significant progress, often struggle with large missing areas, complex geometric structures, and high-resolution images. We find that one of the main reasons for that is the lack of an ef-fective receptive field in both the inpainting network andthe loss function. To alleviate this issue, we propose anew method called large mask inpainting (LaMa). LaM ais based on: a new inpainting network architecture that uses fast Fourier convolutions, which have the image-widereceptive field a high receptive field perceptual loss; large training masks, which unlocks the potential ofthe first two components. Our inpainting network improves the state-of-the-art across a range of datasets and achieves excellent performance even in challenging scenarios, e.g.completion of periodic structures. Our model generalizes surprisingly well to resolutions that are higher than thoseseen at train time, and achieves this at lower parameter & compute costs than the competitive baselines.

Table of Contents

TODO

  • LaMa Demo with lama-cleaner
  • LaMa with SAM
  • LaMa with GroundingDINO
  • LaMa with Grounded-SAM

Installation

We're using lama-cleaner for this demo, install it as follows:

pip install lama-cleaner

Please refer to lama-cleaner for more details.

Then install Grounded-SAM follows Grounded-SAM Installation for some extension demos.

LaMa Demos

Here we provide the demos for LaMa

LaMa Demo with lama-cleaner

cd playground/LaMa
python lama_inpaint_demo.py

with the highly organized code lama-cleaner, this demo can be done in about 20 lines of code. The result will be saved as lama_inpaint_demo.jpg:

Input Image Mask Inpaint Output

LaMa with SAM

cd playground/LaMa
python sam_lama.py

Tips To make it better for inpaint, we should dilate the mask first to make it a bit larger to cover the whole region (Thanks a lot for Inpaint-Anything and Tao Yu for this)

The original mask and dilated mask are shown as follows:

Mask Dilated Mask

And the inpaint result will be saved as sam_lama_demo.jpg:

Input Image SAM Output Dilated Mask LaMa Inpaint