def discriminator(input, gan): previous_step = None next_step = None input_layer = input layer = tf.layers.conv2d(input, filters_list[sheets], (1, 1), name='from_rgb_' + str(sheets), kernel_initializer=initialization) #from RGB layer = tf.nn.leaky_relu(layer, alpha=0.2) #Growing layers for i in range(sheets, 0, -1): layer = new_sheet(filters_list[i], (3, 3), 'same', 'disc_layer_b' + str(i), pix_norm=False)(layer) layer = new_sheet(filters_list[i - 1], (3, 3), 'same', 'disc_layer_a' + str(i), pix_norm=False)(layer) layer = tf.layers.average_pooling2d(layer, 2, 2) #smooth fading if i == sheets: next_step = layer previous_step = tf.layers.average_pooling2d(input_layer, 2, 2) previous_step = tf.layers.conv2d( previous_step, filters_list[i - 1], (1, 1), name='from_rgb_' + str(sheets - 1), kernel_initializer=initialization) #from RGB previous_step = tf.nn.leaky_relu(previous_step, alpha=0.2) layer = previous_step + (next_step - previous_step) * transition_alpha(gan) layer = utils.MiniBatchStddev(layer, group_size=4) layer = new_sheet(filters_list[0], (3, 3), 'same', 'disc_head_0', pix_norm=False)(layer) layer = new_sheet(filters_list[0], (4, 4), 'valid', 'disc_head_1', pix_norm=False)(layer) layer = tf.keras.layers.Flatten()(layer) layer = tf.layers.dense(layer, 1, kernel_initializer=initialization) return layer
def build_discriminator(self): previous_step = None next_step = None input_layer = Input(shape=self.inp_shape) layer = Conv2D_sw(filters, (1, 1), weights=self.weights.get('from_rgb', None), name='from_rgb', kernel_initializer=initialization)( input_layer) #from RGB layer = LeakyReLU(alpha=0.2)(layer) layer = utils.PixelNorm()(layer) #Growing layers for i in range(self.layers, 0, -1): layer = new_sheet(self, filters, (3, 3), 'same', 'disc_layer_0' + str(i))(layer) layer = AveragePooling2D(2)(layer) #smooth fading if i == self.layers: next_step = layer previous_step = AveragePooling2D(2)(input_layer) previous_step = Conv2D_sw(filters, (1, 1), weights=self.weights.get( 'from_rgb', None))(previous_step) #from RGB previous_step = LeakyReLU(alpha=0.2)(previous_step) previous_step = utils.PixelNorm()(previous_step) layer = Lambda(lambda x: x[0] + (x[1] - x[0]) * self.transition_alpha.tensor)( [previous_step, next_step]) layer = utils.MiniBatchStddev(group_size=4)(layer) layer = new_sheet(self, filters, (3, 3), 'same', 'disc_head_0')(layer) layer = new_sheet(self, filters, (4, 4), 'valid', 'disc_head_1')(layer) layer = Flatten()(layer) layer = Dense_sw(1, activation=self.disc_activation, kernel_initializer=initialization)(layer) return Model(input_layer, layer)