def test_resnet(): n = 4 x = Input(shape=(1, 8, 8)) y = sequential([ conv2d_block(n), resnet(n) ])(x) model = Model(x, y) assert model.get_output_shape_for((None, 1, 8, 8)) == (None, n, 8, 8)
def render_gan_discriminator_resnet(x, n=32, conv_repeat=1, dense=[], out_activation='sigmoid'): def get_dense(nb): return [ Dense(nb), batch_norm(), LeakyReLU(0.2), ] return sequential([ Convolution2D(n, 3, 3, border_mode='same'), resnet(n, activation=LeakyReLU(0.3)), Convolution2D(n, 3, 3, subsample=(2, 2), border_mode='same'), LeakyReLU(0.2), batch_norm(), resnet(2 * n, activation=LeakyReLU(0.3)), resnet(2 * n, activation=LeakyReLU(0.3)), resnet(2 * n, activation=LeakyReLU(0.3)), resnet(2 * n, activation=LeakyReLU(0.3)), resnet(2 * n, activation=LeakyReLU(0.3)), Convolution2D(4 * n, 3, 3, subsample=(2, 2), border_mode='same'), resnet(4 * n, activation=LeakyReLU(0.3)), resnet(4 * n, activation=LeakyReLU(0.3)), resnet(4 * n, activation=LeakyReLU(0.3)), resnet(4 * n, activation=LeakyReLU(0.3)), resnet(4 * n, activation=LeakyReLU(0.3)), Convolution2D(4 * n, 3, 3, subsample=(2, 2), border_mode='same'), resnet(4 * n, activation=LeakyReLU(0.3)), resnet(4 * n, activation=LeakyReLU(0.3)), resnet(4 * n, activation=LeakyReLU(0.3)), resnet(4 * n, activation=LeakyReLU(0.3)), resnet(4 * n, activation=LeakyReLU(0.3)), Flatten(), [get_dense(nb) for nb in dense], Dense(1, activation=out_activation) ], ns='dis')(concat(x, axis=0, name='concat_fake_real'))
def render_gan_discriminator_resnet(x, n=32, conv_repeat=1, dense=[], out_activation='sigmoid'): def get_dense(nb): return [ Dense(nb), batch_norm(), LeakyReLU(0.2), ] return sequential([ Convolution2D(n, 3, 3, border_mode='same'), resnet(n, activation=LeakyReLU(0.3)), Convolution2D(n, 3, 3, subsample=(2, 2), border_mode='same'), LeakyReLU(0.2), batch_norm(), resnet(2*n, activation=LeakyReLU(0.3)), resnet(2*n, activation=LeakyReLU(0.3)), resnet(2*n, activation=LeakyReLU(0.3)), resnet(2*n, activation=LeakyReLU(0.3)), resnet(2*n, activation=LeakyReLU(0.3)), Convolution2D(4*n, 3, 3, subsample=(2, 2), border_mode='same'), resnet(4*n, activation=LeakyReLU(0.3)), resnet(4*n, activation=LeakyReLU(0.3)), resnet(4*n, activation=LeakyReLU(0.3)), resnet(4*n, activation=LeakyReLU(0.3)), resnet(4*n, activation=LeakyReLU(0.3)), Convolution2D(4*n, 3, 3, subsample=(2, 2), border_mode='same'), resnet(4*n, activation=LeakyReLU(0.3)), resnet(4*n, activation=LeakyReLU(0.3)), resnet(4*n, activation=LeakyReLU(0.3)), resnet(4*n, activation=LeakyReLU(0.3)), resnet(4*n, activation=LeakyReLU(0.3)), Flatten(), [get_dense(nb) for nb in dense], Dense(1, activation=out_activation) ], ns='dis')(concat(x, axis=0, name='concat_fake_real'))