def wdsr(scale, num_filters, num_res_blocks, res_block_expansion, res_block_scaling, res_block): """ WDSR model edited to be single channel uint16 """ x_in = Input(shape=(None, None, 1)) x = Lambda(normalize)(x_in) # main branch # m = conv2d_weightnorm(num_filters, 3, padding='same')(x) m = conv2d_weightnorm(num_filters, 1, padding='same')(x) for i in range(num_res_blocks): m = res_block(m, num_filters, res_block_expansion, kernel_size=3, scaling=res_block_scaling) m = conv2d_weightnorm(1 * scale**2, 3, padding='same', name=f'conv2d_main_scale_{scale}')(m) m = Lambda(pixel_shuffle(scale))(m) # skip branch s = conv2d_weightnorm(1 * scale**2, 5, padding='same', name=f'conv2d_skip_scale_{scale}')(x) s = Lambda(pixel_shuffle(scale))(s) x = Add()([m, s]) x = Lambda(denormalize)(x) return Model(x_in, x, name="wdsr")
def wdsr(scale, num_filters, num_res_blocks, res_block_expansion, res_block_scaling, res_block): x_in = Input(shape=(None, None, 3)) x = Lambda(normalize)(x_in) # main branch m = Conv2D(num_filters, 3, padding='same')(x) for i in range(num_res_blocks): m = res_block(m, num_filters, res_block_expansion, kernel_size=3, scaling=res_block_scaling) m = Conv2D(3 * scale**2, 3, padding='same', name=f'conv2d_main_scale_{scale}')(m) m = Lambda(pixel_shuffle(scale))(m) # skip branch s = Conv2D(3 * scale**2, 5, padding='same', name=f'conv2d_skip_scale_{scale}')(x) s = Lambda(pixel_shuffle(scale))(s) x = Add()([m, s]) x = Lambda(denormalize)(x) return Model(x_in, x, name="wdsr")
def upsampler(x, scale, num_feats, name): up_name = name _scale = int(math.log(scale,2)) for i in range(_scale): x = Conv2D(num_feats*4, 3, padding='same', name=up_name+'/up'+str(i+1)+'/conv')(x) x = Lambda(pixel_shuffle(scale=2), name=up_name+'/up'+str(i+1)+'/pixel_shuffle')(x) return x
def upsampler_eusr(x, scale, num_feats, name): up_name = name _scale = int(math.log(scale,2)) for i in range(_scale): x_list = list() for j in range(4): x = res_module(x, num_feats, num_res=1, name=up_name+'/up'+str(i+1)+'/rm'+str(j+1)) x_list.append(x) x = concatenate(x_list, axis=3, name=up_name+'/up'+str(i+1)+'/concat') x = Lambda(pixel_shuffle(scale=2), name=up_name+'/up'+str(i+1)+'/pixel_shuffle')(x) return x
def upsample_1(x, factor, **kwargs): x = Conv2D(num_filters * (factor**2), ks, padding='same', **kwargs)(x) return Lambda(pixel_shuffle(scale=factor))(x)
def upsample(x_in, num_filters): x = Conv2D(num_filters, kernel_size=3, padding='same')(x_in) x = Lambda(pixel_shuffle(scale=2))(x) return PReLU(shared_axes=[1, 2])(x)
def dscn(starting_num_filters=64, min_filters=24, filters_decay_gamma=1.5, nin_filters=64, n_fe_layers=8, scale=4): nin_filters2 = nin_filters // 2 x_in = Input(shape=(None, None, 3)) normalised = Lambda(normalize)(x_in) # Generate the 1st layer # layer_1 = conv2d_weightnorm(num_filters, 3, padding='same', , use_bias=True, activation=prelu_activation())(x_in) # layer_1 = conv2d_block(x_in, num_filters, 3, padding='same', initial_alpha=0.1) # conv_layers = [layer_1] ############################ Build feature extraction layers ########################### conv_layers = [] total_filter_layers = 0 previous_num_filters = starting_num_filters for layer_no in range(n_fe_layers): num_filters = int( max(previous_num_filters // filters_decay_gamma, min_filters)) # Find the correct input layer input_layer = conv_layers[-1] if len(conv_layers) > 0 else normalised layer_n = conv2d_weightnorm(num_filters, 3, padding='same', use_bias=True, activation=prelu_activation())(input_layer) conv_layers.append(layer_n) total_filter_layers += num_filters previous_num_filters = num_filters feature_extraction_layer = Concatenate( name="Feature_Extraction_Layer")(conv_layers) ######################### Build Reconstruction layers ################################## A1 = conv2d_weightnorm( nin_filters, 1, padding='same', use_bias=True, activation=prelu_activation())(feature_extraction_layer) B1 = conv2d_weightnorm( nin_filters2, 1, padding='same', use_bias=True, activation=prelu_activation())(feature_extraction_layer) B2 = conv2d_weightnorm(nin_filters2, 1, padding='same', use_bias=True, activation=prelu_activation())(B1) reconstruction_layer = Concatenate(name="Reconstruction_Layer")([A1, B2]) ######################### Upsampling Layer ############################################ upsampled_conv = conv2d_weightnorm(3 * (scale**2), 5, padding='same', use_bias=True)(reconstruction_layer) upsampled_layer = Lambda(pixel_shuffle(scale))(upsampled_conv) ######################## Reconstruction Layer ########################################### denormalised = Lambda(denormalize)(upsampled_layer) model = Model(x_in, denormalised, name="dscn") return model
def upsample_1(x, factor, **kwargs): """Sub-pixel convolution.""" x = Conv2D(num_filters * (factor**2), 3, padding='same', **kwargs)(x) return Lambda(pixel_shuffle(scale=factor))(x)