GithubHelp home page GithubHelp logo

shi-labs / fcf-inpainting Goto Github PK

View Code? Open in Web Editor NEW
171.0 171.0 13.0 38.51 MB

[WACV 2023] Keys to Better Image Inpainting: Structure and Texture Go Hand in Hand

Home Page: https://praeclarumjj3.github.io/fcf-inpainting/

License: Other

Python 18.54% Shell 0.11% C++ 0.45% Cuda 1.02% Jupyter Notebook 79.88%
fast-fourier-convolution fcfgan image-inpainting pytorch stylegan2

fcf-inpainting's People

Contributors

praeclarumjj3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fcf-inpainting's Issues

New easy to use inpanting method with transformers

Dear reasercher, please also consider checking our newly introduced face inpainting method to address the symmetry problems of general inpainting mehthods by using swin transformer and semantic aware discriminators.
Our proposed method showed better results in terms of fid score and newly proposed metric which focus on the face symmetry compared to some of the state-of-the-art methods including lama.
Our paper is availabe at:
https://www.researchgate.net/publication/366984165_SFI-Swin_Symmetric_Face_Inpainting_with_Swin_Transformer_by_Distinctly_Learning_Face_Components_Distributions

The code also will be published in:
https://github.com/mohammadrezanaderi4/SFI-Swin

pretrain model can't download

hello,it's amazing.Thank you for your sharing.But when I download your pretrain model,it opens a document.Could you please share your pretrain model with Google drive.Thank you. Besides that, my computer has only one GPU, how do I train the network? Can I just modify the parameters of the number of GPUs trained?

question of source code

HI @ningyu1991

thanks for your work, I have a question with source code in training/networks.py line 246. mask is img[:, -1].unsqueeze(1)
in training/training_loop.py img is img=torch.cat([0.5 - mask, erased_img], dim=1) in training/training_loop.py line 262

so I'm a bit confused about this.

Lama Cleaner add FcF model support

Thank you for open-sourcing your code and pre-training model. I maintain an inpainting tool Lama Cleaner that allows anyone to easily use the SOTA inpainting model. If anyone is interested, you can check out the project's repo.

LaMa FcF
texture texture_lama texture_fcf

About How to Train 512 Model

Hi, Author, I trained the 512 models (#17 ) but the model didn't converge until now. Since I only have 4 GPUs, I have to use a batch size of 16 or 8. I tried the lr from 0.0005 to 0.002, and different number of training image (--kimg 25000). But the training is unstable and I cannot get a converged model (i.e., FID score is from high to low and stable). Can you be kind to give some advice to handle this? Thank you very much!

Best,
Mike

trying to export the model for deployment using torch.jit.trace

This project is truly amazing, and I've been trying to export the model for deployment using torch.jit.trace, but I've run into some issues. Could you please help me refine this part of the code? Thank you very much.

RuntimeError:
Could not export Python function call 'BiasActCuda'. Remove calls to Python functions before export. Did you forget to add @script or @script_method annotation? If this is a nn.ModuleList, add it to __constants__:

TypeError: run_G() missing 1 required positional argument: 'c'

Hello, I encountered this error when running train.py.

Traceback (most recent call last): File "train.py", line 523, in <module> main() # pylint: disable=no-value-for-parameter File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/click/core.py", line 1130, in __call__ return self.main(*args, **kwargs) File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/click/core.py", line 1055, in main rv = self.invoke(ctx) File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, **ctx.params) File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/click/core.py", line 760, in invoke return __callback(*args, **kwargs) File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/click/decorators.py", line 26, in new_func return f(get_current_context(), *args, **kwargs) File "train.py", line 516, in main subprocess_fn(rank=0, args=args, temp_dir=temp_dir) File "train.py", line 391, in subprocess_fn training_loop.training_loop(rank=rank, **args) File "/FcF-Inpainting-main/training/training_loop.py", line 327, in training_loop loss.accumulate_gradients(phase=phase.name, erased_img=erased_img, real_img=real_img, mask=mask, real_c=real_c, gen_c=gen_c, sync=sync, gain=gain) File "/FcF-Inpainting-main/training/losses/loss.py", line 65, in accumulate_gradients gen_img, _ = self.run_G(g_inputs, gen_c, sync=sync) # May get synced by Gpl. TypeError: run_G() missing 1 required positional argument: 'c'

The second is that I can't download the place2 dataset through wget.

`(myconda) root@PVGa1O:/FcF-Inpainting-main# wget http://data.csail.mit.edu/places/places365/train_large_places365challenge.tar
--2023-02-28 08:34:03-- http://data.csail.mit.edu/places/places365/train_large_places365challenge.tar
Resolving data.csail.mit.edu (data.csail.mit.edu)... 128.52.129.40
Connecting to data.csail.mit.edu (data.csail.mit.edu)|128.52.129.40|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2023-02-28 08:34:04 ERROR 404: Not Found.

(myconda) root@PVGa1O:/FcF-Inpainting-main# wget http://data.csail.mit.edu/places/places365/val_large.tar
--2023-02-28 08:34:18-- http://data.csail.mit.edu/places/places365/val_large.tar
Resolving data.csail.mit.edu (data.csail.mit.edu)... 128.52.129.40
Connecting to data.csail.mit.edu (data.csail.mit.edu)|128.52.129.40|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2023-02-28 08:34:19 ERROR 404: Not Found.

(myconda) root@PVGa1O:/FcF-Inpainting-main#
`

baseline

Hello author, when you compared other baseline models, did you use the mask generated in this paper and the corresponding data set to retrain the baseline model? Looking forward to your reply!

TypeError: run_G() missing 1 required positional argument: 'c'

When I run
python train.py
--outdir=training-runs-inp
--img_data=/raid/yiptmp/zyfai_docker_project/Palette-Image-to-Image-Diffusion-Models/forInpait_512/train
--gpus 2
--resolution 512
--kimg 25000
--gamma 10
--aug 'noaug'
--metrics True
--eval_img_data=/raid/yiptmp/zyfai_docker_project/Palette-Image-to-Image-Diffusion-Models/forInpait_512/random_val
--batch 64

I got this issue,how can I solve it?Thanks!

Process of high-resolution images

Hello
How are you?
Thanks for contributing to this project.
The Lama model was trained with 256x256 size of image but it is robust for higher resolution images (ex: 2900x1800) by the with refinement process (https://arxiv.org/pdf/2206.13644.pdf).
I'm curious if this FcF method can be applied for high-resolution input as 2900x1800.
If the image resolution is very high as 2900x1800 and the hole mask size is also bigger than 256x256 or 512x512, how can this method be applied to such images?
Is it possible to integrate such a refinement process like in Lama for high resolution image?

can't download CelebA-HQ Dataset

Hello.Thank you for sharing the codes! When I try to download CelebA-HQ Dataset, the link fails. Could you please update the link with Google drive or Baidu drive. Thanks again!
image

how to finetune ?

I use --resume places.pkl to finetune on my own datasets, but the result is not good, even worse than places.pkl,,,,i want to know if should i change the lr or other params?

TypeError: forward() missing 1 required positional argument: 'ws'

When I run train.py, this error occurs. StyleGAN2Loss in loss.py, line 45.

 with misc.ddp_sync(self.G_synthesis, sync):
            img = self.G_synthesis(x_global, feats, ws)

But G_synthesis need four parameters to run forward. There's no parameter mask here.
Did I get something wrong?

训练问题

您好,如果使用自制数据集的话也需要分割掩码吗?这个掩码分割的作用是什么呢?

AttributeError: 'EasyDict' object has no attribute 'mask_generator_kwargs'

Hello, I encountered this error when running bash tools/prepare_places_segm_evaluation.sh

Detectron v2 is not installed
Traceback (most recent call last):
File "tools/gen_random_segm_masks.py", line 123, in
main(aparser.parse_args())
File "tools/gen_random_segm_masks.py", line 103, in main
process_images(in_files, args.indir, args.outdir, config)
File "tools/gen_random_segm_masks.py", line 28, in process_images
mask_generator = SegmentationMask(**config.mask_generator_kwargs)
AttributeError: 'EasyDict' object has no attribute 'mask_generator_kwargs'

About convergence on the celebahq dataset

Hello author! Thanks for your wonderful work! I would like to ask how many epochs of training the model on celebahq can converge when the equipment is limited? I only have one gpu, so the training time is very important for me.
Looking forward to your reply!

ModuleNotFoundError: No module named 'training.augment'

Thanks for your great work,I encountered this problem while training using the '--augpipe=geom' parameter,i need some help about scaling the training images,thanks for your reply.

python train.py --outdir=training-runs-inp
--img_data=datasets/demo/train
--gpus 4
--kimg 2000
--gamma 10
--metrics True
--eval_img_data datasets/demo/evaluation/random_val
--batch 8
--resolution 512
--augpipe geom

ModuleNotFoundError:No module named 'training'

Hello, thank you very much for your contribution. I encountered the following error when I was debugging. When I run the bash tools/prepare_places_val.sh command I get No module named 'training'
2023-05-10 10-32-06 的屏幕截图
Thank you very much for your reply!!!

Inpainting failing for a particular texture

Dear authors,

I tried your Colab demo and ran into a problem. When I tried to inpaint the following image:
texture_dark
with this mask:
texture_dark_mask
I got quite a good result:
texture_dark_inpainted

However, if I just made the input image brighter (multiplied pixel values by 2):
texture_bright
the inpainting (with the same mask) failed:
texture_bright_inpainted

I thought it could be some overflow in the image domain, but when I tried to crop the input image a bit (about 10 % on the top and right side):
texture_bright_crop
the inpainting worked again:
texture_bright_crop_inpaint

Could be some overflow in the frequency domain or am I just doing something wrong? Thank you for your response.

Codes for Loss Function

Hi, this is a great job for inpainting. I am training my own dataset, but I didn't find the codes for the loss function described in the paper. Can you please tell where I can find it? Thank you very much!

SyntaxError: invalid character in identifier

raceback (most recent call last):
  File "train.py", line 523, in <module>
    main() # pylint: disable=no-value-for-parameter
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "train.py", line 516, in main
    subprocess_fn(rank=0, args=args, temp_dir=temp_dir)
  File "train.py", line 391, in subprocess_fn
    training_loop.training_loop(rank=rank, **args)
  File "/content/FcF-Inpainting/training/training_loop.py", line 181, in training_loop
    G = dnnlib.util.construct_class_by_name(**G_kwargs, **common_kwargs).train().requires_grad_(False).to(device) # subclass of torch.nn.Module
  File "/content/FcF-Inpainting/dnnlib/util.py", line 289, in construct_class_by_name
    return call_func_by_name(*args, func_name=class_name, **kwargs)
  File "/content/FcF-Inpainting/dnnlib/util.py", line 282, in call_func_by_name
    func_obj = get_obj_by_name(func_name)
  File "/content/FcF-Inpainting/dnnlib/util.py", line 275, in get_obj_by_name
    module, obj_name = get_module_from_obj_name(name)
  File "/content/FcF-Inpainting/dnnlib/util.py", line 246, in get_module_from_obj_name
    importlib.import_module(module_name) # may raise ImportError
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 724, in exec_module
  File "<frozen importlib._bootstrap_external>", line 860, in get_code
  File "<frozen importlib._bootstrap_external>", line 791, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/content/FcF-Inpainting/training/networks.py", line 1
    # Modified from https://github.com/NVlabs/stylegan2-ada-pytorch
    ^
SyntaxError: invalid character in identifier

Training 512x512 model

Hello
How are you?
Thanks for contributing to this project.
I am going to train a 512x512 model on my own data.
But I met the following issue.

image

I set the resolution parameter to 512 in the script "train.py"

RuntimeError: Output 0 of SliceBackward0 is a view and is being modified inplace.

Thanks for your excellent work, but I have encountered some problems.
I got an error when using multiple GPUs:
Traceback (most recent call last):
File "/anaconda3/envs/pytorch_1.10/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 59, in _wrap fn(i, *args)
File "/nfs/PycharmProjects/FcF-Inpainting/train.py", line 393, in subprocess_fn training_loop.training_loop(rank=rank, **args)
File "/nfs/PycharmProjects/FcF-Inpainting/training/training_loop.py", line 327, in training_loop
loss.accumulate_gradients(phase=phase.name, erased_img=erased_img, real_img=real_img, mask=mask, real_c=real_c, gen_c=gen_c, sync=sync, gain=gain)
File "/nfs/PycharmProjects/FcF-Inpainting/training/losses/loss.py", line 65, in accumulate_gradients gen_img, _ =self.run_G(g_inputs, mask, gen_c, sync=sync) # May get synced by Gpl.
File "/nfs/PycharmProjects/FcF-Inpainting/training/losses/loss.py", line 44, in run_G
ws[:, cutoff:] = self.G_mapping(torch.randn_like(z), c, skip_w_avg_update=True)[:, cutoff:]
RuntimeError: Output 0 of SliceBackward0 is a view and is being modified inplace. This view was created inside a custom Function (or because an input was returned as-is) and the autograd logic to handle view+inplace would override the custom backward associated with the custom Function, leading to incorrect gradients. This behavior is forbidden. You can fix this by cloning the output of the custom Function.
But when I only run on one GPU, everything is fine.
How should I solve it?

Trained with 512x512 Input but not Converged

Hi, authors. I used this repository to train with an input image size of 256x256, it worked very well and can converge when I looked at the FID score. However, after I changed the resolution from 256 to 512 in the corresponding files and keep other hyperparameters remained, I have to reduce the batch size for training (from 64 to 8), but the FID score is up during the training. Can you tell me how to handle this? Thank you very much!

Best,
Mike

about generator

Hello author, I would like to ask if the Fourier Coarse-to-Fine (FcF) Generator generation network is the class Generator in network.py in the traning folder. I want to try to put this generation network into my model. thank you.

training time and infer image's size

Thanks for your amazing work. And I have some questions for your help:

  1. how long time have you trained with celeba-hq?
  2. In paper I see you trained 25M images, and the number of Celebahq is 30000, did this mean that you train the model with 800+ epochs?
  3. Can I change my inference image's size with model trained with 256*256? Do you have any suggestions if my test images have different size?
    Look forward to your favourable reply~

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.