def __transition_up_block(ip, nb_filters, type='upsampling', output_shape=None, weight_decay=1E-4): ''' SubpixelConvolutional Upscaling (factor = 2) Args: ip: keras tensor nb_filters: number of layers type: can be 'upsampling', 'subpixel', 'deconv', or 'atrous'. Determines type of upsampling performed output_shape: required if type = 'deconv'. Output shape of tensor weight_decay: weight decay factor Returns: keras tensor, after applying upsampling operation. ''' if type == 'upsampling': x = UpSampling2D()(ip) elif type == 'subpixel': x = Convolution2D(nb_filters, 3, 3, activation="relu", border_mode='same', W_regularizer=l2(weight_decay), bias=False, init='he_uniform')(ip) x = SubPixelUpscaling(scale_factor=2)(x) x = Convolution2D(nb_filters, 3, 3, activation="relu", border_mode='same', W_regularizer=l2(weight_decay), bias=False, init='he_uniform')(x) elif type == 'atrous': # waiting on https://github.com/fchollet/keras/issues/4018 x = AtrousConvolution2D(nb_filters, 3, 3, activation="relu", W_regularizer=l2(weight_decay), bias=False, atrous_rate=(2, 2), init='he_uniform')(ip) else: x = Deconvolution2D(nb_filters, 3, 3, output_shape, activation='relu', border_mode='same', subsample=(2, 2), init='he_uniform')(ip) return x
def transition_up_block(ip, nb_filters, type='subpixel', output_shape=None, weight_decay=1E-4): ''' SubpixelConvolutional Upscaling (factor = 2) Args: ip: keras tensor nb_filters: number of layers type: can be 'subpixel' or 'deconv'. Determines type of upsampling performed output_shape: required if type = 'deconv'. Output shape of tensor weight_decay: weight decay factor Returns: keras tensor, after applying batch_norm, relu-conv, dropout, maxpool ''' if type == 'subpixel': x = Convolution2D(nb_filters, 3, 3, activation="relu", border_mode='same', W_regularizer=l2(weight_decay), bias=False)(ip) x = SubPixelUpscaling(r=2, channels=int(nb_filters // 4))(x) x = Convolution2D(nb_filters, 3, 3, activation="relu", border_mode='same', W_regularizer=l2(weight_decay), bias=False)(x) else: x = Deconvolution2D(nb_filters, 3, 3, output_shape, activation='relu', border_mode='same', subsample=(2, 2))(ip) return x
def _upscale_block(self, ip, id): init = ip x = Convolution2D(256, 3, 3, activation="linear", border_mode='same', name='sr_res_upconv1_%d' % id)(init) x = LeakyReLU(alpha=0.25, name='sr_res_up_lr_%d_1_1' % id)(x) x = SubPixelUpscaling(r=2, channels=self.filters, name='sr_res_upscale1_%d' % id)(x) x = Convolution2D(256, 3, 3, activation="linear", border_mode='same', name='sr_res_filter1_%d' % id)(x) x = LeakyReLU(alpha=0.25, name='sr_res_up_lr_%d_1_2' % id)(x) return x