def get_resnet(x_tensor, reuse, is_training, x_batch_size):
    with tf.variable_scope('resnet', reuse=reuse):
        with slim.arg_scope(resnet_v2.resnet_arg_scope()):
            resnet, end_points = resnet_v2.resnet_v2_50(
                x_tensor,
                global_pool=False,
                is_training=is_training,
                reuse=reuse,
                output_stride=32)
        global_pool = tf.reduce_mean(resnet, [1, 2])
        with tf.variable_scope('fc'):
            global_pool = slim.fully_connected(global_pool,
                                               2048,
                                               scope='fc/fc_1')
            global_pool = slim.fully_connected(global_pool,
                                               1024,
                                               scope='fc/fc_2')
            global_pool = slim.fully_connected(global_pool,
                                               512,
                                               scope='fc/fc_3')
            theta = output_layer(global_pool, (grid_h + 1) * (grid_w + 1) * 2)

        with tf.name_scope('gen_theta'):
            id2_loss = tf.reduce_mean(tf.abs(theta)) * id_mul
    return theta, id2_loss, id2_loss
Exemple #2
0
def get_resnet(x_tensor, reuse, is_training, x_batch_size):
    with tf.variable_scope('resnet', reuse=reuse):
        with slim.arg_scope(resnet_v2.resnet_arg_scope()):
            resnet, end_points = resnet_v2.resnet_v2_50(
                x_tensor,
                global_pool=False,
                is_training=is_training,
                reuse=reuse,
                output_stride=32)
        global_pool = tf.reduce_mean(resnet, [1, 2])
        with tf.variable_scope('fc'):
            theta = output_layer(global_pool, 8)
        with tf.name_scope('gen_theta'):
            eyes = tf.constant([1, 0, 0, 0, 1, 0, 0, 0, 1],
                               dtype=tf.float32)  #, trainable=False)
            eyes = tf.reshape(tf.tile(eyes, [x_batch_size]),
                              [x_batch_size, -1])
            ones = tf.zeros(shape=[x_batch_size, 1], dtype=tf.float32)
            id_loss = tf.reduce_mean(tf.abs(theta)) * id_mul
            theta = tf.concat([theta, ones], 1)
            theta = theta + eyes
    return theta, id_loss
def reduce_layer(input):
    with tf.variable_scope('reduce_layer'):
        with tf.variable_scope('conv0'):
            conv0_ = conv_bn_relu_layer(input, [1, 1, 2048, 512], 1)

        with tf.variable_scope('conv1_0'):
            conv1_0_ = conv_bn_relu_layer2(conv0_, [1, 16, 512, 512], [1, 1])
        with tf.variable_scope('conv2_0'):
            conv2_0_ = conv_bn_relu_layer2(conv1_0_, [9, 1, 512, 512], [1, 1])

        with tf.variable_scope('conv1_1'):
            conv1_1_ = conv_bn_relu_layer2(conv0_, [9, 1, 512, 512], [1, 1])
        with tf.variable_scope('conv2_1'):
            conv2_1_ = conv_bn_relu_layer2(conv1_1_, [1, 16, 512, 512], [1, 1])
        with tf.variable_scope('conv2'):
            conv2_ = conv2_0_ + conv2_1_
        with tf.variable_scope('conv3'):
            conv3_ = conv_bn_relu_layer(conv2_, [1, 1, 512, 128], 1)
        with tf.variable_scope('conv4'):
            conv4_ = conv_bn_relu_layer(conv3_, [1, 1, 128, 32], 1)
        with tf.variable_scope('fc'):
            out = output_layer(tf.reshape(conv4_, [batch_size, 32]), 8)
    return out