SRGAN icon indicating copy to clipboard operation
SRGAN copied to clipboard

How just enhance an image, without increasing the resolution?

Open ontheway16 opened this issue 6 years ago • 35 comments

Hello, Is there a way to modify this code to produce just an enhanced image, without increasing the actual resolution? There may be cases where the input image have good enough resolution to contain necessary details, but image quality is somehow detoriated. In this case, just image restoration is needed, instead of higher resolution. Any ideas?

ontheway16 avatar Apr 11 '18 16:04 ontheway16

Joining the question! And specifically, the README example seems to do exactly that - the castle images before and after appear to have same size - how this image was created?

Thanks a lot! Adva

advaza avatar May 21 '18 21:05 advaza

Hi, you can delete the last subpixel convolution, then the output size is the same with the input size.

zsdonghao avatar May 21 '18 21:05 zsdonghao

This one?

n = SubpixelConv2d(n, scale=2, n_out_channel=None, act=tf.nn.relu, name='pixelshufflerx2/2')

ontheway16 avatar May 21 '18 21:05 ontheway16

yeap

zsdonghao avatar May 21 '18 22:05 zsdonghao

I suggest you to read the paper before using this code ~

zsdonghao avatar May 21 '18 22:05 zsdonghao

After removing SubpixelConv2d, this error is showing, found_var.get_shape())) ValueError: Trying to share variable SRGAN_d/ho/dense/W, but specified shape (4608, 1) and found shape (18432, 1). Do I need to remove anything from discriminator as well ?

rahat-yasir avatar Jun 13 '18 20:06 rahat-yasir

@zsdonghao I acted as you said. However, the following error occurred : ValueError: Dimension 2 in both shapes must be equal, but are 256 and 64. Shapes are [1,1,256,3] and [1,1,64,3]. for 'Assign_171' (op: 'Assign') with input shapes: [1,1,256,3], [1,1,64,3]. What should I do? How should the source code be modified? I would appreciate your teaching.

bluewidy avatar Jul 11 '18 13:07 bluewidy

Same error here
ValueError: Dimension 2 in both shapes must be equal, but are 256 and 64. Shapes are [1,1,256,3] and [1,1,64,3]. for 'Assign_171' (op: 'Assign') with input shapes: [1,1,256,3], [1,1,64,3].

@zsdonghao could you more clarification please, and save us hours to solve this without any luck edit: i see here https://github.com/tensorlayer/srgan/issues/100, that it seem not that easy, it loke like a nightmare to make it works after all, thanks anyway

ABDOELSHEMY avatar Jul 17 '18 15:07 ABDOELSHEMY

@ABDOELSHEMY You are having the same problem as me! I tried very hard, but eventually I gave up... can you help me please?

bluewidy avatar Jul 17 '18 16:07 bluewidy

Why you have this error? @ABDOELSHEMY ? you remove one subpixel and load the pre-trained model? If yes, you can't do like that, you need to re-train the model from scratch.

zsdonghao avatar Jul 17 '18 18:07 zsdonghao

oh, i understand now, Unfortunately that is excatly what i did, remove one subpixel and simply load the pre-trained model and trying so on more than 2 hours, thank you @zsdonghao for your great clarification.

@bluewidy, as zsdonghao said, we should re-train the model after remove one subpixel.

ABDOELSHEMY avatar Jul 17 '18 19:07 ABDOELSHEMY

@all, does somebody can show enhance image result(no enlarge), I am interested in it. thank you!

suke27 avatar Jul 18 '18 02:07 suke27

@zsdonghao It was a decisive answer! Thank you! But I have a question. Is it impossible to do that with a pre-trained model? re-train the model from scratch is cumbersome and time consuming.

bluewidy avatar Jul 18 '18 19:07 bluewidy

@bluewidy we always have to re-train it..

alternatively, to make the output size smaller, you can try adding a DownSamplingLayer to the output layer.

zsdonghao avatar Jul 19 '18 15:07 zsdonghao

@zsdonghao Oh, really? That's sound great! I want to add a DownSamplingLayer! Where is output layer? model.py? or main.py?

bluewidy avatar Jul 19 '18 15:07 bluewidy

@zsdonghao I found InputLayer on model.py. However, the OutputLayer is not visible.

bluewidy avatar Jul 19 '18 15:07 bluewidy

@bluewidy the output layer means the finial layer in the model.

zsdonghao avatar Jul 19 '18 15:07 zsdonghao

@zsdonghao Aha... Thank you! I'm fool XD

bluewidy avatar Jul 19 '18 15:07 bluewidy

@zsdonghao Well ... Adding the DownSamplingLayer seems very difficult ... I'll just choice re-train the model.

bluewidy avatar Jul 19 '18 15:07 bluewidy

@zsdonghao I set up the main.py placeholder as follows.

t_image = tf.placeholder('float32', [batch_size, 96, 96, 3], name='t_image_input_to_SRGAN_generator') t_target_image = tf.placeholder('float32', [batch_size, 96, 96, 3], name='t_target_image')``

and I set up the utils.py as follow.

def crop_sub_imgs_fn(x, is_random=True): x = crop(x, wrg=96, hrg=96, is_random=is_random) x = x / (255. / 2.) x = x - 1. return x

def downsample_fn(x): # We obtained the LR images by downsampling the HR images using bicubic kernel with downsampling factor r = 4. x = imresize(x, size=[96, 96], interp='bicubic', mode=None) x = x / (255. / 2.) x = x - 1. return x``

In this case, the size of the input and output are the same. This will not increase the resolution, but will improve the quality of the image. Right?

bluewidy avatar Jul 19 '18 16:07 bluewidy

Following.

ontheway16 avatar Jul 19 '18 16:07 ontheway16

@bluewidy, you enlarge from LR, then resize to original image. I don't think it will improve the quality of image. if any progress Plz share to us.

suke27 avatar Jul 20 '18 02:07 suke27

This is original LR Image.

valid_lr

and this is SRGAN Image.

valid_gen

@suke27 here is share my result. It's really awesome.

bluewidy avatar Jul 23 '18 07:07 bluewidy

@bluewidy, based on your result, it looks like worse than original image

suke27 avatar Jul 23 '18 08:07 suke27

I've upscaled the picture with waifu2x (factor 2) and then downscaled it with ssim based perceptual downscaling. The result looks slightly different than the original: res difference: res

I think it is possible to use SRGAN instead of waifu2x.

HybridDog avatar Jul 23 '18 11:07 HybridDog

@bluewidy how did you get this result, are you add a DownSamplingLayer, or removing SubpixelConv2d and retrain the model

ABDOELSHEMY avatar Jul 24 '18 03:07 ABDOELSHEMY

@ABDOELSHEMY How do I add a DownSamplingLayer? Can you show me example?

bluewidy avatar Jul 24 '18 08:07 bluewidy

@bluewidy Unfortunately I did not success to make it work as I am not a professional in this field, if I success to make it work any time I will let you know

ABDOELSHEMY avatar Jul 24 '18 10:07 ABDOELSHEMY

@ABDOELSHEMY Thank you! XD

bluewidy avatar Jul 24 '18 11:07 bluewidy

I met the problem too.After removing SubpixelConv2d, this error is showing, found_var.get_shape())) ValueError: Trying to share variable SRGAN_d/ho/dense/W, but specified shape (2048, 1) and found shape (18432, 1). What should i do? @zsdonghao

nerdsang avatar Nov 08 '18 14:11 nerdsang