def age_classify(inp, age_size): global reuse_agecls, bn_training with tf.variable_scope('age_cls', reuse=reuse_agecls): mod = Model(inp) mod.set_bn_training(bn_training) mod.flatten() mod.fcLayer(512, activation=M.PARAM_LRELU) mod.fcLayer(256, activation=M.PARAM_LRELU) mod.fcLayer(age_size) reuse_agecls = True return mod.get_current_layer()
def discriminator(inp): global reuse_dis, bn_training, blknum blknum = 0 with tf.variable_scope('discriminator', reuse=reuse_dis): mod = Model(inp) mod.set_bn_training(bn_training) mod.convLayer(7, 16, stride=2, activation=M.PARAM_LRELU, batch_norm=True) # 64 mod.convLayer(5, 32, stride=2, activation=M.PARAM_LRELU, batch_norm=True) # 32 mod.SelfAttention(4) feat = mod.convLayer(5, 64, stride=2, activation=M.PARAM_LRELU) # 16 mod.batch_norm() mod.convLayer(3, 128, stride=2, activation=M.PARAM_LRELU, batch_norm=True) # 8 mod.convLayer(3, 128, stride=2, activation=M.PARAM_LRELU, batch_norm=True) adv = mod.convLayer(3, 1) mod.set_current_layer(feat) mod.convLayer(3, 128, stride=2, activation=M.PARAM_LRELU, batch_norm=True) block(mod, 128, 1) # 8 mod.convLayer(3, 128, stride=2, activation=M.PARAM_LRELU, batch_norm=True) block(mod, 256, 1) # 4 mod.convLayer(3, 128, stride=2, activation=M.PARAM_LRELU, batch_norm=True) block(mod, 256, 1) # 2 mod.flatten() age = mod.fcLayer(1) reuse_dis = True return adv, age
def discriminator_f(inp, id_num): global reuse_dis_f, bn_training with tf.variable_scope('dis_f', reuse=reuse_dis_f): mod = Model(inp) mod.set_bn_training(bn_training) mod.flatten() feat = mod.get_current_layer() mod.fcLayer(512, activation=M.PARAM_LRELU, batch_norm=True) mod.fcLayer(256, activation=M.PARAM_LRELU, batch_norm=True) adv = mod.fcLayer(1) mod.set_current_layer(feat) ip = mod.fcLayer(id_num) reuse_dis_f = True return adv, ip