Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions ISR/models/rrdn.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -131,29 +131,25 @@ def _RRDB(self, input_layer, t):

# SUGGESTION: MAKE BETA LEARNABLE
x = input_layer

for d in range(1, self.D + 1):
LFF = self._dense_block(x, d, t)
LFF_beta = Lambda(lambda x: x * self.beta)(LFF)
LFF_beta = MultiplyBeta(self.beta)(LFF)
x = Add(name='LRL_%d_%d' % (t, d))([x, LFF_beta])
x = Lambda(lambda x: x * self.beta)(x)
x = MultiplyBeta(self.beta)(x)
x = Add(name='RRDB_%d_out' % (t))([input_layer, x])
return x

def _pixel_shuffle(self, input_layer):
""" PixelShuffle implementation of the upscaling part. """

x = Conv2D(
self.c_dim * self.scale ** 2,
kernel_size=3,
padding='same',
kernel_initializer=self.initializer,
name='PreShuffle',
)(input_layer)
return Lambda(
lambda x: tf.nn.depth_to_space(x, block_size=self.scale, data_format='NHWC'),
name='PixelShuffle',
)(x)

return PixelShuffle(self.scale)(x)

def _build_rdn(self):
LR_input = Input(shape=(self.patch_size, self.patch_size, 3), name='LR_input')
Expand Down Expand Up @@ -191,3 +187,33 @@ def _build_rdn(self):
name='SR',
)(PS)
return Model(inputs=LR_input, outputs=SR)

class PixelShuffle(tf.keras.layers.Layer):
def __init__(self, scale, *args, **kwargs):
super(PixelShuffle, self).__init__(*args, **kwargs)
self.scale = scale

def call(self, x):
return tf.nn.depth_to_space(x, block_size=self.scale, data_format='NHWC')

def get_config(self):
config = super().get_config().copy()
config.update({
'scale': self.scale,
})
return config

class MultiplyBeta(tf.keras.layers.Layer):
def __init__(self, beta, *args, **kwargs):
super(MultiplyBeta, self).__init__(*args, **kwargs)
self.beta = beta

def call(self, x, **kwargs):
return x * self.beta

def get_config(self):
config = super().get_config().copy()
config.update({
'beta': self.beta,
})
return config