Giter Site home page Giter Site logo

rajatkb / rdnsr-residual-dense-network-for-super-resolution-keras Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 8.0 36.22 MB

Residual Dense Network for Super Resolution implementation in Keras

License: Apache License 2.0

Python 100.00%
super-resolution deep-learning residual-networks densenet

rdnsr-residual-dense-network-for-super-resolution-keras's Introduction

RDNSR-Residual-Dense-Network-for-Super-Resolution-Keras

Residual Dense Network for Super Resolution implementation in Keras
Original Paper : RDNSR


Model

The standard model and the RDB blocks

for each conv block the channel count = 64 and filter is (3,3) unless mentiond by the network
otherwise. Skip connections are actually concatenation , the idea roots from Dense Networks
And plus signs means Local or Global

Observation

  1. The model is small considering you are using only 3 RDB blocks , in total there are only around 800000 parameters,
  2. The model can be made much deeper only it will increase the training time. Converging takes a lot of time.
  3. Also never go with the per patch PSNR, since reconstruction would reduce it. Per patch PSNR should be atleast 80
    in order to get good results i.e less noise ad more clarity in picture.
  4. Though the paper does not mentions you can either take the input layer off and have the model repeatedly
    initialized to create progressive upscalling or just change the SubPixel upscaling 'r' value in the code to
    get 4x and 8x zoom.
  5. Awesome edge recreation.
  6. Global + Local Residual Learning is an effective way of preserving gemmoteric features.

Usage

Data

In the script SRIP DATA BUILDER just point the below line to whichever folder you have your training images in

d = DATA(folder='./BSDS200_Padded' , patch_size = int(scale * 32))

It will create few npy files which training data. The training_patch_Y.npy contains the original data in patches
of 64x64 or 128x128 how you specify. In case the image provided for training is not of proper shape, the script will pad them by black borders and convert the image in patches and save them in the npy file. trainig_patches_2x contains the 2x
downscaled patches and respcitvely 4x and 8x contains the same. The noisy one is in case if you want to have
them trained on grainy and bad image sample for robust training. The lines for noisy are commented , just uncomment and maybe at them in if else.

p , r, c = DATA.patchify(img  , scale = 1)

By default patch size is 64. So
img : Input image of shape (H,W,C)
scale : scale determines the size of patch = patch_size / scale
returns : list of patches , number of rows , number of columns

Training

Just run the main.py , there are a few arguments in below format

(rajat-py3) sanchit@Alpha:~/rajatKb/SRResNet$ python main.py -h
usage: main.py [-h] [--to TRYOUT] [--ep EPOCHS] [--bs BATCH_SIZE]
               [--lr LEARNING_RATE] [--gpu GPU] [--chk CHK] [--sample SAMPLE]
               [--scale SCALE] [--data FOLDER] [--test_image TEST_IMAGE]
               [--test_only TEST_ONLY]

control RDNSR

optional arguments:
  -h, --help            show this help message and exit
  --to TRYOUT
  --ep EPOCHS
  --bs BATCH_SIZE
  --lr LEARNING_RATE
  --gpu GPU
  --chk CHK
  --sample SAMPLE
  --scale SCALE
  --data FOLDER
  --test_image TEST_IMAGE
  --test_only TEST_ONLY

The file will be looking for few images to generate test results after every try out run. So you can provide
your own test image or use one provided.

test_only activate when you dont need to train , so you just point to model checkpoint get the results.

Dataset

Date: 30 June 2018
The model is currently running on BSD300 and within 200 epochs generates image that captures the geometric shapes
really well. Though small details are still smudged much like a MSE loss function. Look in to the training section
of the paper and results section for furthur data.

Update:

Trained on DIV2K and it is given good results considering we don't zooming in pixel level, there are some pepper noises there. But cannot be seen untill 200% zoom

Results

2x results

low resolution image

bicubic image

generated image from RDN

4x results

low resolution image

bicubic image

generated image from RDN

the network has an incremental Upsampling block at the end of the features transformation and extraction and i am not sure was is the intended way of creating 4x and 8x results. But really great and well written paper from the authors. I did mailed them and they were generous enough to help me understand training details.

Train

On standard DIV2k dataset for 2x there are 32x32 640,000 input patches and corresponding high resolution patches. I took a random sample of 16,000 and went for one epoch on it with batch size of 16. If you read the paper they had a similar method. It just that they had defined 1000 iterations as one epoch for 16 batch size and i took 16000 as one epoch.

Thanks to:

https://github.com/tetrachrome/subpixel , Tetrachrome for his subpixel convolution layer in Keras. Though there were bugs
But got it working. Will read the ESPCN paper for better understanding.

rdnsr-residual-dense-network-for-super-resolution-keras's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rdnsr-residual-dense-network-for-super-resolution-keras's Issues

about noiise

hello, i noticed that your result contains irregular noise. why does this happen and have you solve it?thanks and hope your reply

error in the 164th line during testing with the pretrained weights.

The ran the line "python main.py --test_only True --gpu 1 --chk 160 --scale 2 --test_image bsds_test2.jpg" in the terminal.

Error:
File "main.py", line 187, in
net = SRResnet(lr = learning_rate,scale = scale , chk = chk)
File "main.py", line 164, in init
output = Convolution2D(filters =3 , kernel_size=(3,3) , strides=(1 , 1) , padding='same')(output)
File "/home/dip_student/miniconda3/envs/pra36/lib/python3.6/site-packages/keras/engine/base_layer.py", line 463, in call
self.build(unpack_singleton(input_shapes))
File "/home/dip_student/miniconda3/envs/pra36/lib/python3.6/site-packages/keras/layers/convolutional.py", line 141, in build
constraint=self.kernel_constraint)
File "/home/dip_student/miniconda3/envs/pra36/lib/python3.6/site-packages/keras/engine/base_layer.py", line 279, in add_weight
weight = K.variable(initializer(shape, dtype=dtype),
File "/home/dip_student/miniconda3/envs/pra36/lib/python3.6/site-packages/keras/initializers.py", line 227, in call
dtype=dtype, seed=self.seed)
File "/home/dip_student/miniconda3/envs/pra36/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 4357, in random_uniform
shape, minval=minval, maxval=maxval, dtype=dtype, seed=seed)
File "/home/dip_student/miniconda3/envs/pra36/lib/python3.6/site-packages/tensorflow/python/keras/backend.py", line 5253, in random_uniform
shape, minval=minval, maxval=maxval, dtype=dtype, seed=seed)
File "/home/dip_student/miniconda3/envs/pra36/lib/python3.6/site-packages/tensorflow/python/ops/random_ops.py", line 247, in random_uniform
rnd = gen_random_ops.random_uniform(shape, dtype, seed=seed1, seed2=seed2)
File "/home/dip_student/miniconda3/envs/pra36/lib/python3.6/site-packages/tensorflow/python/ops/gen_random_ops.py", line 820, in random_uniform
name=name)
File "/home/dip_student/miniconda3/envs/pra36/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 626, in _apply_op_helper
param_name=input_name)
File "/home/dip_student/miniconda3/envs/pra36/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 60, in _SatisfiesTypeConstraint
", ".join(dtypes.as_dtype(x).name for x in allowed_list)))
TypeError: Value passed to parameter 'shape' has DataType float32 not in list of allowed values: int32, int64.

I Tried to remove as well as find the source of the problem but failed to do so. Kindly help me resolve the issue

about model result

Hi, rajatkb

Can I know your test result based on the model you have trained ? Specificlly, what is the PSNR value on Set5 test set (or other benchmark dataset ) of x2 scale .

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.