def discriminator_resnet_stl10(x, x_shape, dim=64, ss_task = 0,\ name = 'discriminator', reuse=False): relu = tf.nn.relu with tf.variable_scope(name, reuse=reuse): image = tf.reshape( x, [-1, x_shape[0], x_shape[1], x_shape[2]]) #48 * 48 * 3 h0 = optimized_block(image, dim, 'd_optimized_block1', \ act=relu) # 24 * 24 * dim h1 = d_block(h0, dim * 2, 'd_block2', act=relu) # 12 * 12 * dim * 2 h2 = d_block(h1, dim * 4, 'd_block3', act=relu) # 6 * 6 * dim * 4 h3 = d_block(h2, dim * 8, 'd_block4', act=relu) # 3 * 3 * dim * 8 h4 = d_block(h3, dim * 16, 'd_block5', None, act=relu) # 3 * 3 * dim * 16 h4_act = relu(h4) feat = tf.reshape(h4_act, [-1, dim * 16 * 3 * 3]) h5 = tf.reduce_sum(h4_act, [1, 2]) out = ops.linear(h5, 1, scope='linear_out') if ss_task == 1: k = 4 elif ss_task == 2: k = 5 else: k = -1 if ss_task > 0: print( '[net_resnet.py -- discriminator_resnet_stl10] SS task = %d with k = %d classes' % (ss_task, k)) cls = ops.linear(feat, k) return tf.sigmoid(out), out, feat, cls else: return tf.sigmoid(out), out, feat
def discriminator_resnet_cifar(x, x_shape, dim=128, ss_task = 0,\ name = 'discriminator', reuse=False): relu = tf.nn.relu with tf.variable_scope(name, reuse=reuse): image = tf.reshape(x, [-1, x_shape[0], x_shape[1], x_shape[2]]) h0 = optimized_block(image, dim, 'd_optimized_block1', \ act=relu) # 16 x 16 x dim h1 = d_block(h0, dim, 'd_block2', act=relu) # 8 x 8 x dim h2 = d_block(h1, dim, 'd_block3', None, act=relu) # 8 x 8 x dim h3 = d_block(h2, dim, 'd_block4', None, act=relu) # 8 x 8 x dim h3_act = relu(h3) feat = tf.reshape(h3_act, [-1, 8 * 8 * dim]) h4 = tf.reduce_sum(h3_act, [1, 2]) out = ops.linear(h4, 1, scope='linear_out') if ss_task == 1: k = 4 elif ss_task == 2: k = 5 else: k = -1 if ss_task > 0: print( '[net_resnet.py -- discriminator_dcgan_cifar] SS task = %d with k = %d classes' % (ss_task, k)) cls = ops.linear(feat, k) return tf.sigmoid(out), out, feat, cls else: return tf.sigmoid(out), out, feat
def generator_resnet_cifar(z, x_shape, dim=128, name = 'generator', \ reuse=False, training=True): dim = dim * 2 # 256 like sn-gan paper x_dim = x_shape[0] * x_shape[1] * x_shape[2] with tf.variable_scope(name, reuse=reuse): act0 = ops.linear(z, dim * 4 * 4, scope='g_linear0') act0 = tf.reshape(act0, [-1, 4, 4, dim]) act1 = g_block(act0, dim, training, 'g_block1') # 8 * 8 act2 = g_block(act1, dim, training, 'g_block2') # 16 * 16 act3 = g_block(act2, dim, training, 'g_block3') # 32 * 32 bn = ops.batch_norm(name='g_bn') act3 = tf.nn.relu(bn(act3, training)) act4 = ops.conv2d(act3, 3, 3, 3, 1, 1, name='g_conv_last') out = tf.nn.sigmoid(act4) return tf.reshape(out, [-1, x_dim])
def generator_resnet_stl10(z, x_shape, dim=64, name = 'generator', \ reuse=False, training=True): x_dim = x_shape[0] * x_shape[1] * x_shape[2] with tf.variable_scope(name, reuse=reuse): act0 = ops.linear(z, dim * 8 * 6 * 6, scope='g_linear0') act0 = tf.reshape(act0, [-1, 6, 6, dim * 8]) # 6 * 6 * dim * 8 act1 = g_block(act0, dim * 4, training, 'g_block1') # 12 * 12 * dim * 4 act2 = g_block(act1, dim * 2, training, 'g_block2') # 24 * 24 * dim * 2 act3 = g_block(act2, dim * 1, training, 'g_block3') # 48 * 48 * dim * 1 bn = ops.batch_norm(name='g_bn') act3 = tf.nn.relu(bn(act3, training)) act4 = ops.conv2d(act3, 3, 3, 3, 1, 1, name='g_conv_last') out = tf.nn.sigmoid(act4) return tf.reshape(out, [-1, x_dim])
def encoder_resnet_stl10(x, x_shape, z_dim=128, dim=64, \ name = 'encoder', reuse=False, training=True): act = lrelu with tf.variable_scope(name, reuse=reuse): image = tf.reshape(x, [-1, x_shape[0], x_shape[1], x_shape[2]]) image = ops.conv2d(image, dim, 3, 3, 1, 1, \ name='e_conv0') # 48 * 48 * dim act0 = e_block(image, dim * 2, training = training,\ name = 'e_block1', act=act) # 24 * 24 * dim * 2 act1 = e_block(act0, dim * 4, training, \ name = 'e_block2', act=act) # 12 * 12 * dim * 4 act2 = e_block(act1, dim * 8, training, \ name = 'e_block3', act=act)# 6 * 6 * dim * 8 bn = ops.batch_norm(name='e_bn') act2 = act(bn(act2, training)) act2 = tf.reshape(act2, [-1, 6 * 6 * dim * 8]) out = ops.linear(act2, z_dim) return out
def encoder_resnet_cifar(x, x_shape, z_dim=128, dim=128, \ name = 'encoder', reuse=False, training=True): dim = dim * 2 # 256 like sn-gan paper act = lrelu with tf.variable_scope(name, reuse=reuse): image = tf.reshape(x, [-1, x_shape[0], x_shape[1], x_shape[2]]) image = ops.conv2d(image, dim, 3, 3, 1, 1, \ name='e_conv0') # 32 * 32 act0 = e_block(image, dim, training = training,\ name = 'e_block1', act=act) # 16 * 16 act1 = e_block(act0, dim, training, \ name = 'e_block2', act=act) # 8 * 8 act2 = e_block(act1, dim, training, \ name = 'e_block3', act=act)# 4 * 4 bn = ops.batch_norm(name='e_bn') act2 = act(bn(act2, training)) act2 = tf.reshape(act2, [-1, 4 * 4 * dim]) out = ops.linear(act2, z_dim) return out