leftthomas / srgan Goto Github PK
View Code? Open in Web Editor NEWA PyTorch implementation of SRGAN based on CVPR 2017 paper "Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network"
License: MIT License
A PyTorch implementation of SRGAN based on CVPR 2017 paper "Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network"
License: MIT License
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.
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?
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))?
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.
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!
Hi,
I've trained my SRResnet on DIV2K and during testing I've tried SET14.
Here is my resulting image
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?
It seems baidu had removed the result image and video contents.
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)
I'm unable to download the dataset from given link. The links are in chinese language and we are unable to understand and to convert it .
Thank you for providing your srgan code. I am now using your model as a baseline model to compare the quality between different methods. Would you mind providing download link for your pretrained model? THX.
In the discriminator loss and generator loss, isn't there a log function missing before the mean?
In the SRGAN paper in eq. 2 there is a log function.
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?
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?
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.
I notice that in the paper, they use vgg19 for perceptual loss. In the loss.py, vgg16 is used.
In your code, d_loss = 1 - real_out + fake_out and I cannot understand this line code. Can you explain it?
why is valid_crop_size calculated by crop_size - (crop_size % upscale_factor)??
There is no for me or someone else who have the same issue of registration to get access to your data.
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
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?
我训练到第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:
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".
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.
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
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
I want to super resolute the images with 8 upscaling factor. How can I do this?
[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?
Hello, I check your loss function in train process, seems not different with paper, is it special point to get higher quality than paper?
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 !
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 ⨯
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:
I don't really see any difference between the two.
Is this a normal behavior? Thank you.
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)
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
`
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
The code do not include that how to get the test data and test target, can you add it?THX
Thank you for your codes.
I want to modify the hyperparameters, like learning rate of G or D.
Where is the code?
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.
calculate the psnr on y_channel using y,,=Image.open('').convert('YCbCr').split()but that refers to the JPEG, and not the ITU-R BT.2020, standard,
this result is different from the paper matlab version.can we solve it?
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.
I am trying on the SR of the image containing text now, but is there a problem using the pre-training model of VGG16? Are there other more appropriate models? Can you teach me any good ideas?
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 ?
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 ?
Test with my own dataset
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.