Code Monkey home page Code Monkey logo

ffa-net's Introduction

Official implementation.


by Xu Qin, Zhilin Wang et al. Peking University and Beijing University of Aeronautics & Astronautics.

Citation

@inproceedings{qin2020ffa,
title={FFA-Net: Feature fusion attention network for single image dehazing},
author={Qin, Xu and Wang, Zhilin and Bai, Yuanchao and Xie, Xiaodong and Jia, Huizhu},
booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
volume={34},
number={07},
pages={11908--11915},
year={2020}
}

Dependencies and Installation

  • python3
  • PyTorch>=1.0
  • NVIDIA GPU+CUDA
  • numpy
  • matplotlib
  • tensorboardX(optional)

Datasets Preparation

Dataset website:RESIDE ; Paper arXiv version:[RESIDE: A Benchmark for Single Image Dehazing]

FILE STRUCTURE
    FFA-Net
    |-- README.md
    |-- net
    |-- data
        |-- RESIDE
            |-- ITS
                |-- hazy
                    |-- *.png
                |-- clear
                    |-- *.png
            |-- OTS 
                |-- hazy
                    |-- *.jpg
                |-- clear
                    |-- *.jpg
            |-- SOTS
                |-- indoor
                    |-- hazy
                        |-- *.png
                    |-- clear
                        |-- *.png
                |-- outdoor
                    |-- hazy
                        |-- *.jpg
                    |-- clear
                        |-- *.png

Metrics update

Methods Indoor(PSNR/SSIM) Outdoor(PSNR/SSIM)
DCP 16.62/0.8179 19.13/0.8148
AOD-Net 19.06/0.8504 20.29/0.8765
DehazeNet 21.14/0.8472 22.46/0.8514
GFN 22.30/0.8800 21.55/0.8444
GCANet 30.23/0.9800 -/-
Ours 36.39/0.9886 33.57/0.9840

Usage

Train

Remove annotation from main.py if you want to use tensorboard or view intermediate predictions

If you have more computing resources, expanding bs, crop_size, gps, blocks will lead to better results

train network on ITS dataset

python main.py --net='ffa' --crop --crop_size=240 --blocks=19 --gps=3 --bs=2 --lr=0.0001 --trainset='its_train' --testset='its_test' --steps=500000 --eval_step=5000

train network on OTS dataset

python main.py --net='ffa' --crop --crop_size=240 --blocks=19 --gps=3 --bs=2 --lr=0.0001 --trainset='ots_train' --testset='ots_test' --steps=1000000 --eval_step=5000

Test

Trained_models are available at baidudrive: https://pan.baidu.com/s/1-pgSXN6-NXLzmTp21L_qIg with code: 4gat

or google drive: https://drive.google.com/drive/folders/19_lSUPrpLDZl9AyewhHBsHidZEpTMIV5?usp=sharing Put models in the net/trained_models/folder.

Put your images in net/test_imgs/

python test.py --task='its or ots' --test_imgs='test_imgs'

Samples

ffa-net's People

Contributors

ninesun127 avatar zhilin007 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

ffa-net's Issues

Incompatible tensor shape in FFA.py?

Hi,

Thanks for open-sourcing your work. I was trying to write a TensorFlow implementation of your model, and ran into the following issue.

In FFA.py, you have the code below at L96:

w=w.view(-1,self.gps,self.dim)[:,:,:,None,None]
out=w[:,0,::]*res1+w[:,1,::]*res2+w[:,2,::]*res3

Questions:

  1. After the first line, tensor w will have shape [B, gps, dim, 1, 1], where B is the batch size. Is that correct?
  2. Subsequently, in the second line, w[:, 0, ::] has shape [B, dim, 1, 1]. Correct?
  3. But res1 has shape [B, H, W, dim], where H and W are the spatial dimensions. How could you multiply w[:, 0, ::] and res1 which have incompatible shapes?

Sorry if this is trivial - I normally write TensorFlow and am quite unfamiliar with the specifics about PyTorch. Thanks!

Remember to change the dataLoader before running

我不知道是上传的代码版本有问题还是别的原因,但是DataLoader确实有问题,它没有返回hazy and gt, 而是hazy和正则化的hazy(名字为clear)。 这就是为什么指标很好,但是视觉上看没有效果的原因:因为dataloader的问题,模型拟合的目标一开始就是错的。
Error in class dataloader , it should return hazy image and clear image, but dataloader returns normalized hazy image and hazy image. This is why the metrics are good, but visually ineffective: because of the dataloader, the goal of the model fitting was wrong in the first place.

Code below looks normal but "clear" is actually hazy image.

clear_name = img    
clear = Image.open(os.path.join(self.clear_dir, clear_name))  

Advised Solution:

(__init__)
self.clear_imgs_dir = os.listdir(os.path.join(path, 'GT'))
self.clear_imgs = [os.path.join(path, 'GT', img) for img in self.clear_imgs_dir]                  
(__getitem__)
clear = Image.open(self.clear_imgs[index])

attention map

Hello, how to print the channel-wise and pixel-wise feature weights map of the Group Structure output? Can it be printed in training the dataset or after training the dataset? Thank you very much!

re-implement result on RESIDE

I used your code to train and test on RESIDE V0 dataset but I got the result 0.84/20.57 (SSIM/PSNR) for indoor task. Was I wrong at any step?

Fake Experiment and Fake Paper

We have asked AAAI to recall your paper, as it's impossible to achieve the same perfmance in your paper.
Vrevision it if there is something wrong. Or we will let your college and mentor informed.
Academic fraud is shameful.

Problem of pre-trained model

Hi, thank you for releasing the code and pre-trained models.

When I test the pre-trained model ('its_train_ffa_3_19.pk') downloaded from the released website, I got
"loading state_dict for DataParallel:
Unexpected key(s) in state_dict: "module.g1.la.gamma", "module.g1.last.weight", "module.g1.last.bias", "module.g2.la.gamma", "module.g2.last.weight", "module.g2.last.bias", "module.g3.la.gamma", "module.g3.last.weight", "module.g3.last.bias"."

Do you know why?

Thanks a lot!

Regards.

Assessment result question(PSNR&SSIM)

Why is there a big difference between the same picture using the PSNR and SSIM methods here and the method provided on the RESIDE official website? What caused it?

when I run the main.py .I have this problem and can't solve it,anyone can help me?

D:\python\envs\pytorch\python.exe E:/FFA-Net-master/net/main.py
Namespace(blocks=20, bs=16, crop=False, crop_size=240, device='cpu', eval_step=5000, gps=3, lr=0.0001, model_dir='./trained_models/its_train_ffa_3_20.pk', net='ffa', no_lr_sche=False, perloss=False, resume=True, steps=100000, testset='its_test', trainset='its_train')
model_dir: ./trained_models/its_train_ffa_3_20.pk
16
E:\FFA-Net-master\net
crop size whole_img
crop size whole img
crop size whole_img
crop size whole img
log_dir : logs/its_train_ffa_3_20
model_name: its_train_ffa_3_20
train from scratch ***
Traceback (most recent call last):
File "E:/FFA-Net-master/net/main.py", line 156, in
train(net,loader_train,loader_test,optimizer,criterion)
File "E:/FFA-Net-master/net/main.py", line 62, in train
x,y=next(iter(loader_train))
File "D:\python\envs\pytorch\lib\site-packages\torch\utils\data\dataloader.py", line 346, in next
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "D:\python\envs\pytorch\lib\site-packages\torch\utils\data_utils\fetch.py", line 47, in fetch
return self.collate_fn(data)
File "D:\python\envs\pytorch\lib\site-packages\torch\utils\data_utils\collate.py", line 79, in default_collate
return [default_collate(samples) for samples in transposed]
File "D:\python\envs\pytorch\lib\site-packages\torch\utils\data_utils\collate.py", line 79, in
return [default_collate(samples) for samples in transposed]
File "D:\python\envs\pytorch\lib\site-packages\torch\utils\data_utils\collate.py", line 55, in default_collate
return torch.stack(batch, 0, out=out)
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 460 and 407 in dimension 2 at C:\w\1\s\tmp_conda_3.6_081743\conda\conda-bld\pytorch_1572941935551\work\aten\src\TH/generic/THTensor.cpp:689

Process finished with exit code 1

RESIDE数据集相关的问题

请问在室外场景的训练集、测试集中,RESIDE数据集给出的室外场景OTS训练集和室外场景测试集SOTS是有重叠的,您是如何解决的这个问题?

result on real hazy image look not good

I have use you trained models to test on real hazy image (from google) but it look not good. Have I done something wrong?
(left: hazy imge - right: prediction using ots model)
image
image
image

the effect is very different

  Hello, I train the network on my server according to your training method, the effect is very different, PSNR = 12.52, SSIM = 0.3597. What is the reason for this.

cuda out of memory

我用作者提供的代码在我的设备上运行main.py,报错内存不足,只有当我把batchsize设置为1时才能运行成功,但是我用的时TeslaV100 32G显卡,作者用的是2080Ti,作者设置的batchsize是16,为什么我的会内存不足呢,有同学遇到这个问题吗

License for this model

Thanks for sharing your great work!

I am a collector of great models. I basically collect models in the repositories below with the consent of the model authors, convert them from PyTorch to other frameworks such as TensorFlow or ONNX, and publish them.
https://github.com/PINTO0309/PINTO_model_zoo

By the way, I have already succeeded in converting your model.
PyTorch -> ONNX, TFLite, CoreML, TFJS, TF-TRT, OpenVINO, Myriad Inference Engine Blob
Screenshot 2021-10-18 08:40:05

However, I am hesitant to publish models whose license is not clear, no matter how great they are. If possible, could you please add a LICENSE file? I am assuming that I will be quoting under the license you guys specify. For example, Apache2.0, MIT, and GPLv3, etc...

Thank you. 😄

mian.py问题,提示RAM不够,我有32G呢

提示内存不够,我在任务管理器中看了内存条32g的确是将近满了,CPU90%以上,我有两个GPU,GPU0是Intel(R) HD Graphics 630约30%,GPU1是NVIDIA GeForce GTX 1050 Ti2%基本没变化,我感觉我NVIDIA显卡没派上用场,你的电脑配置是什么样的跑成功了吗,你是使用什么软件运行这个代码的?

test result

hi,The test input is the pre-processing result after normalization( tfs.Normalize(mean=[0.64, 0.6, 0.58],std=[0.14,0.15, 0.152])), while the output needs to be de-normalized to get the RGB image with the output pixel value between 0 and 255. Could you please tell me how to de-normalize it?

about trained model

If I use my own dataset for training, do I not need the model trained by the author before?
Thanks very much!

implement details

I am sorry to disturb you again.
"The number of Group Structure G is 3. In each Group Structure, we set the Basic Block Structure number as B = 19."
Why G is 3, B is 19?
Thank you very much!

code in main.py

code in main.py 19th line
why mean=[0.45627367, 0.38360259, 0.36426624]#clear?
how to calculate mean?
thank you!

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.