https://github.com/blutjens/image-super-resolution-via-iterative-refinement

Unofficial implementation of Image Super-Resolution via Iterative Refinement by Pytorch

https://github.com/blutjens/image-super-resolution-via-iterative-refinement

Science Score: 10.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.5%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Unofficial implementation of Image Super-Resolution via Iterative Refinement by Pytorch

Basic Info
  • Host: GitHub
  • Owner: blutjens
  • License: apache-2.0
  • Default Branch: master
  • Homepage:
  • Size: 9.77 MB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Fork of Janspiry/Image-Super-Resolution-via-Iterative-Refinement
Created over 3 years ago · Last pushed over 3 years ago
Metadata Files
Readme License

README.md

Image Super-Resolution via Iterative Refinement

Paper | Project

Brief

This is an unofficial implementation of Image Super-Resolution via Iterative Refinement(SR3) by Pytorch.

There are some implement details with paper description, which may be different from the actual SR3 structure due to details missing.

  • We used the ResNet block and channel concatenation style like vanilla DDPM.
  • We used the attention mechanism in low-resolution features(16×16) like vanilla DDPM.
  • We encode the $\gamma$ as FilM structure did in WaveGrad, and embed it without affine transformation.
  • We define posterior variance as $ \dfrac{1-\gamma{t-1}}{1-\gamma{t}} \betat $ rather than $\betat$, which have the similar results in vanilla paper.

If you just want to upscale 64x64px -> 512x512px images using the pre-trained model, check out this google colab script.

Status

★★★ NEW: Its follow-up Palette-Image-to-Image-Diffusion-Models is now available; See the details here ★★★

Conditional generation(super resolution)

  • [x] 16×16 -> 128×128 on FFHQ-CelebaHQ
  • [x] 64×64 -> 512×512 on FFHQ-CelebaHQ

Unconditional generation

  • [x] 128×128 face generation on FFHQ
  • [ ] ~~1024×1024 face generation by a cascade of 3 models~~

Training Step

  • [x] log / logger
  • [x] metrics evaluation
  • [x] multi-gpu support
  • [x] resume training / pretrained model
  • [x] validate alone script
  • [x] Weights and Biases Logging 🌟 NEW

Results

Note: We set the maximum reverse steps budget to 2000 now. Limited to model parameters in Nvidia 1080Ti, image noise and hue deviation occasionally appear in high-resolution images, resulting in low scores. There is a lot of room to optimization. Welcome to any contributions for more extensive experiments and code enhancements.

| Tasks/Metrics | SSIM(+) | PSNR(+) | FID(-) | IS(+) | | -------------------- | ----------- | -------- | ---- | ---- | | 16×16 -> 128×128 | 0.675 | 23.26 | - | - | | 64×64 -> 512×512 | 0.445 | 19.87 | - | - | | 128×128 | - | - | | | | 1024×1024 | - | - | | |

| show | show | show | | ------------------------------------------------------------ | ---- | ---- |

| show | show | show | | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | | show | show | show |

| show | show | show | | ------------------------------------------------------------ | ---- | ---- |

Usage

Environment

python pip install -r requirement.txt

Pretrained Model

This paper is based on "Denoising Diffusion Probabilistic Models", and we build both DDPM/SR3 network structures, which use timesteps/gama as model embedding input, respectively. In our experiments, SR3 model can achieve better visual results with the same reverse steps and learning rate. You can select the JSON files with annotated suffix names to train the different models.

| Tasks | Platform(Code:qwer) | | --------------------------------- | ------------------------------------------------------------ | | 16×16 -> 128×128 on FFHQ-CelebaHQ | Google Drive|Baidu Yun |
| 64×64 -> 512×512 on FFHQ-CelebaHQ | Google Drive|Baidu Yun |
| 128×128 face generation on FFHQ | Google Drive|Baidu Yun |

```python

Download the pretrain model and edit [sr|sample][ddpm|sr3][resolution option].json about "resume_state":

"resume_state": [your pretrain model path] ```

Data Prepare

New Start

If you didn't have the data, you can prepare it by following steps:

Download the dataset and prepare it in LMDB or PNG format using script.

```python

Resize to get 16×16 LRIMGS and 128×128 HRIMGS, then prepare 128×128 Fake SR_IMGS by bicubic interpolation

python data/prepare_data.py --path [dataset root] --out [output root] --size 16,128 -l ```

then you need to change the datasets config to your data path and image resolution:

json "datasets": { "train": { "dataroot": "dataset/ffhq_16_128", // [output root] in prepare.py script "l_resolution": 16, // low resolution need to super_resolution "r_resolution": 128, // high resolution "datatype": "lmdb", //lmdb or img, path of img files }, "val": { "dataroot": "dataset/celebahq_16_128", // [output root] in prepare.py script } },

Own Data

You also can use your image data by following steps, and we have some examples in dataset folder.

At first, you should organize the images layout like this, this step can be finished by data/prepare_data.py automatically:

```shell

set the high/low resolution images, bicubic interpolation images path

dataset/celebahq16128/ ├── hr128 # it's same with sr16128 directory if you don't have ground-truth images. ├── lr16 # vinilla low resolution images └── sr16128 # images ready to super resolution ```

```python

super resolution from 16 to 128

python data/prepare_data.py --path [dataset root] --out celebahq --size 16,128 -l ```

Note: Above script can be used whether you have the vanilla high-resolution images or not.

then you need to change the dataset config to your data path and image resolution:

json "datasets": { "train|val": { // train and validation part "dataroot": "dataset/celebahq_16_128", "l_resolution": 16, // low resolution need to super_resolution "r_resolution": 128, // high resolution "datatype": "img", //lmdb or img, path of img files } },

Training/Resume Training

```python

Use sr.py and sample.py to train the super resolution task and unconditional generation task, respectively.

Edit json files to adjust network structure and hyperparameters

python sr.py -p train -c config/sr_sr3.json ```

Test/Evaluation

```python

Edit json to add pretrain model path and run the evaluation

python sr.py -p val -c config/sr_sr3.json

Quantitative evaluation alone using SSIM/PSNR metrics on given result root

python eval.py -p [result root] ```

Inference Alone

Set the image path like steps in Own Data, then run the script:

```python

run the script

python infer.py -c [config file] ```

Weights and Biases 🎉

The library now supports experiment tracking, model checkpointing and model prediction visualization with Weights and Biases. You will need to install W&B and login by using your access token.

``` pip install wandb

get your access token from wandb.ai/authorize

wandb login ```

W&B logging functionality is added to sr.py, sample.py and infer.py files. You can pass -enable_wandb to start logging.

  • -log_wandb_ckpt: Pass this argument along with -enable_wandb to save model checkpoints as W&B Artifacts. Both sr.py and sample.py is enabled with model checkpointing.
  • -log_eval: Pass this argument along with -enable_wandb to save the evaluation result as interactive W&B Tables. Note that only sr.py is enabled with this feature. If you run sample.py in eval mode, the generated images will automatically be logged as image media panel.
  • -log_infer: While running infer.py pass this argument along with -enable_wandb to log the inference results as interactive W&B Tables.

You can find more on using these features here. 🚀

Acknowledge

Our work is based on the following theoretical works:

and we are benefiting a lot from the following projects:

  • https://github.com/bhushan23/BIG-GAN
  • https://github.com/lmnt-com/wavegrad
  • https://github.com/rosinality/denoising-diffusion-pytorch
  • https://github.com/lucidrains/denoising-diffusion-pytorch
  • https://github.com/hejingwenhejingwen/AdaFM

Owner

  • Name: Björn Lütjens (he/him)
  • Login: blutjens
  • Kind: user
  • Company: MIT

Postdoctoral Associate in tackling climate change with AI @ MIT. Project overview at https://blutjens.github.io/

GitHub Events

Total
Last Year

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 77
  • Total Committers: 8
  • Avg Commits per committer: 9.625
  • Development Distribution Score (DDS): 0.429
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Janspiry l****g@f****m 44
jiangliangwei j****i@t****m 13
Janspiry 1****7@q****m 12
ayulockin m****k@g****m 4
MazeOfEncryption i****x@e****t 1
Andrew Howard d****7@g****m 1
John Swan j****n@z****t 1
Ayush Thakur 3****n 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: over 2 years ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

requirement.txt pypi
  • lmdb *
  • numpy *
  • opencv-python *
  • pandas *
  • pillow *
  • tensorboardx *
  • torch >=1.6
  • torchvision *
  • tqdm *
  • wandb *