Giter VIP home page Giter VIP logo

srgan's Introduction

SRGAN

A PyTorch implementation of SRGAN based on CVPR 2017 paper Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network.

Requirements

conda install pytorch torchvision -c pytorch
  • opencv
conda install opencv

Datasets

Train、Val Dataset

The train and val datasets are sampled from VOC2012. Train dataset has 16700 images and Val dataset has 425 images. Download the datasets from here(access code:5tzp), and then extract it into data directory.

Test Image Dataset

The test image dataset are sampled from | Set 5 | Bevilacqua et al. BMVC 2012 | Set 14 | Zeyde et al. LNCS 2010 | BSD 100 | Martin et al. ICCV 2001 | Sun-Hays 80 | Sun and Hays ICCP 2012 | Urban 100 | Huang et al. CVPR 2015. Download the image dataset from here(access code:xwhy), and then extract it into data directory.

Test Video Dataset

The test video dataset are three trailers. Download the video dataset from here(access code:956d).

Usage

Train

python train.py

optional arguments:
--crop_size                   training images crop size [default value is 88]
--upscale_factor              super resolution upscale factor [default value is 4](choices:[2, 4, 8])
--num_epochs                  train epoch number [default value is 100]

The output val super resolution images are on training_results directory.

Test Benchmark Datasets

python test_benchmark.py

optional arguments:
--upscale_factor              super resolution upscale factor [default value is 4]
--model_name                  generator model epoch name [default value is netG_epoch_4_100.pth]

The output super resolution images are on benchmark_results directory.

Test Single Image

python test_image.py

optional arguments:
--upscale_factor              super resolution upscale factor [default value is 4]
--test_mode                   using GPU or CPU [default value is 'GPU'](choices:['GPU', 'CPU'])
--image_name                  test low resolution image name
--model_name                  generator model epoch name [default value is netG_epoch_4_100.pth]

The output super resolution image are on the same directory.

Test Single Video

python test_video.py

optional arguments:
--upscale_factor              super resolution upscale factor [default value is 4]
--video_name                  test low resolution video name
--model_name                  generator model epoch name [default value is netG_epoch_4_100.pth]

The output super resolution video and compared video are on the same directory.

Benchmarks

Upscale Factor = 2

Epochs with batch size of 64 takes ~2 minute 30 seconds on a NVIDIA GTX 1080Ti GPU.

Image Results

The left is bicubic interpolation image, the middle is high resolution image, and the right is super resolution image(output of the SRGAN).

  • BSD100_070(PSNR:32.4517; SSIM:0.9191)

BSD100_070

  • Set14_005(PSNR:26.9171; SSIM:0.9119)

Set14_005

  • Set14_013(PSNR:30.8040; SSIM:0.9651)

Set14_013

  • Urban100_098(PSNR:24.3765; SSIM:0.7855)

Urban100_098

Video Results

The left is bicubic interpolation video, the right is super resolution video(output of the SRGAN).

Watch the video

Upscale Factor = 4

Epochs with batch size of 64 takes ~4 minute 30 seconds on a NVIDIA GTX 1080Ti GPU.

Image Results

The left is bicubic interpolation image, the middle is high resolution image, and the right is super resolution image(output of the SRGAN).

  • BSD100_035(PSNR:32.3980; SSIM:0.8512)

BSD100_035

  • Set14_011(PSNR:29.5944; SSIM:0.9044)

Set14_011

  • Set14_014(PSNR:25.1299; SSIM:0.7406)

Set14_014

  • Urban100_060(PSNR:20.7129; SSIM:0.5263)

Urban100_060

Video Results

The left is bicubic interpolation video, the right is super resolution video(output of the SRGAN).

Watch the video

Upscale Factor = 8

Epochs with batch size of 64 takes ~3 minute 30 seconds on a NVIDIA GTX 1080Ti GPU.

Image Results

The left is bicubic interpolation image, the middle is high resolution image, and the right is super resolution image(output of the SRGAN).

  • SunHays80_027(PSNR:29.4941; SSIM:0.8082)

SunHays80_027

  • SunHays80_035(PSNR:32.1546; SSIM:0.8449)

SunHays80_035

  • SunHays80_043(PSNR:30.9716; SSIM:0.8789)

SunHays80_043

  • SunHays80_078(PSNR:31.9351; SSIM:0.8381)

SunHays80_078

Video Results

The left is bicubic interpolation video, the right is super resolution video(output of the SRGAN).

Watch the video

The complete test results could be downloaded from here(access code:nkh9).

srgan's People

Contributors

agarkovv avatar anant15 avatar developer0hye avatar jash-maester avatar leftthomas avatar mukulkhanna 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

srgan's Issues

GPU RAM exploding on validation

Hi, first thank you for this awesome implementation.

Here's my problem, I translated your code in Pytorch 1.1, achieved a complete training on VOC2012 in order to reproduce your work. Everything worked fine.
Now I added some images to the dataset (like 5000 more) mostly scene text image, I want to improve the model performance on text reconstruction. The first epoch training works fine, I use the same batch size as before and then when the validation come the GPU memory explode after some iterations (19% of the validation loop).

I know the flag volatile=True is no longer used and I replaced it by torch.no_grad() which worked well on VOC2012.

Do you know what might go wrong with it ?
Thank you for your help !

can't reproduce 4x scaling

with default params i can't reproduce your psnr and ssim on any of the test sets. did you adjust lr, momentum, decay, etc for 4x case?

Test Scripts Not Working

Hi,

I ran the video test scripts and it completed successfully. However, I could not find the output videos anywhere on my system. Here is the output.

turanshare@deepNeuro:~/Documents/github/dev/SRGAN$ python test_video.py --video_name "/home/turanshare/Documents/github/dev/SRGAN/sample.mp4"
[processing video and saving result videos]: 100%|██████████████████████████████████████████████████████████████████████████████████| 2003/2003 [28:00<00:00,  1.19it/s]

Moreover, when I run the image test it fails with an 'out of memory' error. I am not sure why is this happening.

turanshare@deepNeuro:~/Documents/github/dev/SRGAN$ python test_image.py --image_name "/home/turanshare/Documents/github/dev/SRGAN/riz.jpg"
THCudaCheck FAIL file=/opt/conda/conda-bld/pytorch_1518238409320/work/torch/lib/THC/generic/THCStorage.cu line=58 error=2 : out of memory
*** Error in `python': free(): invalid pointer: 0x00007f273ba24ec0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f27549a87e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7f27549b137a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f27549b553c]
/home/turanshare/anaconda2/lib/python2.7/site-packages/torch/_thnn/_THCUNN.so(+0x34cb9)[0x7f26f8624cb9]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x79e5)[0x7f275570a615]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x7e9)[0x7f275570c4e9]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(+0x6cfda)[0x7f2755694fda]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f2755670773]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_CallObjectWithKeywords+0x48)[0x7f27557026d8]
/home/turanshare/anaconda2/lib/python2.7/site-packages/torch/_C.so(_Z17THPFunction_applyP7_objectS0_+0x271)[0x7f273a4a4201]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x79e5)[0x7f275570a615]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x817c)[0x7f275570adac]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x7e9)[0x7f275570c4e9]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(+0x6d0c7)[0x7f27556950c7]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f2755670773]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x28a0)[0x7f27557054d0]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x7e9)[0x7f275570c4e9]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(+0x6cfda)[0x7f2755694fda]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f2755670773]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(+0x5750d)[0x7f275567f50d]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f2755670773]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(+0xa1574)[0x7f27556c9574]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f2755670773]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x190b)[0x7f275570453b]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x7e9)[0x7f275570c4e9]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(+0x6d0c7)[0x7f27556950c7]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f2755670773]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x28a0)[0x7f27557054d0]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x7e9)[0x7f275570c4e9]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(+0x6cfda)[0x7f2755694fda]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f2755670773]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(+0x5750d)[0x7f275567f50d]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f2755670773]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(+0xa1574)[0x7f27556c9574]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f2755670773]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x190b)[0x7f275570453b]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x7e9)[0x7f275570c4e9]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(+0x6d0c7)[0x7f27556950c7]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f2755670773]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x28a0)[0x7f27557054d0]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x7e9)[0x7f275570c4e9]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(+0x6cfda)[0x7f2755694fda]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f2755670773]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(+0x5750d)[0x7f275567f50d]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f2755670773]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(+0xa1574)[0x7f27556c9574]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f2755670773]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x190b)[0x7f275570453b]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x7e9)[0x7f275570c4e9]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyEval_EvalCode+0x1a)[0x7f275570c70a]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(+0xfd93d)[0x7f275572593d]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyRun_FileExFlags+0x78)[0x7f2755726ab8]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(PyRun_SimpleFileExFlags+0xe8)[0x7f2755727cd8]
/home/turanshare/anaconda2/bin/../lib/libpython2.7.so.1.0(Py_Main+0xbac)[0x7f2755739d3c]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f2754951830]
python(+0x87f)[0x5598ccb0a87f]
======= Memory map: ========
10000000-10001000 rw-s 00000000 00:06 519                                /dev/nvidia3
10001000-10002000 rw-s 00000000 00:06 519                                /dev/nvidia3
10002000-10003000 rw-s 00000000 00:06 519                                /dev/nvidia3
10003000-10004000 rw-s 00000000 00:06 519                                /dev/nvidia3
10004000-10005000 rw-s 00000000 00:06 519                                /dev/nvidia3
10005000-10006000 rw-s 00000000 00:06 519                                /dev/nvidia3
10006000-10007000 rw-s 00000000 00:06 519                                /dev/nvidia3
10007000-10008000 rw-s 00000000 00:06 519                                /dev/nvidia3
10008000-10009000 rw-s 00000000 00:06 519                                /dev/nvidia3
10009000-1000a000 rw-s 00000000 00:06 519                                /dev/nvidia3
1000a000-1000b000 rw-s 00000000 00:06 519                                /dev/nvidia3
1000b000-1000c000 rw-s 00000000 00:06 519                                /dev/nvidia3
1000c000-1000d000 rw-s 00000000 00:06 519                                /dev/nvidia3
1000d000-1000e000 rw-s 00000000 00:06 519                                /dev/nvidia3
1000e000-1000f000 rw-s 00000000 00:06 519                                /dev/nvidia3
1000f000-10010000 rw-s 00000000 00:06 519                                /dev/nvidia3
10010000-20000000 ---p 00000000 00:00 0
200000000-200100000 rw-s 00000000 00:06 518                              /dev/nvidiactl
200100000-200200000 ---p 00000000 00:00 0
200200000-200204000 rw-s 00000000 00:06 518                              /dev/nvidiactl
200204000-200400000 ---p 00000000 00:00 0
200400000-200800000 rw-s 00000000 00:06 518                              /dev/nvidiactl
.
.
.
7f27474f4000-7f27474f5000 r--p 00010000 fc:00 464971                     /home/turanshare/anaconda2/lib/libgcc_s.so.1
7f27474f5000-7f27474f6000 rw-p 00011000 fc:00 464971                     /home/turanshare/anaconda2/lib/libgcc_s.so.1Aborted (core dumped)

Kindly, if anyone can help me with this.
Thank you.

Error when I use 1-channel image file

Hi,

I am using SRGAN "test_image.py" for a 1-channel image file. I see the following error:

"RuntimeError: Given groups=1, weight of size [64, 3, 9, 9], expected input[1, 1, 128, 128] to have 3 channels, but got 1 channels instead"

Please let me know how I can use SRGAN for 1-channel image.

If I train network from scratch with a dataset containing only 1-channel images, can I use this new model for 1-channel images?

Discriminator Loss

In your code, d_loss = 1 - real_out + fake_out and I cannot understand this line code. Can you explain it?

Error while training

Hi everyone,
I'm getting the following error while loading the data given in your train.py file. I can't even find the solution for this error. Does anyone know how to fix it? I appreciate any help/suggestions.
issue

Test image

Hi @leftthomas
Thank you for your work. I have tested the code. Below, the left image is the original, the right image is the result image. The boundaries seem not be so smooth. Could you give me some clues about this?
Thank you!
sr-4

Pretrain models

Thank you very much for your nice code.
Are the pretrain models be the ones you used in the demos?
They are the optimal models or I should retrain these models.

HR and LR split training problem

Hi , thanks for your time.I admire your work.
Nowadays , I met a strange problem.For personal reason,I must split the HR and LR images.
( In your original code, the LR images are resize from HR images , but now I want to use two folders import high-resolution and low-resolution images respectively ).
So I change your code achieve my goal , in theory it's a simple change. But the result turned out badly and I can't figure out why.
I would really appreciate it if you could take a moment to look at my questions.
Thank you.
[code.zip](https://github.com/leftthomas/SRGAN/files/2775362/code.zip)

Runtime error after train

Hi, I have an error when I load the trained model.

I did the train with my own dataset but when I try to test it I got this error.

RuntimeError: Error(s) in loading state_dict for Generator: Missing key(s) in state_dict: "block8.1.weight", "block8.1.bias". Unexpected key(s) in state_dict: "block8.2.weight", "block8.2.bias", "block8.1.conv.weight", "block8.1.conv.bias", "block8.1.prelu.weight".

test_video doesn't work

I tried the test_video script and it gets stuck at cv2.VideoWriter line. My input video's a 15sec mp4, RGB video I also tried other formats like avi. I'm running the code on an ubuntu system with 1 GPU, python3, opencv 4.1.0-pre installed.
I really appreciate any help.

Cann't run the code

For some reason, the code download can not run on my machine, I guess it's caused by environment or package versions' difference. Would the author tell the environment and package versions', including the version of python and PyTorch. Thanks a lot.

Loading pretrained weights from "epochs/" directory

Hi Thomas,

We are trying to load and test your pre-trained weights for the generator network found in epoch/ directory. However, it doesn't seem to load for us. Could the model have changed in between after you saved the weights? If so, are you able to provide the latest weights that apply to the current master branch?

Thanks.
-Naba

error when trying to run the code

When I try to do anything, whether it is scaling an image, video or whatever, this error always comes out:

Traceback (most recent call last):
File "test_video.py", line 30, in
model.load_state_dict(torch.load('epochs/' + MODEL_NAME))
File "/usr/local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 522, in load_state_dict
.format(name))
KeyError: 'unexpected key "block8.1.weight" in state_dict'

or:

Traceback (most recent call last):
File "test_video.py", line 30, in
model.load_state_dict(torch.load('epochs/' + MODEL_NAME))
File "/usr/local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 526, in load_state_dict
raise KeyError('missing keys in state_dict: "{}"'.format(missing))
KeyError: 'missing keys in state_dict: "{'block7.1.running_var', 'block7.1.bias', 'block7.1.running_mean'}"'

I use ubuntu 18.04, pytorch 0.3.1 and cuda 9

Dataset size

If I hope to train my own data set for special task(not open data set ,such as VOC), can you commend the appropriate dataset size I should have to train the model.Do you think 1000 images is too small to train a model?

would it effects the final result that feeding a input in size of 96x96 to pretrained model while the pretrained model was trained with 224x224 on imagenet ?

Hi,
I found the pretrained model you use is torchvision.models.vgg whose input size should be 224x224. And when you deploy the model to calculate the feature map, you feed HR_image whose size is 96x96 directly to the pretrained model. Obvious the two sizes are mismatched though there is no error occurs when train.
Would the slight difference influences the final result, i.e the feature maps of input image in vgg higher layer are not well represented ?

Discriminator loss plateau on DIV2K

Hello,
I'm not a GAN expert but I tried your code on the DIV2K dataset (I uploaded it on my S3 account to be easier to download) and after few epochs the discriminator loss seems to stop decreasing (which I believe means it stops giving relevant feedback to the generator). Here are the logs:

[12/100] Loss_D: 1.0234 Loss_G: 0.0090 D(x): 0.6659 D(G(z)): 0.6893: 100%|██████████████| 13/13 [00:15<00:00,  1.22s/it]
[converting LR images to SR images] PSNR: 22.3313 dB SSIM: 0.6381: 100%|██████████████| 100/100 [00:33<00:00,  3.03it/s]
[saving training results]: 100%|████████████████████████████████████████████████████████| 20/20 [00:14<00:00,  1.40it/s]
[13/100] Loss_D: 1.0124 Loss_G: 0.0082 D(x): 0.6671 D(G(z)): 0.6795: 100%|██████████████| 13/13 [00:16<00:00,  1.26s/it]
[converting LR images to SR images] PSNR: 22.1826 dB SSIM: 0.6464: 100%|██████████████| 100/100 [00:32<00:00,  3.04it/s]
[saving training results]: 100%|████████████████████████████████████████████████████████| 20/20 [00:14<00:00,  1.42it/s]
[14/100] Loss_D: 1.0271 Loss_G: 0.0091 D(x): 0.6130 D(G(z)): 0.6401: 100%|██████████████| 13/13 [00:16<00:00,  1.23s/it]
[converting LR images to SR images] PSNR: 21.5150 dB SSIM: 0.6378: 100%|██████████████| 100/100 [00:33<00:00,  3.03it/s]
[saving training results]: 100%|████████████████████████████████████████████████████████| 20/20 [00:14<00:00,  1.41it/s]
...
[97/100] Loss_D: 1.0000 Loss_G: 0.0044 D(x): 1.0000 D(G(z)): 1.0000: 100%|██████████████| 13/13 [00:16<00:00,  1.26s/it]
[converting LR images to SR images] PSNR: 24.2824 dB SSIM: 0.7469: 100%|██████████████| 100/100 [00:33<00:00,  3.03it/s]
[saving training results]: 100%|████████████████████████████████████████████████████████| 20/20 [00:13<00:00,  1.44it/s]
[98/100] Loss_D: 1.0000 Loss_G: 0.0044 D(x): 1.0000 D(G(z)): 1.0000: 100%|██████████████| 13/13 [00:16<00:00,  1.27s/it]
[converting LR images to SR images] PSNR: 22.9190 dB SSIM: 0.7432: 100%|██████████████| 100/100 [00:33<00:00,  3.01it/s]
[saving training results]: 100%|████████████████████████████████████████████████████████| 20/20 [00:13<00:00,  1.44it/s]
[99/100] Loss_D: 1.0000 Loss_G: 0.0047 D(x): 1.0000 D(G(z)): 1.0000: 100%|██████████████| 13/13 [00:16<00:00,  1.27s/it]
[converting LR images to SR images] PSNR: 24.6174 dB SSIM: 0.7501: 100%|██████████████| 100/100 [00:33<00:00,  3.03it/s]
[saving training results]: 100%|████████████████████████████████████████████████████████| 20/20 [00:13<00:00,  1.44it/s]
[100/100] Loss_D: 1.0000 Loss_G: 0.0044 D(x): 1.0000 D(G(z)): 1.0000: 100%|█████████████| 13/13 [00:16<00:00,  1.27s/it]
[converting LR images to SR images] PSNR: 24.8851 dB SSIM: 0.7500: 100%|██████████████| 100/100 [00:32<00:00,  3.04it/s]

At some point the SSIM metric will not improve above ~0.75 and the PSNR above ~24/25.
Here is an example of an image augmented with the test_image.py script after training for 100 epochs:

The original image

img_1190

The SR image

out_srf_4_img_1190

I don't really see any difference between the two.
Is this a normal behavior? Thank you.

Alternative download links?

Hello,
Is it possible that you upload the train/val/test datasets to something else than baidu? I'm not chinese and each time I try to download what appears to be the dataset I actually download an executable file. I don't want to install anything on my computer, just download the datasets. Thanks.

Some matters that need further discussion?

1.RGB->YCbCr
has many different standard,while the past papers's transfer style is different from the Image.convert function.

2.pillow vs matlab
matlab's resize function to produce the LR image is different from the pillow Image.resize(image.bicubic).
I have test the LR image pillow and DIV2K provided,some pixel value is different

3.when test the benchmark,the crop size should be the rectange rather than squre(valid_crop_size)

4.I will extend my greatest the appreciation if you can offer an complete code that achieve the same metric on benchmark dataset as SR paper

Some KeyError raised when I test single image

I executed the test_image.py to test the model on my own image whose size is 256 * 256 * 3.
When I set the upscale factor to 2, the following KeyError occured:
Traceback (most recent call last):
File "test_image.py", line 26, in
model.load_state_dict(torch.load('epochs/' + MODEL_NAME))
File "/home/gasoon/anaconda3/envs/vd/lib/python3.6/site-packages/torch/nn/modules/module.py", line 522, in load_state_dict
.format(name))
KeyError: 'unexpected key "block8.1.conv.weight" in state_dict'

After I changed the upsacle factor to 4, the following KeyError occured:
Traceback (most recent call last):
File "test_image.py", line 26, in
model.load_state_dict(torch.load('epochs/' + MODEL_NAME))
File "/home/gasoon/anaconda3/envs/vd/lib/python3.6/site-packages/torch/nn/modules/module.py", line 522, in load_state_dict
.format(name))
KeyError: 'unexpected key "block8.2.conv.weight" in state_dict'

My pytorch version is 0.3.1 and my python version is 3.6.5
Could anyone tell me how to fix the problem?

D loss & D(X)&D(G(X)) is "1"

我训练到第6个epoch开始Loss_D,D(x), D(G(z)) 就不再变化了,一直是1,只有lossG还在变化,,请问是什么原因呢?
输出的结果如下:
[12/100] Loss_D: 1.0000 Loss_G: 0.0071 D(x): 1.0000 D(G(z)): 1.0000:

where is the learning rate?

Thank you for your codes.
I want to modify the hyperparameters, like learning rate of G or D.
Where is the code?

why D(x) and D(G(z)) estimate all images 1?

VOC12

Recently, I visualize the training stage of Loss in SRGAN.
I use the same code and same dataset (16700 images) from VOC12.
However, I get the training stage as above shown.
What wrong with the experiments?

A simple question

Thanks your works, but I have a simple question that how to keep the same size of input image with output image. I found your result is a same size picture that input,output,origin not enlarge the picture.
image

RuntimeError: cuda runtime error

[converting LR images to SR images] PSNR: 20.9384 dB SSIM: 0.5722: 1%| | 1/176[converting LR images to SR images] PSNR: 20.4518 dB SSIM: 0.5069: 1%| | 2/176[converting LR images to SR images] PSNR: 21.5431 dB SSIM: 0.5412: 2%| | 3/176[converting LR images to SR images] PSNR: 22.1938 dB SSIM: 0.5864: 2%| | 4/176[converting LR images to SR images] PSNR: 21.0993 dB SSIM: 0.5593: 3%| | 5/176 [00:00<00:34, 5.00it/s]THCudaCheck FAIL file=/opt/conda/conda-bld/pytorch_1501972792122/work/pytorch-0.1.12/torch/lib/THC/generic/THCStorage.cu line=66 error=2 : out of memory
Traceback (most recent call last):
File "train.py", line 119, in
sr = netG(lr)
File "/home/zbp/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.py", line 206, in call
result = self.forward(*input, **kwargs)
File "/home/zbp/linge/SRGAN/model.py", line 37, in forward
block8 = self.block8(block1 + block7)
File "/home/zbp/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.py", line 206, in call
result = self.forward(*input, **kwargs)
File "/home/zbp/anaconda2/lib/python2.7/site-packages/torch/nn/modules/container.py", line 64, in forward
input = module(input)
File "/home/zbp/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.py", line 206, in call
result = self.forward(*input, **kwargs)
File "/home/zbp/anaconda2/lib/python2.7/site-packages/torch/nn/modules/conv.py", line 237, in forward
self.padding, self.dilation, self.groups)
File "/home/zbp/anaconda2/lib/python2.7/site-packages/torch/nn/functional.py", line 40, in conv2d
return f(input, weight, bias)
RuntimeError: cuda runtime error (2) : out of memory at /opt/conda/conda-bld/pytorch_1501972792122/work/pytorch-0.1.12/torch/lib/THC/generic/THCStorage.cu:66

Thanks for your nice code,but I have some issues about runtime error when training.Can you help me to solve this problem?

about loss function

Hello, I check your loss function in train process, seems not different with paper, is it special point to get higher quality than paper?

How do you init the model weights?

Hi! I check the code but don't find anything about how to init weights. Do you just inherit it from nn.Module? But the model performance seems to be too good at just a few epochs if it is random init.

Output image

Hi,
I've trained my SRResnet on DIV2K and during testing I've tried SET14.
Here is my resulting image
output

My image is having this weird green/blue pixels around sharp and bright regions.Is this because my model isn't working well or do i need to perform further processing on my output?
What do u suggest?

Wrong loss on discriminator

Hey! I found that when optimizing the discriminator its loss is defined as:
d_loss = 1-real_out+fake_out
which translates into D(G(z))+1-D(x). Shouldn't it be:
d_loss = 1+real_out-fake_out
so it matches the discriminator definition D(x)+1-D(G(z))?

how do you get the PSNR and SSIM value

Sorry to bother you that , I am wondering how you calculated these evaluation indicators? Do you use the function already written in the MATLAB or you just write by yourself? If you write by yourself,will you upload to github?
waiting for your reply ~ thx

What is the version of pytorch and torchvision?

Could you tell me the versions of pytorch and torchvision? The following error has occurred.

⋊> ~/SRGAN on master ⨯   python train.py                                                                                                 0909:00:51
Traceback (most recent call last):
  File "train.py", line 14, in <module>
    from data_utils import TrainDatasetFromFolder, ValDatasetFromFolder, display_transform
  File "/root/SRGAN/data_utils.py", line 6, in <module>
    from torchvision.transforms import Compose, RandomCrop, ToTensor, ToPILImage, CenterCrop, Resize
ImportError: cannot import name 'Resize'
⋊> ~/SRGAN on master ⨯

scratchpad.cpp on mkl-dnn error

Hi,

First thank you for your amazing work. I have been trying your implementation these last few weeks, everything worked as expected and yesterday I got a c++ error.

I only use your inference script:

import argparse
import time
import os
import torch
from PIL import Image
from torch.autograd import Variable
from torchvision.transforms import ToTensor, ToPILImage

from model import Generator

parser = argparse.ArgumentParser(description='Test Single Image')
parser.add_argument('--upscale_factor', default=2, type=int, help='super resolution upscale factor')
parser.add_argument('--test_mode', default='CPU', type=str, choices=['GPU', 'CPU'], help='using GPU or CPU')
parser.add_argument('--folder_name', type=str, help='test low resolution folder name')
parser.add_argument('--model_name', default='netG_epoch_2_100.pth', type=str, help='generator model epoch name')
opt = parser.parse_args()

UPSCALE_FACTOR = opt.upscale_factor
TEST_MODE = True if opt.test_mode == 'GPU' else False
FOLDER_NAME = opt.folder_name
MODEL_NAME = opt.model_name

model = Generator(UPSCALE_FACTOR).eval()
if TEST_MODE:
    model.cuda()
    model.load_state_dict(torch.load('epochs/' + MODEL_NAME))
else:
    model.load_state_dict(torch.load('epochs/' + MODEL_NAME, map_location=lambda storage, loc: storage))

start = time.time()
for file in os.listdir(FOLDER_NAME):
    out_path = FOLDER_NAME[:-1] + "_sr" if FOLDER_NAME[-1] == "/" else FOLDER_NAME + "_sr"
    output = os.path.join(f"{out_path}", file)
    if os.path.exists(output): continue
    path = os.path.join(FOLDER_NAME, file)
    image = Image.open(path).convert('RGB')
    with torch.no_grad():
        image = Variable(ToTensor()(image)).unsqueeze(0)
        if TEST_MODE:
            image = image.cuda()
        out = model(image)
        out_img = ToPILImage()(out[0].data.cpu())
    if not os.path.isdir(out_path): os.mkdir(out_path)
    out_img.save(output)

elapsed = (time.time() - start)
print('cost' + str(elapsed) + 's')

python: /opt/conda/conda-bld/pytorch_1549630534704/work/third_party/ideep/mkl-dnn/src/common/scratchpad.cpp:63: mkldnn::impl::global_scratchpad_t::global_scratchpad_t(size_t): Assertion 'scratchpad_ != nullptr' failed.

Have you ever seen something like this ?

Error when train with new dataset

after terminal python train.py, appear error below, i don't find error ? Can you help me? thank you!
`/usr/lib/python3/dist-packages/requests/init.py:80: RequestsDependencyWarning: urllib3 (1.23) or chardet (3.0.4) doesn't match a supported version!
RequestsDependencyWarning)

generator parameters: 734092

discriminator parameters: 5215425

0%| | 0/1 [00:00<?, ?it/s]Traceback (most recent call last):
File "train.py", line 60, in
for data, target in train_bar:
File "/home/neosai/.local/lib/python3.6/site-packages/tqdm/_tqdm.py", line 930, in iter
for obj in iterable:
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 336, in next
return self._process_next_batch(batch)
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 357, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
ValueError: Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 106, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 106, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/neosai/Documents/github/GAN/SRGAN/data_utils.py", line 50, in getitem
hr_image = self.hr_transform(Image.open(self.image_filenames[index]))
File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/transforms.py", line 49, in call
img = t(img)
File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/transforms.py", line 421, in call
i, j, h, w = self.get_params(img, self.size)
File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/transforms.py", line 399, in get_params
`

Error in loading the data

Hi,
I'm getting the following error while loading the data given in your train.py file. I can't even find the solution for this error. Can you help?

image

RuntimeError:

hello!
When I run the program, I encounter the following errors. I hope you can give me an answer.Thanks!

RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

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.