Beispiel #1
0
def id_loss(images, renders, vggpath):
    model = VGGFace(vggpath, False)

    inputs = tf.concat([images, renders], axis=0)
    layers, _, _ = model.encoder(inputs, False)
    z = layers['fc7']

    z_images, z_renders = tf.split(z, 2, axis=0)
    loss = tf.reduce_mean(tf.square(z_images - z_renders), name='id_loss')
    return loss
class CoarseModel(object):

    def __init__(self, vggpath='', basis3dmm=None, trainable=True):
        self.basis3dmm = basis3dmm
        self.model = VGGFace(vggpath, trainable)

    def encoder3DMM(self, imgs, reuse=False):

        with tf.variable_scope('CoarseModel', reuse=tf.AUTO_REUSE):
            layers, _, _ = self.model.encoder(imgs, reuse)

            z = tf.reshape(layers['fc7'], [-1, 4096])

            with tf.variable_scope('decoder', reuse=tf.AUTO_REUSE) as scope:

                para_shape = tf.layers.dense(z,
                    self.basis3dmm['bases_shape'].shape[0],
                    use_bias=False,
                    kernel_initializer=tf.truncated_normal_initializer(stddev=0.002),
                    name='para_shape')

                para_exp = tf.layers.dense(z,
                    self.basis3dmm['bases_exp'].shape[0],
                    use_bias=False,
                    kernel_initializer=tf.zeros_initializer(),
                    name='para_exp')

                para_tex = tf.layers.dense(z,
                    self.basis3dmm['bases_tex'].shape[0],
                    use_bias=False,
                    kernel_initializer=tf.truncated_normal_initializer(stddev=0.002),
                    name='para_tex')

                para_pose  = tf.layers.dense(z,
                    6,
                    use_bias=False,
                    kernel_initializer=tf.zeros_initializer(),
                    name='para_pose')

                para_illum = tf.layers.dense(z,
                    27,
                    use_bias=False,
                    kernel_initializer=tf.zeros_initializer(),
                    name='para_illum')

            return para_shape, para_exp, para_tex, para_pose, para_illum