Git Product home page Git Product logo

panini's Introduction

Panini-Net: GAN Prior based Degradation-Aware Feature Interpolation for Face Restoration

This repository is for Panini-Net introduced in the following paper

Yinhuai Wang, Yujie Hu, Jian Zhang, "Panini-Net: GAN Prior based Degradation-Aware Feature Interpolation for Face Restoration", AAAI 2022, [arxiv]

Colab Demo for Panini-Net Face Restoration & Super Resolution! google colab logo.

Face Restoration

Face Super-Resolution

Introduction

Emerging high-quality face restoration (FR) methods often utilize pre-trained GAN models (i.e., StyleGAN2) as GAN Prior. However, these methods usually struggle to balance realness and fidelity when facing various degradation levels. Besides, there is still a noticeable visual quality gap compared with pre-trained GAN models. In this paper, we propose a novel GAN Prior based degradation-aware feature interpolation network, dubbed Panini-Net, for FR tasks by explicitly learning the abstract representations to distinguish various degradations. Specifically, an unsupervised degradation representation learning (UDRL) strategy is first developed to extract degradation representations (DR) of the input degraded images. Then, a degradation-aware feature interpolation (DAFI) module is proposed to dynamically fuse the two types of informative features (i.e., features from input images and features from GAN Prior) with flexible adaption to various degradations based on DR. Ablation studies reveal the working mechanism of DAFI and its potential for editable FR. Extensive experiments demonstrate that our Panini-Net achieves state-of-the-art performance for multi-degradation face restoration and face super-resolution.

Figure: Overview of Panini-Net

Installation

Clone this repository:

git clone https://github.com/jianzhangcs/panini.git
cd panini

This code is based on MMEditing. Please refer to install.md to install dependencies.

Dataset

This code uses FFHQ for training and CelebA-HQ for testing.

After downloading and degenerating the datasets, we put the datasets into data/

Test Using Pre-trained Models

Download our pre-trained model (moco, panini_mfr, panini_16xsr) and put them into checkpoint/

You can use scripts in file test_script.sh to test.

Note: This work does not focus on real world degradation, but studies how to adapt to multiple degradation, which is currently artificially designed, and the parameters are not fine-tuned specifically for real world degradation, so our generalization performance on real world degradation is poor. If you want to reproduce the results of the paper, you can use the test examples we provide or use our degrade function to generate the test images.

Test a single image

python demo/restoration_single_face_demo.py --config configs/panini_mfr.py --checkpoint checkpoint/panini_mfr_latest.pth --img_path examples/MFR/00001.png --save_path examples/MFR_result/00001.png

python demo/restoration_single_face_demo.py --config configs/panini_sr.py --checkpoint checkpoint/panini_sr_latest.pth --img_path examples/SR/00001.png --save_path examples/SR_result/00001.png

Test a directory with images

python demo/restoration_dir_face_demo.py --config configs/panini_mfr.py --checkpoint checkpoint/panini_mfr_latest.pth --img_path examples/MFR --save_path examples/MFR_result

python demo/restoration_dir_face_demo.py --config configs/panini_sr.py --checkpoint my_project/panini_sr/latest.pth --img_path examples/SR --save_path examples/SR_result

Train Moco

You can use scripts in file 'moco/train.sh' to train.

python main_moco.py --lr 0.03 --batch-size 32 --dist-url 'tcp://localhost:10001' --multiprocessing-distributed --world-size 1 --rank 0 --epochs 200

Train Panini-Net

You can use scripts in file train_script.sh to train/test.

Train with a single GPU

python tools/train.py configs/panini_mfr.py --work-dir my_project/panini_mfr

python tools/train.py configs/panini_sr.py --work-dir my_project/panini_sr

Resume from a previous checkpoint file

python tools/train.py configs/panini_mfr.py --work-dir my_project/panini_mfr --resume-from my_project/panini_mfr/latest.pth

python tools/train.py configs/panini_sr.py --work-dir my_project/panini_sr --resume-from my_project/panini_sr/latest.pth

Train with multiple GPUs

python -m torch.distributed.launch --nproc_per_node=2 tools/train.py configs/panini_mfr.py --work-dir my_project/panini_mfr --launcher pytorch

python -m torch.distributed.launch --nproc_per_node=2 tools/train.py configs/panini_sr.py --work-dir my_project/panini_sr --launcher pytorch

Citation

If our work is useful for your research, please consider citing:

@inproceedings{wang2022panini,
	title={Panini-Net: GAN Prior Based Degradation-Aware Feature Interpolation for Face Restoration},
	author={Wang, Yinhuai and Hu, Yujie and Zhang, Jian},
	booktitle={Proceedings of the AAAI Conference on Artificial Intelligence (AAAI)},
	year={2022}
}

Acknowledgments

This code borrows heavily from MMEditing.

panini's People

Contributors

geevegeorge avatar jianzhangcs 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

panini's Issues

Install.md is not found?

Please check the Install.md, install.md is not found or what could I do to install dependencies?

colab error in sr

!python demo/restoration_single_face_demo.py --config configs/panini_sr.py --checkpoint checkpoint/panini_sr_latest.pth --img_path /content/panini/examples/SR_result/00001.png --save_path examples/SR_result/result.png

load checkpoint from http path: http://download.openmmlab.com/mmgen/stylegan2/official_weights/stylegan2-ffhq-config-f-official_20210327_171224-bce9310c.pth
2022-04-26 05:22:09,092 - mmedit - INFO - Load pretrained model from http://download.openmmlab.com/mmgen/stylegan2/official_weights/stylegan2-ffhq-config-f-official_20210327_171224-bce9310c.pth
0
1
2
3
load checkpoint from http path: http://download.openmmlab.com/mmgen/stylegan2/official_weights/stylegan2-ffhq-config-f-official_20210327_171224-bce9310c.pth
2022-04-26 05:22:10,933 - mmedit - INFO - Load pretrained model from http://download.openmmlab.com/mmgen/stylegan2/official_weights/stylegan2-ffhq-config-f-official_20210327_171224-bce9310c.pth
2022-04-26 05:22:13,327 - mmedit - INFO - load checkpoint from torchvision path: torchvision://vgg16
load checkpoint from local path: checkpoint/panini_sr_latest.pth
Traceback (most recent call last):
File "demo/restoration_single_face_demo.py", line 65, in
main()
File "demo/restoration_single_face_demo.py", line 48, in main
args.config, args.checkpoint, device=torch.device('cuda', args.device))
File "./mmedit/apis/train.py", line 45, in init_model
checkpoint = load_checkpoint(model, checkpoint)
File "/usr/local/lib/python3.7/dist-packages/mmcv/runner/checkpoint.py", line 581, in load_checkpoint
checkpoint = _load_checkpoint(filename, map_location, logger)
File "/usr/local/lib/python3.7/dist-packages/mmcv/runner/checkpoint.py", line 520, in _load_checkpoint
return CheckpointLoader.load_checkpoint(filename, map_location, logger)
File "/usr/local/lib/python3.7/dist-packages/mmcv/runner/checkpoint.py", line 285, in load_checkpoint
return checkpoint_loader(filename, map_location)
File "/usr/local/lib/python3.7/dist-packages/mmcv/runner/checkpoint.py", line 302, in load_from_local
checkpoint = torch.load(filename, map_location=map_location)
File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 713, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 920, in _legacy_load
magic_number = pickle_module.load(f, **pickle_load_args)
EOFError: Ran out of input

KeyError: "GLEAN: 'Panini_MFR is not in the model registry'"`

Getting the following error , after executing :

!python demo/restoration_single_face_demo.py --config configs/panini_mfr.py --checkpoint checkpoint/panini_mfr_latest.pth --img_path examples/MFR/00001.png --save_path examples/MFR_result/00001.png
ERROR LOG

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/mmcv/utils/registry.py", line 52, in build_from_cfg
    return obj_cls(**args)
  File "/content/mmediting/mmedit/models/restorers/srgan.py", line 51, in __init__
    self.generator = build_backbone(generator)
  File "/content/mmediting/mmedit/models/builder.py", line 31, in build_backbone
    return build(cfg, BACKBONES)
  File "/content/mmediting/mmedit/models/builder.py", line 22, in build
    return build_from_cfg(cfg, registry, default_args)
  File "/usr/local/lib/python3.7/dist-packages/mmcv/utils/registry.py", line 45, in build_from_cfg
    f'{obj_type} is not in the {registry.name} registry')
KeyError: 'Panini_MFR is not in the model registry'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "demo/restoration_single_face_demo.py", line 65, in <module>
    main()
  File "demo/restoration_single_face_demo.py", line 48, in main
    args.config, args.checkpoint, device=torch.device('cuda', args.device))
  File "/content/mmediting/mmedit/apis/matting_inference.py", line 31, in init_model
    model = build_model(config.model, test_cfg=config.test_cfg)
  File "/content/mmediting/mmedit/models/builder.py", line 60, in build_model
    return build(cfg, MODELS, dict(train_cfg=train_cfg, test_cfg=test_cfg))
  File "/content/mmediting/mmedit/models/builder.py", line 22, in build
    return build_from_cfg(cfg, registry, default_args)
  File "/usr/local/lib/python3.7/dist-packages/mmcv/utils/registry.py", line 55, in build_from_cfg
    raise type(e)(f'{obj_cls.__name__}: {e}')
KeyError: "GLEAN: 'Panini_MFR is not in the model registry'"

How can this be fixed?

How to test my own images?

Hello! Great job, amazing results! I have a question or even a request - please make it possible to make demo with ability to use own images - as I understand it - crop face, restore cropped face and paste it back. Unfortunately I don't have enough knowledge to implement it myself. Thanks!

Data directories are missing for training Moco, and supplemental materials.

Dear Authors,

First of all I want to thank you for presenting this great work along with public codes. It really inspires the following work. And I have encountered some small problems during running the codes myself. It would be a great help if you could offer some tips about them.

First, while trying to re-train Moco, it reports that the data folder 'moco/ffhq_deg_q' and 'moco/ffhq_deg_k' are missing. Could you please provide some instructions on how these folders are generated? In the paper it looks that the paired positive data are generated during training for each iteration, yet in the codes it seems to be pre-generated.

Second, the paper mentions there are supplemental materials, and could you please leave a link for downloading them?

Thanks for your time, and looking forward to your reply!

Best Regards,
Fangzhou

testing your model made bad quality images.

Thank you for giving us expressive your work.

When i tried your code on colab, output image quality is not so good.

Is there anything i have to do for getting good quality?

input and output are like below.
input(SR model)
a0004038_main____
output(SR model)
20a18724-abaa-40c6-8b6f-0092ccdbf563

input(MFR model)
2a1bef3d-2faa-42a0-ae8a-a7a00f9b7d6b
output(MFR model)
190790d6-e4de-4963-a5d9-adfe486d9143

GLEAN: 'Panini_MFR is not in the model registry'

Thanks for your great work.
Here I got a KeyError: GLEAN: 'Panini_MFR is not in the model registry'
I have already installed the requirements.
Actually, there is no problem I used it before. I have no idea what's going on.
Looking forward to your answer.
Thanks.

Welcome update to OpenMMLab 2.0

Welcome update to OpenMMLab 2.0

I am Vansin, the technical operator of OpenMMLab. In September of last year, we announced the release of OpenMMLab 2.0 at the World Artificial Intelligence Conference in Shanghai. We invite you to upgrade your algorithm library to OpenMMLab 2.0 using MMEngine, which can be used for both research and commercial purposes. If you have any questions, please feel free to join us on the OpenMMLab Discord at https://discord.gg/amFNsyUBvm or add me on WeChat (van-sin) and I will invite you to the OpenMMLab WeChat group.

Here are the OpenMMLab 2.0 repos branches:

OpenMMLab 1.0 branch OpenMMLab 2.0 branch
MMEngine 0.x
MMCV 1.x 2.x
MMDetection 0.x 、1.x、2.x 3.x
MMAction2 0.x 1.x
MMClassification 0.x 1.x
MMSegmentation 0.x 1.x
MMDetection3D 0.x 1.x
MMEditing 0.x 1.x
MMPose 0.x 1.x
MMDeploy 0.x 1.x
MMTracking 0.x 1.x
MMOCR 0.x 1.x
MMRazor 0.x 1.x
MMSelfSup 0.x 1.x
MMRotate 1.x 1.x
MMYOLO 0.x

Attention: please create a new virtual environment for OpenMMLab 2.0.

512in, 512out

Can we train models with input and output values of 512

ImportError: /usr/local/lib/python3.7/dist-packages/mmcv/_ext.cpython-37m-x86_64-linux-gnu.so

I am getting this error in
google colab

Traceback (most recent call last):
  File "demo/restoration_single_face_demo.py", line 12, in <module>
    from mmedit.apis import init_model, restoration_inference
  File "./mmedit/apis/__init__.py", line 5, in <module>
    from .train import init_random_seed, set_random_seed, train_model, init_model
  File "./mmedit/apis/train.py", line 21, in <module>
    from mmedit.models import build_model
  File "./mmedit/models/__init__.py", line 7, in <module>
    from .components import *  # noqa: F401, F403
  File "./mmedit/models/components/__init__.py", line 3, in <module>
    from .stylegan2 import StyleGAN2Discriminator, StyleGANv2Generator
  File "./mmedit/models/components/stylegan2/__init__.py", line 2, in <module>
    from .generator_discriminator import (StyleGAN2Discriminator,
  File "./mmedit/models/components/stylegan2/generator_discriminator.py", line 12, in <module>
    from .modules import (ConstantInput, ConvDownLayer, EqualLinearActModule,
  File "./mmedit/models/components/stylegan2/modules.py", line 13, in <module>
    from mmcv.ops.fused_bias_leakyrelu import (FusedBiasLeakyReLU,
  File "/usr/local/lib/python3.7/dist-packages/mmcv/ops/__init__.py", line 2, in <module>
    from .active_rotated_filter import active_rotated_filter
  File "/usr/local/lib/python3.7/dist-packages/mmcv/ops/active_rotated_filter.py", line 10, in <module>
    ['active_rotated_filter_forward', 'active_rotated_filter_backward'])
  File "/usr/local/lib/python3.7/dist-packages/mmcv/utils/ext_loader.py", line 13, in load_ext
    ext = importlib.import_module('mmcv.' + name)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: /usr/local/lib/python3.7/dist-packages/mmcv/_ext.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZNK3c1010TensorImpl36is_contiguous_nondefault_policy_implENS_12MemoryFormatE

how to fix this

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.