Giter Club home page Giter Club logo

image-super-resolution-via-iterative-refinement's Introduction

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 implementation details that may vary from the paper's description, which may be different from the actual SR3 structure due to details missing. Specifically, we:

  • Used the ResNet block and channel concatenation style like vanilla DDPM.
  • Used the attention mechanism in low-resolution features ( $16 \times 16$ ) like vanilla DDPM.
  • Encode the $\gamma$ as FilM structure did in WaveGrad, and embed it without affine transformation.
  • Define the posterior variance as $\dfrac{1-\gamma_{t-1}}{1-\gamma_{t}} \beta_t$ rather than $\beta_t$, which gives similar results to the vanilla paper.

If you just want to upscale $(64 \times 64)\text{px} \rightarrow (512 \times 512)\text{px}$ images using the pre-trained model, check out this google colab script.

Status

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

Conditional Generation (with Super Resolution)

  • 16×16 -> 128×128 on FFHQ-CelebaHQ
  • 64×64 -> 512×512 on FFHQ-CelebaHQ

Unconditional Generation

  • 128×128 face generation on FFHQ
  • 1024×1024 face generation by a cascade of 3 models

Training Step

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

Results

Note: We set the maximum reverse steps budget to $2000$. We limited the 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 for optimization. We are 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

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/gamma as model embedding inputs, respectively. In our experiments, the 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
# Download the pretrained model and edit [sr|sample]_[ddpm|sr3]_[resolution option].json about "resume_state":
"resume_state": [your pretrained model's 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.

# Resize to get 16×16 LR_IMGS and 128×128 HR_IMGS, 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:

"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:

# set the high/low resolution images, bicubic interpolation images path 
dataset/celebahq_16_128/
├── hr_128 # it's same with sr_16_128 directory if you don't have ground-truth images.
├── lr_16 # vinilla low resolution images
└── sr_16_128 # images ready to super resolution
# 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:

"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

# 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

# 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:

# 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 the 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. 🚀

Acknowledgements

Our work is based on the following theoretical works:

Furthermore, we are benefitting a lot from the following projects:

image-super-resolution-via-iterative-refinement's People

Contributors

ayulockin avatar devjake avatar drew6017 avatar janspiry avatar mazeofencryption 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  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

image-super-resolution-via-iterative-refinement's Issues

Not getting great results

Hey @Janspiry, I was trying to infer on a few images to get their super-resolution variants.

Here's the result of the inference: https://wandb.ai/ayush-thakur/sr_ffhq/runs/9zfkm2zm

image

I have used the following checkpoint: 16×16 -> 128×128 on FFHQ-CelebaHQ

The output images (middle column) are definitely super-resolution but not preserving the semantics very well. Can you let me know what I might be missing?

Python and Torch version

I have an issue when loading the dataset with file data/LRHR_dataset.py
self.data_len = min(self.data_len, self.dataset_len) TypeError: '<' not supported between instances of 'int' and 'NoneType'

Could you please share the python and torch versions?

Thanks in advance.

1024x1024 model question

Hi. Do you plan to release 1024x1024 model?
Or it can be done modifying code to cascade all models?
Cause, I think it is better to not downscale images to 128Pixels.
Thank you very much in advance

inference troubles

Hi, i trying to run singe image inference and got this error. Any ideas to fix it?

image

Train tips

Hi
Thanks for your work. Can you please give advice or some tips and things to try to improve training process?
Loss is reducing but validation results are still poor. And quality isn't improving with new epoches. Despite dataset is quite big (10000 pics) and homogeneous . I'm trying to train 256 ->1024 sr3.
I would appreciate any tips or ideas. Thanks!

"model": { "which_model_G": "sr3", // use the ddpm or sr3 network structure "finetune_norm": false, "unet": { "in_channel": 6, "out_channel": 3, "inner_channel": 16, "norm_groups": 16, "channel_multiplier": [ 1, 2, 4, 8, // 8, // 16, 16, 32, 32, 32 ], "attn_res": [ // 16 ], "res_blocks": 1, "dropout": 0 },

Speeding up training/testing

Hi,

I have access to a big server with 6 GPUs and 64 CPU's. I'm using three of the GPUs in a docker container to run some images through this.

Currently my config train file looks like:

    "datasets": {
        "train": {
            "name": "FFHQ",
            "mode": "HR", // whether need LR img
            "dataroot": "dataset/ffhq_64_512",
            "datatype": "img", //lmdb or img, path of img files
            "l_resolution": 64, // low resolution need to super_resolution
            "r_resolution": 512, // high resolution
            "batch_size": 2,
            "num_workers": 16,
            "use_shuffle": true,
            "data_len": -1 // -1 represents all data used in train
        },

where num_workers was changed from 8 to 16 in the default settings. However, training doesn't seem to noticeably have sped up (it's still about a minute per 50 iterations).

When I try to raise the batch_size, I start getting out-of-memory errors.
Is there a good way to speed up training by using the power of this server?

Thanks!

Multi-gpu support

Multi-gpu training support seems to be problematic~
When the loss type is "l1", l_pix in line47 of model/model.py will be a list. Thus, l_pix.backward() will not run correctly.
When the loss type is "l1", line47 of model/model.py should be l_pix = self.netG(self.data).mean()
I'm not sure if the change is correct.

Iteration Count

This may be a dumb question, but is there a way to change the amount of "diffusion steps" or iterations the model does when upscaling. Right now I think it is 2000. Thank you so much in advance! 👍 Amazing project might I add!

Inference: PIL.UnidentifiedImageError: cannot identify image file

I trained and when running inference using following command:

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

i get following error:

PIL.UnidentifiedImageError: cannot identify image file

File "/content/ISR/data/LRHR_dataset.py", line 59, in getitem
img_LR = Image.open(BytesIO(lr_img_bytes)).convert("RGB")
File "/usr/local/lib/python3.7/dist-packages/PIL/Image.py", line 2896, in open
"cannot identify image file %r" % (filename if filename else fp)
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7fab1d486890>

Training Resume Error

21-09-13 21:50:38.132 - INFO: Loading pretrained model for G [experiments/sr_ffhq_210913_210552/checkpoint/I10000_E1] ...
Traceback (most recent call last):
  File "sr.py", line 51, in <module>
    diffusion = Model.create_model(opt)
  File "/opt/github/Image-Super-Resolution-via-Iterative-Refinement/model/__init__.py", line 7, in create_model
    m = M(opt)
  File "/opt/github/Image-Super-Resolution-via-Iterative-Refinement/model/model.py", line 23, in __init__
    self.load_network()
  File "/opt/github/Image-Super-Resolution-via-Iterative-Refinement/model/model.py", line 162, in load_network
    self.optG.load_state_dict(opt['optimizer'])
AttributeError: 'DDPM' object has no attribute 'optG'

release of another pretrained model for imagenet

Thank you for the release of the pretrained model for faces.
For my particular use case, a model pretrained on imagenet could be more useful and I can't manage to train it on my dataset (apparently, 256 GB GPU is required even when I set the parameters to lower values, and I only have a 8GB GPU)
Could you also release the model pretrained on imagenet?

Thank you for your work.

super resolution

Hi everyone.

I tried to use this incredible tool with data that has been mentioned in the repository, but I face an error when I try to run [python3 sr.py -p train -config sr_sr3_16_128.json]

the edition in the sr_sr3_16_128.json:
"datasets": { "train|val": { "dataroot": "/content/drive/MyDrive/sr/dataset_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 } },

the error:
export CUDA_VISIBLE_DEVICES=0 Traceback (most recent call last): File "/content/drive/MyDrive/sr/sr.py", line 23, in <module> opt = Logger.parse(args) File "/content/drive/MyDrive/sr/core/logger.py", line 73, in parse opt['datasets']['val']['data_len'] = 3 KeyError: 'val'

when I change the order to val like = [python3 sr.py -p val -config sr_sr3_16_128.json], the error is :
Traceback (most recent call last): File "/content/drive/MyDrive/sr/sr.py", line 144, in <module> for _, val_data in enumerate(val_loader): NameError: name 'val_loader' is not defined

Even when I change the order to = [python3 infer.py -config sr_sr3_16_128.json] as mentioned in the issues section, the error is :
Traceback (most recent call last): File "/content/drive/MyDrive/sr/infer.py", line 59, in <module> for _, val_data in enumerate(val_loader): NameError: name 'val_loader' is not defined

I don't understand why that errors .. thanks in advance for helping ❤️

Dependencies missing from repo

The repo lacks a way of pulling all necessary dependencies before running. Something like dependencies.txt would be helpful.

"CUDA out of memory error" while training

RuntimeError: CUDA out of memory. Tried to allocate 48.00 MiB (GPU 0; 6.00 GiB total capacity; 4.05 GiB already allocated; 0 bytes free; 4.17 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

Error(s) in loading state_dict for GaussianDiffusion

Seeing Error(s) in loading state_dict for GaussianDiffusion when trying to load the model I1560000_E91.
I tried to use pytorch 1.7.1, python 3.7 to load the model. Was this also the version used to train it?

21-11-14 04:14:05.699 - INFO: Dataset [LRHRDataset - CelebaHQ] is created.
21-11-14 04:14:05.699 - INFO: Initial Dataset Finished
21-11-14 04:14:06.367 - INFO: Loading pretrained model for G [experiments/I1560000_E91] ...
Traceback (most recent call last):
  File "infer.py", line 46, in <module>
    diffusion = Model.create_model(opt)
  File "/home/jotschi/workspaces/ml/Image-Super-Resolution-via-Iterative-Refinement/model/__init__.py", line 7, in create_model
    m = M(opt)
  File "/home/jotschi/workspaces/ml/Image-Super-Resolution-via-Iterative-Refinement/model/model.py", line 42, in __init__
    self.load_network()
  File "/home/jotschi/workspaces/ml/Image-Super-Resolution-via-Iterative-Refinement/model/model.py", line 158, in load_network
    gen_path), strict=False)
  File "/home/jotschi/anaconda3/envs/py37/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1052, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for GaussianDiffusion:
        size mismatch for denoise_fn.downs.0.weight: copying a param with shape torch.Size([64, 3, 3, 3]) from checkpoint, the shape in current model is torch.Size([64, 6, 3, 3]).
        size mismatch for denoise_fn.downs.5.res_block.noise_func.noise_func.0.weight: copying a param with shape torch.Size([128, 64]) from checkpoint, the shape in current model is torch.Size([256, 64]).
        size mismatch for denoise_fn.downs.5.res_block.noise_func.noise_func.0.bias: copying a param with shape torch.Size([128]) from checkpoint, the shape in current model is torch.Size([256]).

No such file or directory: 'I830000_E32_gen.pth'

I tried upscaling a simple picture using the colab notebook but instead getting this "No such file.." error on running the last cell
download

21-11-13 09:59:49.904 - INFO: Dataset [LRHRDataset - CelebaHQ] is created.
21-11-13 09:59:49.904 - INFO: Initial Dataset Finished
21-11-13 10:00:06.355 - INFO: Loading pretrained model for G [I830000_E32] ...
Traceback (most recent call last):
File "infer.py", line 46, in
diffusion = Model.create_model(opt)
File "/content/Image-Super-Resolution-via-Iterative-Refinement/model/init.py", line 7, in create_model
m = M(opt)
File "/content/Image-Super-Resolution-via-Iterative-Refinement/model/model.py", line 42, in init
self.load_network()
File "/content/Image-Super-Resolution-via-Iterative-Refinement/model/model.py", line 158, in load_network
gen_path), strict=(not self.opt['model']['finetune_norm']))
File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 594, in load
with _open_file_like(f, 'rb') as opened_file:
File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 230, in _open_file_like
return _open_file(name_or_buffer, mode)
File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 211, in init
super(_open_file, self).init(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: 'I830000_E32_gen.pth'

Question about posterior variance

Hi, thank you for sharing all the codes!

I have a question about the implementation and the equations of the paper.

In the testing phase, using the SR3 model and the conditional input:

  • What is the reference for this posterior variance? In the paper, they used sqrt(1 - \alpha_t). In the same equation, why divide by 2 and take the exponential in this line?

Thanks!

Can you give me an example?

Can you give me an example , like I have a low resolution images picture ,how i run out a super resolution images?
python sr.py -p val -c config/sr_sr3_64_512.json and python eval.py not work

DDPM Model Sample.py did not converge due to n_timestep

Hello.
I trained the default model and the ddpm model didn't converge for me after 550,000 iters.
the results always was something like that:
550000_4_sr

I changed in line 68 to: n_timestep=2000

"beta_schedule": {
"train": {
"schedule": "linear",
"n_timestep": 2000,
"linear_start": 1e-4,
"linear_end": 2e-2
},
"val": {
"schedule": "linear",
"n_timestep": 100,
"linear_start": 1e-4,
"linear_end": 2e-2
}

Now the model converges good.
Is it supposed to be always equal in train and val phases?

Thanks.
Erez.

UserWarning: Argument interpolation should be of type InterpolationMode instead of int. Please, use InterpolationMode enum.

So, when running the command:
python data/prepare_data.py --path /content/Image-Super-Resolution-via-Iterative-Refinement/input/ --size 64,512 --out ./dataset/celebahq

I get the following output:

0/1 images processed
/usr/local/lib/python3.7/dist-packages/torchvision/transforms/functional.py:405: UserWarning: Argument interpolation should be of type InterpolationMode instead of int. Please, use InterpolationMode enum.
  "Argument interpolation should be of type InterpolationMode instead of int. "
0/1 images processed

I tried manually changing all instances of Image.BICUBIC with InterpolationMode.BICUBIC and it didn't work. In this case I got 0/1 images processed and that was it.

Also tried running both in the Google Collab project, and also locally an Ubuntu, and got the same problem both times.

Any directions on what i could do to fix it? Thanks a lot!

Memory leak in multiprocessing pool

(windows10 / python3.6 / conda:latest / all-other-packages:latest)

There is a memory leak somewhere in the multiprocessing section:

with multiprocessing.Pool(n_worker) as pool:

Running 8 workers on a system with 16GB of ram will lead to a crash within ~1-2mins and a nasty pagefile increase to 40GB! I re-wrote the script using the older Process() api and no shared variables between instances which fixed the issue so its probably something to do with data passing.

All of my tests were done on the full celebahq dataset.

There is no prepare.py file

As stated by the Issue title, there is no prepare.py file in the repository. I think it should be prepare_data.py instead.

In the markdown shown below, it should be: python data/prepare_data.py ..
image

Custom input issue

Please pardon my inexperience using SR GANs, I wondering if you could clarify what is the role of the data input folders:

  1. Should the l_resolution/h_resolution folders contain the same images (with different sizes)? I assume so for testing/validation steps.
  2. What sort of images does the sr_16_64 contains initially?
  3. Where should I put the images for which I want to increase the resolution?

Thank you in advance for your answer and thank you for sharing your awesome work!

Failed to create env

Hello, I'm currently having a problem while running the setup. I'm also quite inexperienced in Conda and Python. What am I doing wrong here?

$ conda env create -f core/environment.yml
Collecting package metadata (repodata.json): failed

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64/repodata.json>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
'https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64'

Specs:

  • WSL 2: 5.10.60.1-microsoft-standard-WSL2 with Ubuntu
  • using Anaconda: conda 4.11.0
  • on Windows 10
  • GPU (8 GiB): NVIDIA GeForce RTX 2060 SUPER

Collab?

Would it be possible to create a collab in order to try it?

Training epoch

I'm a little confused about training logic。Is the code below only used to control training one epoch?

# line 65-71 of sr.py
if opt['phase'] == 'train':
        while current_step < n_iter:
            current_epoch += 1
            for _, train_data in enumerate(train_loader):
                current_step += 1
                if current_step > n_iter:
                    break

Infer.Py needs to be rewritten

Traceback (most recent call last):
File "infer.py", line 40, in
val_set = Data.create_dataset(dataset_opt, phase)
File "/content/Image-Super-Resolution-via-Iterative-Refinement/data/init.py", line 34, in create_dataset
need_LR=(mode == 'LRHR')
File "/content/Image-Super-Resolution-via-Iterative-Refinement/data/LRHR_dataset.py", line 30, in init
'{}/sr_{}_{}'.format(dataroot, l_resolution, r_resolution))
File "/content/Image-Super-Resolution-via-Iterative-Refinement/data/util.py", line 16, in get_paths_from_images
assert os.path.isdir(path), '{:s} is not a valid directory'.format(path)
AssertionError: dataset/celebahq_64_512/sr_64_512 is not a valid directory

cuda out of memory

now i'm in tutorial. i downloaded FFHQ 512×512 dataset and i converted it 64_512 dataset to use prepare_data.py.

and then generate following code that python sr.py -p train -c config/sr_sr3_64_512.json

but i got this error code that cuda out of memory.

what kind of parameter do i have to fix for clear this error code?

image

The saved weights do not load properly

Trained my models on images, got a PSNR of like ~19, loaded the same model using infer.py and the images were just noise. Tried using sr.py (val & train) and it's like the loaded model is brand new (even thought it is loaded) and the PSNR starts at ~12.

Checked the images outputted during the training phase and they look decent but the second the training stops and I use an other code it doesn't work.

Any reason why that could be happening?

No difference

I have tried using my own images, but I have not got any difference between hr (which is just upscaled lr) and inf.
My photos are black and white though, I don't know if that would have any effect on it. I seems to me, this is only copying whatever is in the hr folder. Because it doesn't matter if I use actual ground truths or upscaled low res images, the inference looks the same as it.

TypeError: __init__() got an unexpected keyword argument 'norm_groups'

when running using following command:
python sr.py -p val -c config/sr_ddpm_16_128.json
I get following error:

(pytorch_env) admin@Admins-MacBook-Pro sr3 % python sr.py -p val -c config/sr_ddpm_16_128.json
export CUDA_VISIBLE_DEVICES=0
21-09-09 17:32:40.626 - INFO:   name: sr_ffhq
  phase: val
  gpu_ids: [0]
  path:[
    log: experiments/sr_ffhq_210909_173240/logs
    tb_logger: experiments/sr_ffhq_210909_173240/tb_logger
    results: experiments/sr_ffhq_210909_173240/results
    checkpoint: experiments/sr_ffhq_210909_173240/checkpoint
    resume_state: Users/admin/sr3/pretrained/I640000_E37
    experiments_root: experiments/sr_ffhq_210909_173240
  ]
  datasets:[
    train:[
      name: FFHQ
      mode: HR
      dataroot: dataset/ffhq_16_128
      datatype: img
      l_resolution: 16
      r_resolution: 128
      batch_size: 12
      num_workers: 8
      use_shuffle: True
      data_len: -1
    ]
    val:[
      name: CelebaHQ
      mode: LRHR
      dataroot: dataset/celebahq_16_128
      datatype: img
      l_resolution: 16
      r_resolution: 128
      data_len: 3
    ]
  ]
  model:[
    which_model_G: ddpm
    finetune_norm: False
    unet:[
      in_channel: 6
      out_channel: 3
      inner_channel: 64
      channel_multiplier: [1, 1, 2, 2, 4, 4]
      attn_res: [16]
      res_blocks: 2
      dropout: 0.2
    ]
    beta_schedule:[
      train:[
        schedule: linear
        n_timestep: 2000
        linear_start: 0.0001
        linear_end: 0.02
      ]
      val:[
        schedule: linear
        n_timestep: 100
        linear_start: 0.0001
        linear_end: 0.02
      ]
    ]
    diffusion:[
      image_size: 128
      channels: 3
      conditional: True
    ]
  ]
  train:[
    n_iter: 1000000
    val_freq: 10000.0
    save_checkpoint_freq: 10000.0
    print_freq: 200
    optimizer:[
      type: adam
      lr: 0.0001
    ]
    ema_scheduler:[
      step_start_ema: 5000
      update_ema_every: 1
      ema_decay: 0.9999
    ]
  ]
  distributed: False

21-09-09 17:32:40.643 - INFO: Dataset [LRHRDataset - CelebaHQ] is created.
21-09-09 17:32:40.644 - INFO: Initial Dataset Finished
Traceback (most recent call last):
  File "sr.py", line 51, in <module>
    diffusion = Model.create_model(opt)
  File "/Users/admin/sr3/model/__init__.py", line 7, in create_model
    m = M(opt)
  File "/Users/admin/sr3/model/model.py", line 16, in __init__
    self.netG = self.set_device(networks.define_G(opt))
  File "/Users/admin/sr3/model/networks.py", line 91, in define_G
    model = unet.UNet(
  File "/Users/admin/sr3/model/ddpm_modules/unet.py", line 218, in __init__
    self.final_conv = Block(pre_channel, default(out_channel, in_channel), norm_groups=norm_groups)
TypeError: __init__() got an unexpected keyword argument 'norm_groups'

colab errors

/content/Image-Super-Resolution-via-Iterative-Refinement
0/2 images processed/usr/local/lib/python3.7/dist-packages/torchvision/transforms/functional.py:405: UserWarning: Argument interpolation should be of type InterpolationMode instead of int. Please, use InterpolationMode enum.
"Argument interpolation should be of type InterpolationMode instead of int. "
/usr/local/lib/python3.7/dist-packages/torchvision/transforms/functional.py:405: UserWarning: Argument interpolation should be of type InterpolationMode instead of int. Please, use InterpolationMode enum.
"Argument interpolation should be of type InterpolationMode instead of int. "
0/2 images processed

Traceback (most recent call last):
File "infer.py", line 12, in
import wandb
ModuleNotFoundError: No module named 'wandb'

Bug in Image Augmentations

Hi,
When reading and augment the data we call:

def transform_augment(img_list, split='val', min_max=(0, 1)):
ret_img = []
for img in img_list:
img = transform2numpy(img)
img = augment(img, split)
img = transform2tensor(img, min_max)
ret_img.append(img)
return ret_img

The bugs:

  1. This line iterate over the first dimension of the numpy image (because the function augment(img, split) called with single image)

    return [_augment(img) for img in img_list]

  2. the hflip get the split value. ( We should call it augment(img, split=split) )

    def augment(img_list, hflip=True, rot=True, split='val'):

Suggested solution:

def transform_augment(img_list, split='val', min_max=(0, 1)):
    imgs = [transform2numpy(img) for img in img_list]
    imgs = augment(imgs, split=split)
    ret_img = [transform2tensor(img, min_max) for img in imgs]
    return ret_img

Please let me know if it's correct.

Training on another big datasets

Have you plans training this network on ImageNet, COCO, or another datasets? Can model demonstrate good results in common objects photo (nature, city) after that?

ZeroDivisionError

error while running sr3.py file

export CUDA_VISIBLE_DEVICES=0
21-08-16 15:31:59.624 - INFO: name: basic_sr_ffhq
phase: val
gpu_ids: [0]
path:[
log: experiments\basic_sr_ffhq_210816_153159\logs
tb_logger: experiments\basic_sr_ffhq_210816_153159\tb_logger
results: experiments\basic_sr_ffhq_210816_153159\results
checkpoint: experiments\basic_sr_ffhq_210816_153159\checkpoint
resume_state: model/pretrained/checkpoint/I640000_E37_gen.pth
experiments_root: experiments\basic_sr_ffhq_210816_153159
]
datasets:[
train:[
name: FFHQ
mode: HR
dataroot: dataset/ffhq
l_resolution: 16
r_resolution: 128
batch_size: 4
num_workers: 8
use_shuffle: True
data_len: -1
]
val:[
name: CelebaHQ
mode: LRHR
dataroot: dataset/celebahq
l_resolution: 16
r_resolution: 128
data_len: 50
]
]
model:[
which_model_G: sr3
finetune_norm: False
unet:[
in_channel: 6
out_channel: 3
inner_channel: 64
channel_multiplier: [1, 2, 4, 8, 8]
attn_res: [16]
res_blocks: 2
dropout: 0.2
]
beta_schedule:[
train:[
schedule: linear
n_timestep: 2000
linear_start: 1e-06
linear_end: 0.01
]
val:[
schedule: linear
n_timestep: 2000
linear_start: 1e-06
linear_end: 0.01
]
]
diffusion:[
image_size: 128
channels: 3
conditional: True
]
]
train:[
n_iter: 1000000
val_freq: 10000.0
save_checkpoint_freq: 10000.0
print_freq: 200
optimizer:[
type: adam
lr: 0.0001
]
ema_scheduler:[
step_start_ema: 5000
update_ema_every: 1
ema_decay: 0.9999
]
]
distributed: False

Traceback (most recent call last):
File "sr.py", line 45, in
val_set = Data.create_dataset(dataset_opt, phase)
File "D:\rp\Projects\SuperResolution\sr3\data_init_.py", line 33, in create_dataset
need_LR=(mode == 'LRHR')
File "D:\rp\Projects\SuperResolution\sr3\data\LRHR_dataset.py", line 14, in init
readahead=False, meminit=False)
lmdb.Error: dataset/celebahq: The system cannot find the path specified.

(facerec) D:\rp\Projects\SuperResolution\sr3>python eval.py -p boot_img
Traceback (most recent call last):
File "eval.py", line 36, in
avg_psnr = avg_psnr / idx
ZeroDivisionError: float division by zero

Sharing your Pretrained models with the Hugging Face Hub

Hi @Janspiry !

The results of the models are quite impressive! I see you currently share your models with Google Drive. Would you be interested in sharing your models in the Hugging Face Hub? The Hub offers free hosting of over 25K models, and it would make your work more accessible and visible to the rest of the ML community.

Some of the benefits of sharing your models through the Hub would be:

  • versioning, commit history and diffs
  • repos provide useful metadata about their tasks, languages, metrics, etc that make them discoverable
  • multiple features from TensorBoard visualizations, PapersWithCode integration, and more
  • wider reach of your work to the ecosystem

Creating the repos and adding new models should be a relatively straightforward process if you've used Git before. This is a step-by-step guide explaining the process in case you're interested. Please let us know if you would be interested and if you have any questions.

Happy to hear your thoughts,
Omar and the Hugging Face team

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.