Awesome
Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling (HCFlow, ICCV2021)
<a href="https://colab.research.google.com/gist/JingyunLiang/cdb3fef89ebd174eaa43794accb6f59d/hcflow-demo-on-x8-face-image-sr.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="google colab logo"></a> <a href="https://replicate.ai/jingyunliang/hcflow-sr"><img src="https://img.shields.io/static/v1?label=Replicate&message=Demo and Docker Image&color=blue"></a>
This repository is the official PyTorch implementation of Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling (arxiv, supp).
:rocket: :rocket: :rocket: News:
- Sep. 07, 2021: We add an online Colob demo <a href="https://colab.research.google.com/gist/JingyunLiang/cdb3fef89ebd174eaa43794accb6f59d/hcflow-demo-on-x8-face-image-sr.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="google colab logo"></a> for easy comparison of HCFlow and SRFlow.
- Sep.06, 2021: See our recent work SwinIR: Transformer-based image restoration <a href="https://colab.research.google.com/gist/JingyunLiang/a5e3e54bc9ef8d7bf594f6fee8208533/swinir-demo-on-real-world-image-sr.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="google colab logo"></a>
- Aug. 17, 2021: See our recent work for blind SR: Mutual Affine Network for Spatially Variant Kernel Estimation in Blind Image Super-Resolution (MANet), ICCV2021 <a href="https://colab.research.google.com/gist/JingyunLiang/4ed2524d6e08343710ee408a4d997e1c/manet-demo-on-spatially-variant-kernel-estimation.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="google colab logo"></a>
- Aug. 17, 2021: See our recent work for real-world image SR: Designing a Practical Degradation Model for Deep Blind Image Super-Resolution (BSRGAN), ICCV2021
- Aug. 17, 2021: See our previous flow-based kernel estimation: Flow-based Kernel Prior with Application to Blind Super-Resolution (FKP), CVPR2021
</p>Normalizing flows have recently demonstrated promising results for low-level vision tasks. For image super-resolution (SR), it learns to predict diverse photo-realistic high-resolution (HR) images from the low-resolution (LR) image rather than learning a deterministic mapping. For image rescaling, it achieves high accuracy by jointly modelling the downscaling and upscaling processes. While existing approaches employ specialized techniques for these two tasks, we set out to unify them in a single formulation. In this paper, we propose the hierarchical conditional flow (HCFlow) as a unified framework for image SR and image rescaling. More specifically, HCFlow learns a bijective mapping between HR and LR image pairs by modelling the distribution of the LR image and the rest high-frequency component simultaneously. In particular, the high-frequency component is conditional on the LR image in a hierarchical manner. To further enhance the performance, other losses such as perceptual loss and GAN loss are combined with the commonly used negative log-likelihood loss in training. Extensive experiments on general image SR, face image SR and image rescaling have demonstrated that the proposed HCFlow achieves state-of-the-art performance in terms of both quantitative metrics and visual quality.
<p align="center"> <img height="120" src="./illustrations/computation_graph.png"> <img height="120" src="./illustrations/architecture.png">
Requirements
- Python 3.7, PyTorch == 1.7.1
- Requirements: opencv-python, lpips, natsort, etc.
- Platforms: Ubuntu 16.04, cuda-11.0
cd HCFlow-master
pip install -r requirements.txt
Quick Run (takes 1 Minute)
To run the code with one command (without preparing data), run following command. Or you can go to our online Colob demo <a href="https://colab.research.google.com/gist/JingyunLiang/cdb3fef89ebd174eaa43794accb6f59d/hcflow-demo-on-x8-face-image-sr.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="google colab logo"></a> to have a try.
cd codes
# face image SR
python test_HCFlow.py --opt options/test/test_SR_CelebA_8X_HCFlow.yml
# general image SR
python test_HCFlow.py --opt options/test/test_SR_DF2K_4X_HCFlow.yml
# image rescaling
python test_HCFlow.py --opt options/test/test_Rescaling_DF2K_4X_HCFlow.yml
Data Preparation
The framework of this project is based on MMSR and SRFlow. To prepare data, put training and testing sets in ./datasets
as ./datasets/DIV2K/HR/0801.png
. Commonly used SR datasets can be downloaded here.
There are two ways for accerleration in data loading: First, one can use ./scripts/png2npy.py
to generate .npy
files and use data/GTLQnpy_dataset.py
. Second, one can use .pklv4
dataset (recommended) and use data/LRHR_PKL_dataset.py
. Please refer to SRFlow for more details. Prepared datasets can be downloaded here.
Training
To train HCFlow for general image SR/ face image SR/ image rescaling, run this command:
cd codes
# face image SR
python train_HCFlow.py --opt options/train/train_SR_CelebA_8X_HCFlow.yml
# general image SR
python train_HCFlow.py --opt options/train/train_SR_DF2K_4X_HCFlow.yml
# image rescaling
python train_HCFlow.py --opt options/train/train_Rescaling_DF2K_4X_HCFlow.yml
All trained models can be downloaded from here.
Testing
Please follow the Quick Run section. Just modify the dataset path in test_HCFlow_*.yml
.
Results
We achieved state-of-the-art performance on general image SR, face image SR and image rescaling.
<img height="400" src="./illustrations/face_result.png">
For more results, please refer to the paper and supp for details.
Citation
@inproceedings{liang21hierarchical,
title={Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling},
author={Liang, Jingyun and Lugmayr, Andreas and Zhang, Kai and Danelljan, Martin and Van Gool, Luc and Timofte, Radu},
booktitle={IEEE International Conference on Computer Vision},
year={2021}
}
License & Acknowledgement
This project is released under the Apache 2.0 license. The codes are based on MMSR, SRFlow, IRN and Glow-pytorch. Please also follow their licenses. Thanks for their great works.