def create_sr_model(self, ip): x = Convolution2D(64, 3, 3, activation='relu', border_mode='same', name='sr_res_conv1')(ip) nb_residual = 5 if self.small_model else 15 for i in range(nb_residual): x = self._residual_block(x, i + 1) x = Deconvolution2D(64, 3, 3, activation='relu', border_mode='same', subsample=(2, 2), name='sr_res_deconv1', output_shape=(self.batch_size, 64, self.img_width * 2, self.img_height * 2))(x) x = Deconvolution2D(64, 3, 3, activation='relu', border_mode='same', subsample=(2, 2), name='sr_res_deconv2', output_shape=(self.batch_size, 64, self.img_width * 4, self.img_height * 4))(x) tv_regularizer = TVRegularizer(img_width=self.img_width * 4, img_height=self.img_height * 4, weight=self.tv_weight) x = Convolution2D(3, 3, 3, activation="linear", border_mode='same', activity_regularizer=tv_regularizer, name='sr_res_conv_final')(x) #x = Denormalize(name='sr_res_output')(x) return x
def create_sr_model(self, ip): x = Convolution2D(self.filters, 5, 5, activation='linear', border_mode='same', name='sr_res_conv1')(ip) x = BatchNormalization(axis=channel_axis, mode=self.mode, name='sr_res_bn_1')(x) x = LeakyReLU(alpha=0.25, name='sr_res_lr1')(x) x = Convolution2D(self.filters, 5, 5, activation='linear', border_mode='same', name='sr_res_conv2')(x) x = BatchNormalization(axis=channel_axis, mode=self.mode, name='sr_res_bn_2')(x) x = LeakyReLU(alpha=0.25, name='sr_res_lr2')(x) nb_residual = 5 if self.small_model else 15 for i in range(nb_residual): x = self._residual_block(x, i + 1) for scale in range(self.nb_scales): x = self._upscale_block(x, scale + 1) scale = 2**self.nb_scales tv_regularizer = TVRegularizer(img_width=self.img_width * scale, img_height=self.img_height * scale, weight=self.tv_weight) x = Convolution2D(3, 5, 5, activation='tanh', border_mode='same', activity_regularizer=tv_regularizer, name='sr_res_conv_final')(x) x = Denormalize()(x) return x
def add_total_variation_loss(transform_output_layer, weight): # Total Variation Regularization layer = transform_output_layer # Output layer tv_regularizer = TVRegularizer(weight)(layer) layer.add_loss(tv_regularizer)