Giter Club home page Giter Club logo

restoreformer's Introduction

Updating

  • 20230915 Update an online demo Huggingface Gradio
  • 20230915 A more user-friendly and comprehensive inference method refer to our RestoreFormer++
  • 20230116 For convenience, we further upload the test datasets, including CelebA (both HQ and LQ data), LFW-Test, CelebChild-Test, and Webphoto-Test, to OneDrive and BaiduYun.
  • 20221003 We provide the link of the test datasets.
  • 20220924 We add the code for metrics in scripts/metrics.

RestoreFormer

This repo includes the source code of the paper: "RestoreFormer: High-Quality Blind Face Restoration from Undegraded Key-Value Pairs" (CVPR 2022) by Zhouxia Wang, Jiawei Zhang, Runjian Chen, Wenping Wang, and Ping Luo.

RestoreFormer tends to explore fully-spatial attentions to model contextual information and surpasses existing works that use local operators. It has several benefits compared to prior arts. First, it incorporates a multi-head coross-attention layer to learn fully-spatial interations between corrupted queries and high-quality key-value pairs. Second, the key-value pairs in RestoreFormer are sampled from a reconstruction-oriented high-quality dictionary, whose elements are rich in high-quality facial features specifically aimed for face reconstruction.

Environment

  • python>=3.7
  • pytorch>=1.7.1
  • pytorch-lightning==1.0.8
  • omegaconf==2.0.0
  • basicsr==1.3.3.4

Warning Different versions of pytorch-lightning and omegaconf may lead to errors or different results.

Preparations of dataset and models

Dataset:

  • Training data: Both HQ Dictionary and RestoreFormer in our work are trained with FFHQ which attained from FFHQ repository. The original size of the images in FFHQ are 1024x1024. We resize them to 512x512 with bilinear interpolation in our work. Link this dataset to ./data/FFHQ/image512x512.
  • Test data:

Model: Both pretrained models used for training and the trained model of our RestoreFormer can be attained from OneDrive or BaiduYun(code x6nn). Link these models to ./experiments.

Test

sh scripts/test.sh

Training

sh scripts/run.sh

Note.

  • The first stage is to attain HQ Dictionary by setting conf_name in scripts/run.sh to 'HQ_Dictionary'.
  • The second stage is blind face restoration. You need to add your trained HQ_Dictionary model to ckpt_path in config/RestoreFormer.yaml and set conf_name in scripts/run.sh to 'RestoreFormer'.
  • Our model is trained with 4 V100 GPUs.
sh scripts/metrics/run.sh

Note.

  • You need to add the path of CelebA-Test dataset in the script if you want get IDD, PSRN, SSIM, LIPIS.

Citation

@article{wang2022restoreformer,
  title={RestoreFormer: High-Quality Blind Face Restoration from Undegraded Key-Value Pairs},
  author={Wang, Zhouxia and Zhang, Jiawei and Chen, Runjian and Wang, Wenping and Luo, Ping},
  booktitle={The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
  year={2022}
}

Acknowledgement

We thank everyone who makes their code and models available, especially Taming Transformer, basicsr, and GFPGAN.

Contact

For any question, feel free to email [email protected] or [email protected].

restoreformer's People

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

restoreformer's Issues

DICTIONARY MODEL

Hello,
I get the error message
No such file or directory: 'YOUR TRAINED HD DICTIONARY MODEL'
when I start the run.sh

About FID on test datasets

The real HR images need to be input when calculating FID. Is the real HR images from FFHQ or GT corresponding to CelebA-HQ when testing on the CelebA-test dataset? When testing on real-world datasets without GT, is FFHQ used?

Training settings in the paper differ from the code

Hi! Thank you for publishing such an amazing work! In the paper you decay learning rate after 6e5 steps while in HQ_Dictionary.yaml it is set to 4e5 steps. Schedule steps, learning rate and loss weights in the configs for both HQ dictionary and RestoreFormer are different from the paper. Which settings should I use to reproduce your excellent results?

When run the main.py after setting 'HQ_Dictionary' to ‘conf_name’ in scripts/run.sh.I get an error: Missing key comp_weight

Hello, I appreciate your work very much, but I have encountered some problems. As the title says, I set 'HQ_Dictionary' to ‘conf_name’ in scripts/run.sh before I using sh scripts/run.sh command, prepare for training. But I got the following error message:

**_Traceback (most recent call last):
File "main.py", line 481, in
model = instantiate_from_config(config.model)
File "main.py", line 160, in instantiate_from_config
return get_obj_from_str(config["target"])(config.get("params", dict()))
File "/opt/data/private/DESKTOPforG/face_restoration/RestoreFormer/RestoreFormer-main/RestoreFormer/models/vqgan_v1.py", line 30, in init
if lossconfig['params']['comp_weight'] or lossconfig['params']['comp_style_weight']:
File "/root/faceRESTORATION/anaconda3/envs/RestoreFormer/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 377, in getitem
self._format_and_raise(key=key, value=None, cause=e)
File "/root/faceRESTORATION/anaconda3/envs/RestoreFormer/lib/python3.7/site-packages/omegaconf/base.py", line 237, in _format_and_raise
type_override=type_override,
File "/root/faceRESTORATION/anaconda3/envs/RestoreFormer/lib/python3.7/site-packages/omegaconf/_utils.py", line 873, in format_and_raise
_raise(ex, cause)
File "/root/faceRESTORATION/anaconda3/envs/RestoreFormer/lib/python3.7/site-packages/omegaconf/_utils.py", line 771, in _raise
raise ex.with_traceback(sys.exc_info()[2]) # set env var OC_CAUSE=1 for full trace
File "/root/faceRESTORATION/anaconda3/envs/RestoreFormer/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 371, in getitem
return self._get_impl(key=key, default_value=DEFAULT_MARKER)
File "/root/faceRESTORATION/anaconda3/envs/RestoreFormer/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 445, in _get_impl
key=key, throw_on_missing_key=True, validate_key=validate_key
File "/root/faceRESTORATION/anaconda3/envs/RestoreFormer/lib/python3.7/site-packages/omegaconf/basecontainer.py", line 78, in _get_child
throw_on_missing_key=throw_on_missing_key,
File "/root/faceRESTORATION/anaconda3/envs/RestoreFormer/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 482, in get_node
raise ConfigKeyError(f"Missing key {key!s}")
omegaconf.errors.ConfigKeyError: Missing key comp_weight
full_key: model.params.lossconfig.params.comp_weight
object_type=dict

I checked the code carefully and found that the problem lies in your RestoreFormer.models.vqgan_v1, in the RestoreFormerModel class of this file, the statement on line 30 is "if lossconfig['params']['comp_weight'] or lossconfig['params']['comp_style_weight']:". It is this statement that reports an error, because in HQ Dictionary.yaml_ file, I found that the lossconfig['params']['comp_weight'] key does not exist exactly. Is this my use error or your project file error. I'm a beginner. Thank you very much. If you can reply and answer my questions, thank you again.

Recommend for large scale training dataset

Hi, thanks for your amazing work. I've several question and hope you can give some advises.

  • Can default arch & config work good with large scale training dataset, e.g 1M image
  • Did you tried VQVAEGANMultiHeadTransformer and compared result with default VQVAEGAN, with my knowledge Transformer will work better with large scale dataset
  • Some hyper parameters turning to deal with large scale dataset

Thanks again

omegaconf.errors.ConfigAttributeError: Missing key logger

Working with z of shape (1, 256, 16, 16) = 65536 dimensions.
loaded pretrained LPIPS loss from /data/juicefs_ai_camera_jgroup/11148646/loss/vgg.pth
VQLPIPSWithDiscriminatorWithCompWithIdentity running with hinge loss.
Traceback (most recent call last):
File "main.py", line 495, in
logger_cfg = lightning_config.logger or OmegaConf.create()
File "/opt/conda/envs/faceformer/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 358, in getattr
key=key, value=None, cause=e, type_override=ConfigAttributeError
File "/opt/conda/envs/faceformer/lib/python3.7/site-packages/omegaconf/base.py", line 237, in _format_and_raise
type_override=type_override,
File "/opt/conda/envs/faceformer/lib/python3.7/site-packages/omegaconf/_utils.py", line 873, in format_and_raise
_raise(ex, cause)
File "/opt/conda/envs/faceformer/lib/python3.7/site-packages/omegaconf/_utils.py", line 771, in _raise
raise ex.with_traceback(sys.exc_info()[2]) # set env var OC_CAUSE=1 for full trace
File "/opt/conda/envs/faceformer/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 354, in getattr
key=key, default_value=DEFAULT_MARKER, validate_key=False
File "/opt/conda/envs/faceformer/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 445, in _get_impl
key=key, throw_on_missing_key=True, validate_key=validate_key
File "/opt/conda/envs/faceformer/lib/python3.7/site-packages/omegaconf/basecontainer.py", line 78, in _get_child
throw_on_missing_key=throw_on_missing_key,
File "/opt/conda/envs/faceformer/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 482, in _get_node
raise ConfigKeyError(f"Missing key {key!s}")
omegaconf.errors.ConfigAttributeError: Missing key logger
full_key: logger
object_type=dict

配置文件

作者您好!HQ和LQ训练的配置文件中的enable_mid都为true,是否需要将HQ阶段训练配置文件的enable_mid设置为false呢

Question about vector quantization

I genuinely think it is a good idea.

Since I have no research experience in vector quantization, I would like to know how to ensure that all tokens in the Dict are optimized. If there is a token in the Dict that is far away from the image's all feature tokens, then it may not be selected by argmin during training.

Training time of the RestoreFormer model

Hi, thanks for your remarkable work. I've several questions as follows:

  1. How many epochs was the RestoreFormer model trained?

  2. How long does it take to train the RestoreFormer model?

Thanks again and look forward to your feedback.

关于测试和训练

作者您好!请问Restore Former模型可以用Windows系统进行训练吗?

ONNX Conversion

Please provide an ONNX model (or atleast a way to convert it).

Training with own data

Hi there,
Could you provide the training script if I would like to train on my own dataset?
The architecture of data folder is like:
--mydata
------train
------------A(haze one)
------------B(Groundtruth)
-------test
------------A(haze one)
------------B(Groundtruth)

Train dataset

Hello!Where can I get the train dataset contain degraded images and HD images?

测试

您好!在测试的时候还需要用到生成HQ Dictionary的网络吗,还是只需要用到网络生成的HQ Dictionary就可以?
谢谢!

How does this compare to CodeFormer?

For a moment and due to the similar names I assumed this was related to CodeFormer but it seems it's just a coincidence, the researchers are different and from different institution entirely.

However I might be wrong, since both papers were released only 3 days apart? Either way, it'd be nice to have a comparison of both, especially if you beat them in quality.

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.