Giter Site home page Giter Site logo

algolzw / image-restoration-sde Goto Github PK

View Code? Open in Web Editor NEW
538.0 5.0 40.0 48.36 MB

Image Restoration with Mean-Reverting Stochastic Differential Equations, ICML 2023. Winning solution of the NTIRE 2023 Image Shadow Removal Challenge.

Home Page: https://algolzw.github.io/ir-sde/index.html

License: MIT License

Shell 0.76% Python 99.24%
deblurring dehazing denoising deraining diffusion-models image-restoration inpainting stochastic-differential-equations super-resolution score-based

image-restoration-sde's Introduction

Image Restoration SDE
Official PyTorch Implementations of [IR-SDE](ICML 2023) and [Refusion](CVPRW 2023).

Ziwei Luo, Fredrik K. Gustafsson, Zheng Zhao, Jens Sjölund, Thomas B. Schön
Department of Information Technology, Uppsala University

Image Restoration with Mean-Reverting Stochastic Differential Equations [Weights and Results]
IR-SDE

Refusion: Enabling Large-Size Realistic Image Restoration with Latent-Space Diffusion Models [Weights and Results]

Refusion Both methods can be used for synthetic and real-world datasets. You can find more details and results from this Project page.

Updates

[2024.04.15] Updated a posterior sampling approach for better image generation. See paper Photo-Realistic Image Restoration in the Wild with Controlled Vision-Language Models for more details.
[2023.10.02] We present a new Universal Image Restoration framework by controlling vision-language models [here].
[2023.07.06] All results and pre-trained models for IR-SDE and Refusion are provided in link1 and link2, respectively.
[2023.04.25] 🎉🎉🎉 Our IR-SDE paper was accepted by ICML 2023 🎉🎉🎉
[2023.04.23] We released the codes for various tasks (including IR-SDE, Refusion, and Latent-Refusion).
[2023.04.17] 🎉🎉🎉 Our method Refusion is the Winning Solution in NTIRE 2023 Image Shadow Removal Challenge [Paper].

Dependenices

  • OS: Ubuntu 20.04
  • nvidia :
    • cuda: 11.7
    • cudnn: 8.5.0
  • python3
  • pytorch >= 1.13.0
  • Python packages: pip install -r requirements.txt

How to use our Code?

Here we provide an example for image deraining task, but can be changed to any problem with replacing the dataset. And the code for Denoising-SDE/ODE will be released later!

We retrained the deraining model from scratch on 4 Nvidia TITAN XP GPUs and find that it achieves a new SOTA even in terms of PSNR on Rain100H:

Method PSNR SSIM LPIPS FID
IR-SDE 31.65 0.9041 0.047 18.64
Restormer 31.46 0.904 - -
MPRNet 30.41 0.8906 0.158 61.59
PReNet 29.46 0.8990 0.128 52.67

Note that we didn't tune any parameter, the last saved checkpoint was used to evaluation.

The pretrained models for all tasks are provided here, and the performances of other SOTAs can be find in here.

For Refusion Model

Note that if you want to train/test the Refusion model, the only change is to replace the "ir-sde.yml" to "refusion.yml". More details please refer to the "demo.sh" bash script in each task's directory.

Dataset Preparation

We employ Rain100H datasets for training (totally 1,800 images) and testing (100 images).

Download training and testing datasets and process it in a way such that rain images and no-rain images are in separately directories, as

#### for training dataset ####
datasets/rain/trainH/GT
datasets/rain/trainH/LQ


#### for testing dataset ####
datasets/rain/testH/GT
datasets/rain/testH/LQ

Then get into the codes/config/deraining directory and modify the dataset paths in option files in options/train/ir-sde.yml and options/test/ir-sde.yml.

Train

The main code for training is in codes/config/deraining and the core algorithms for IR-SDE is in codes/utils/sde_utils.py.

You can train the model following below bash scripts:

cd codes/config/deraining

# For single GPU:
python3 train.py -opt=options/train/ir-sde.yml

# For distributed training, need to change the gpu_ids in option file
python3 -m torch.distributed.launch --nproc_per_node=2 --master_poer=4321 train.py -opt=options/train/ir-sde.yml --launcher pytorch

Then the models and training logs will save in log/derain_sde/. You can print your log at time by running tail -f log/derain_sde/train_derain_sde_***.log -n 100.

Evaluation

To evaluate our method, please modify the benchmark path and model path and run

cd codes/config/deraining
python test.py -opt=options/test/ir-sde.yml

We also provide the results for different tasks here.

Gradio

Here we provide an app.py file for testing your own images. Before that, you need to download the pretrained weights and modify the model path in test_sde_derain.yml. Then by simply running python app.py, you can open http://localhost:7860 to test the model. (We also provide 3 raining images from Rain100H in images dir).

Some Results

IR-SDE

HR Non-Homogeneous Dehazing

Refusion

Image Shadow Removal

Refusion

Interpolation

We also provide a interpolation demo to perform interpolation between two images in codes/demos/interpolation.py, the usage is:

cd codes/demos
python interpolation.py -s source_image_path -t target_image_path --save save_dir

Example of interpolation:

IR-SDE

Citations

If our code helps your research or work, please consider citing our paper. The following are BibTeX references:

@article{luo2023image,
  title={Image Restoration with Mean-Reverting Stochastic Differential Equations},
  author={Luo, Ziwei and Gustafsson, Fredrik K and Zhao, Zheng and Sj{\"o}lund, Jens and Sch{\"o}n, Thomas B},
  journal={International Conference on Machine Learning},
  year={2023},
  organization={PMLR}
}

@inproceedings{luo2023refusion,
  title={Refusion: Enabling Large-Size Realistic Image Restoration with Latent-Space Diffusion Models},
  author={Luo, Ziwei and Gustafsson, Fredrik K and Zhao, Zheng and Sj{\"o}lund, Jens and Sch{\"o}n, Thomas B},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops},
  pages={1680--1691},
  year={2023}
}

Contact

E-mail: [email protected]

--- Thanks for your interest! ---

visitors

image-restoration-sde's People

Contributors

algolzw avatar erjanmx 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

image-restoration-sde's Issues

test.py

Why does GT data need to be used for testing in the deraining/test.py ? In my understanding, during testing, only LQ data is needed, and GT data cannot be involved. Maybe I didn't understand

image

help

During testing, my LQ data was 8X3X256X256, and the code could run. However, why is the dimension of the output data 1x3x256x256. Is there any way to make it output 8x3x256x256

Dataset for reproducing Gaussian image de-noising model in IR-SDE paper

Hi,

Thanks for your amazing work.

I was wondering where could I download the dataset for the Gaussian image de-noising model.

Referring to the "To evaluate the image denoising performance, we train our models on 8 294 high-quality images collected from the DIV2K (Agustsson & Timofte, 2017), Flickr2K (Timofte et al., 2017), BSD500 (Arbelaez et al., 2010), and Waterloo Exploration datasets (Ma et al., 2016)." here in your IR-SDE paper.

Thanks in advance.

SISR Inference results using the pretrained checkpoint

I tried to do the SISR test of IR-SDE on DIV2K. I am using your pretrained model and your test code. However, the png output that I obtained does not match with the results that you provided. It contains lots of noise and artifacts.

During the inference, I only changed the data path and the pretrain_model_G path in the .yml file. Is there anything that I didn't do correctly? Thanks.

Repeat 100it [00:45, 2.22it/s]

What does the repeated statement below mean? I tried to reproduce it, but I've been stuck at this point, and it seems like it doesn't finish running in a short period of time.

Path already exists. Rename it to [/root/image-restoration-sde-main/experiments/deraining/ir-sde_archived_231005-125919]
cosine schedule
100it [00:30, 3.29it/s]
100it [00:25, 3.88it/s]
100it [00:47, 2.10it/s]
100it [00:43, 2.32it/s]
100it [00:25, 3.88it/s]
100it [00:41, 2.44it/s]
100it [00:52, 1.92it/s]
100it [00:51, 1.96it/s]
100it [00:45, 2.22it/s]
100it [00:48, 2.06it/s]
100it [00:45, 2.22it/s]
100it [00:45, 2.22it/s]
100it [00:45, 2.22it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
100it [00:42, 2.36it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
100it [00:45, 2.22it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
100it [00:45, 2.22it/s]
100it [00:25, 3.88it/s]
100it [00:25, 3.88it/s]
36it [00:09, 3.85it/s]

reproduce the rain100H result

您好,这是我用两张3090运行训练rain100H的validation的log,代码需要迭代70w次,我中途迭代到38w次,psnr是在25.5附近(暂未训练完),感觉难以复现到论文的31.65,想排查下原因(没有改动代码,不清楚log是否正常,感觉不太稳定),方便上传您训练的log么;另外,train.py代码中的dataset_ratio多卡训练参数默认是200,是否需要调整,会对结果产生很大的影响么。
UUZP`PQV_CTKAOJ(O3RC$WH

祝好,期待您的解答!

Deblurring code

Thank you for your fantastic work.
When will you be sharing your deblurring and SR code/configs?

The Problem of Loss Function

Thank you for opening up your work!

I have some questions about the loss function .ddpm’s label should be a prior information of gradually increasing noise. How did you modify it to calculate the loss between the enhanced image and the label image, which is reflected in the code?
This place has always confused me,Looking forward to your reply,thank you!

分布式训练错误

当使用分布式训练latent-dehazing 模型时,在时间编码部分出现emb = x[:, None] * emb[None, :]
IndexError: too many indices for tensor of dimension 0 这时x为空。这个错误在单卡训练时并没有出现。

app.py

When I Run app.py There are these erros. Thank you

Traceback (most recent call last):
File "E:\image-restoration-sde-main\image-restoration-sde-main\codes\config\deraining\app.py", line 16, in
opt = option.parse(parser.parse_args().opt, is_train=False)
File "E:\image-restoration-sde-main\image-restoration-sde-main\codes\config\deraining\options.py", line 67, in parse
config_dir = path.split("/")[-2]
IndexError: list index out of range

shadow removal dataset

very nice work! i'm sorry to bother you, but i can't find the dataset you used in shadow removal task according to the references in your paper. could you please give me a link or other information about it? thanks very much

dehaze

What are the metrics obtained by your method on the dehazing dataset (outdoor and indoor)

关于 list index out of range

在运行 python3 train.py -opt=options/train/ir-sde.yml,出现
Traceback (most recent call last):
File "E:\matlab\image-restoration-sde-main\codes\config\deblurring\train.py", line 319, in
main()
File "E:\matlab\image-restoration-sde-main\codes\config\deblurring\train.py", line 52, in main
opt = option.parse(args.opt, is_train=True)
File "E:\matlab\image-restoration-sde-main\codes\config\deblurring\options.py", line 68, in parse
config_dir = path.split("/")[-2]
IndexError: list index out of range

关于inpainting任务超参数的问题

您好,我尝试使用您提供的代码复现inpainting的训练,但是发现出图效果远差于官方提供的pth。请问一下inpainting的实验大概训练多机才会收敛?超参数应该怎么设置呢?

Dataset

The link to the datasets can't be opened.

关于dehazing

您好,麻烦请教一下在Image Restoration with Mean-Reverting Stochastic Differential Equations附录中
image
在indoor数据集上的结果是采用哪个代码进行训练的呢?是否有预训练模型呀?

如何通过HQ获取退化后的LQ?

根据论文,模型是先通过HQ获得LQ',再由LQ‘反向推理HQ'。我想简单改变模型结构,训练一个退化模型,即由HQ获取LQ‘,请问我该如何处理?感谢指导!

Dataset preparation

How should a custom dataset structured? For example, i have a gt image and an image with blur applied at random places. Should i also have the mask for blur regions? And how should i structure this dataset?
Thanks for your efforts.

IndexError: list index out of range

/c/image-restoration-sde-main/codes/config/denoising-sde
$ python test.py -opt=options/test/ir-sde.yml
export CUDA_VISIBLE_DEVICES=0
Traceback (most recent call last):
  File "C:\image-restoration-sde-main\codes\config\denoising-sde\test.py", line 25, in <module>
    opt = option.parse(parser.parse_args().opt, is_train=False)
  File "C:\image-restoration-sde-main\codes\config\denoising-sde\options.py", line 60, in parse
    config_dir = path.split("/")[-2]
IndexError: list index out of range

How can I fix this? Thanks

dehaze results

Can dehazing results for SOTS and NTIRE datasets be available?

name 'OrderedYaml' is not defined

Hello, thank you very much for your contribution. When I ran the inpainting code, the following error occurred (my system is a Linux system)
2023-05-21 11-50-04 的屏幕截图

AssertionError: datasets/rain/trainH/LQ is not a valid directory

I set up the dataset according to the operation you provided, but the following error still occurred at runtime, do you know why, thank you

Traceback (most recent call last):
File "train.py", line 319, in
main()
File "train.py", line 156, in main
train_set = create_dataset(dataset_opt)
File "/LF/image-restoration-sde/codes/config/deraining/../../data/init.py", line 45, in create_dataset
dataset = D(dataset_opt)
File "/LF/image-restoration-sde/codes/config/deraining/../../data/LQGT_dataset.py", line 40, in init
self.LR_paths = util.get_image_paths(
File "/LF/image-restoration-sde/codes/config/deraining/../../data/util.py", line 48, in get_image_paths
paths = sorted(_get_paths_from_images(dataroot))
File "/LF/image-restoration-sde/codes/config/deraining/../../data/util.py", line 19, in _get_paths_from_images
assert os.path.isdir(path), '{:s} is not a valid directory'.format(path)
AssertionError: datasets/rain/trainH/LQ is not a valid directory

NameError: name 'OrderedYaml' is not defined

May I ask if anyone has encountered this problem?
Traceback (most recent call last):
File "E:\Pythonfiles\image-restoration-sde-main\codes\config\deraining\train.py", line 16, in
import config.deraining.options as option
File "E:\Pythonfiles\image-restoration-sde-main\codes\config\deraining\options.py", line 15, in
Loader, Dumper = OrderedYaml()
NameError: name 'OrderedYaml' is not defined

image inpainting复现的问题

你好,我使用官方提供的ckpt在celebA数据集上做推理,发现我无法复现您提供的结果。我使用的脚本是inpainting 中的test.py

ablation experiments for latent-replacing pretraining strategy

I don't see the ablation experiments in the paper “Refusion: Enabling Large-Size Realistic Image Restoration with Latent-Space Diffusion Models” about the latent-replacing pretraining strategy and I would like to know how much impact this strategy brings, can you provide comparison results?

need dehazing pre-trained model

Hi,

can you please share pre-trained dehazing model? the existing latent-dehazing.pth is not generating the results as you have shown in the document.

Thanks

torch.cuda.OutOfMemoryError

Thank you for your fantastic work.
I have only a 3060, I set the batchsize 2, but happens OutOfMemoryError at 5000 iters, where can I modify the code to run?

就Deraining在训练和测试时分别输送到网络的shape区别向学长请教!

罗学长,你好,我注意到在训练的过程中,若配置文件指定参数GT_size: 128 则输送到网络前,图像会进行裁剪(128)等数据增强,而后在unet中再进行适当的padding;而在测试过程中,若直接使用您分享的checkpoint以及相应的测试yml文件,除了在unet中有相应的padding,是不需要对图像做相应操作的,如测试集中的单张图像shape为[1,3,321,481],
我的问题是,训练过程中输送给unet的shape是[b,c,128,128] 测试时输送给unet的shape是[b,c,336,496] (根据默认的yml文件计算)? 所以,unet 所保存的权重仅仅是那些卷积核权重等,不会受到输入的shape的变化所影响,而只受到通道变化的影响?不知道我这样理解的对不对?
如果是这样的话,我的疑问便是,resolution的变化会不会对扩散模型学习的分布有所影响呢?

Bokeh model does not work

I'm having a trouble making bokeh model work. The corresponding script for this model (/codes/config/latent_bokeh/test.py) doesn't seem to be correct - there are multiple places where it fails, can anybody confirm that it should work?

The following output was obtained using these parameters:

  • src_lens: 160
  • tgt_lens: 14
  • disparity: 50

Gradio produces wrong picture with the config codes/config/latent_bokeh/options/bokeh/test/refusion.yml:
Screenshot 2023-06-13 at 0 05 11

How to determine the max_sigma

Hi Algolzw,
I wonder you how to determine the max_sigma and surrogate differentiable function (20).
Could you explain in detail if it's decided by something?

去除路面上的阴影没效果

大佬您好,我在使用您的去阴影的模型去除您论文中的阴影图片的效果挺好的,但是去除我们这边应用场景中的图片感觉没啥效果,下面是我们使用场景的图片以及使用这个算法去除阴影后的效果
包含阴影的图片
1
使用该算法去除阴影后的图片
1

请问下这个算法能去除户外路面上的阴影吗

就latent-diffusion在大尺度图像上超分任务的一些疑问向学长请教

学长好,以latent-dehazing的任务为例,图像大小是[1,3,6000,4000], 学长所给的配置文件中LR-size和GT-size均为1024,并给出了latent_diffusion的预训练权重。我的理解是:
1、训练时,进来的图像[3,6000,4000]会经过随机裁剪以及对称旋转等数据增强得到[3,1024,1024],而后经过latent_unet得到[8,750,500]的隐表示,再走扩散流程来训练;
2、测试时,进来的图像[3,6000,4000]会经过中心裁剪得到[1024,1024],latent-unet得到隐表示[8,750,500],采样生成[8,750,500],再经过latent-unet解码得到[3,1024,1024]
我的疑问是,最后的采样结果是 [1,1024,1024] 最后恢复到 [3,6000,4000]的图像呢?

3、我尝试复现unet-latent,但我发现其对应haze的配置文件,其GT-size居然是256,那么在隐表示岂不是仅仅有32的像素大小,我是否应该调整配置参数 使其与latent-dehazing配置文件的数据参数(GT-SIZE等)保持一致,且latent-dehazing的network_L参数与unet-latent的network_G参数设置保持一致?

4、另外,我发现在一张4090上跑batch=1的任务(除deraining)都会爆显存,这正常吗?因为学长的实验在40GB的显存,batch都能开到4
再次期待学长的耐心解答!!!

About IR-SDE pretrained models question...

感谢您的工作,请问提供的模型文件中,pretrained_models下的模型是在哪个数据集上预训练的?

~~ 另外每个task预训练用到的数据一样吗?如果不一样,用的数据分别是什么?

最后有个小请求,请问可以在百度云盘上分享一份模型文件吗?Google云盘下载有点困难,感谢~~

For deblurring

Thank you for reading this review in his busy schedule.
I would like to ask how should I go about running the code deblurring.
Thank you very much!

image inpainting

Hi, there is an image inpainting task in the code, but I can't seem to find the relevant section in the paper.

About Refusion

Hello, for your Refusion method, I can't seem to find the corresponding part in your paper in the code, such as the part described in the article using GT and LQ to get latent features. I refer to your demo files in each task, and found that just changing the .yml can switch between IR-SDE and Refusion, but I can't find the difference with the IR-SDE method except the backbone network for predicting noise.

But when I looked at the unet-latent file in your project, I found that you separated this part of the code. My question is, did you train the latent model and diffusion separately?

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.