Ejemplo n.º 1
0
def compute_transfweights(source_size,
                          target_size,
                          conditioned,
                          is_training=True,
                          batch_norm=True,
                          reuse=False):
    last_conv = tf.get_collection('last_conv')[0]
    batch_sz = last_conv.get_shape().as_list()[0]

    indexing_tensor = compute_indexing(source_size, target_size)
    indexing_tensor = tf.tile(indexing_tensor, [batch_sz, 1, 1, 1])
    H, W = indexing_tensor.get_shape().as_list()[1:3]

    if conditioned:
        # compute image global features
        with nets.base_arg_scope(is_training, batch_norm):
            with tf.variable_scope('condition_net', reuse=reuse) as scope:
                fc1 = slim.conv2d(last_conv, 64, [1, 1], scope='fc1')
                tf.summary.histogram('fc1', fc1)
                fc2 = slim.conv2d(fc1,
                                  1, [1, 1],
                                  scope='fc2',
                                  activation_fn=None,
                                  normalizer_fn=None)
                tf.summary.histogram('fc2', fc2)
                fc2 = tf.reshape(fc2, [batch_sz, 1, 1, -1])
                fc2 = tf.tile(fc2, [1, H, W, 1])
                fc2 = tf.reshape(fc2, [batch_sz, H, W, -1])
        # concatenate with indexing tensor
        net = tf.concat([indexing_tensor, fc2], 3)
    else:
        net = indexing_tensor

    with nets.base_arg_scope(is_training, batch_norm, weight_decay=0.):
        with tf.variable_scope('weight_net', reuse=reuse) as scope:
            net = slim.conv2d(net, 128, [1, 1], scope='fc1')
            tf.summary.histogram('fc1_wn', net)
            net = slim.conv2d(net, 64, [1, 1], scope='fc2')
            tf.summary.histogram('fc2_wn', net)
            net = slim.conv2d(net,
                              1, [1, 1],
                              scope='fc3',
                              activation_fn=None,
                              normalizer_fn=None)
            tf.summary.histogram('fc3_wn', net)

    weights = tf.reshape(
        net,
        [-1, source_size[0] * source_size[1], target_size[0] * target_size[1]])
    weights = tf.nn.softmax(weights, dim=1)  # sum columns to 1

    return weights
Ejemplo n.º 2
0
def pixelnet(inputs,
             num_class,
             is_training=True,
             reuse=False,
             batch_norm=True):
    with nets.base_arg_scope(is_training, batch_norm):
        net = pixelnet_convs(inputs, num_class, is_training, reuse)
        with tf.variable_scope('aerial_mlp', reuse=reuse):
            fc1 = slim.conv2d(net, 512, [1, 1], scope='fc1')
            fc2 = slim.conv2d(fc1, 512, [1, 1], scope='fc2')
            fc3 = slim.conv2d(fc2,
                              num_class, [1, 1],
                              scope='fc3',
                              activation_fn=None,
                              normalizer_fn=None)

            tf.add_to_collection('aerial_mlp', fc1)
            tf.add_to_collection('aerial_mlp', fc2)
            tf.add_to_collection('aerial_mlp', fc3)

    return fc3
Ejemplo n.º 3
0
def pixelnet_g(inputs,
               num_class,
               is_training=True,
               reuse=False,
               batch_norm=True):
    with nets.base_arg_scope(is_training, batch_norm):
        net = pixelnet_convs_g(inputs, num_class, is_training, reuse)
        net = tf.image.resize_bilinear(net, size=[8, 40])
        with tf.variable_scope('ground_mlp', reuse=reuse):
            fc1 = slim.conv2d(net, 512, [1, 1], scope='fc1_g')
            fc2 = slim.conv2d(fc1, 512, [1, 1], scope='fc2_g')
            fc3 = slim.conv2d(fc2,
                              num_class, [1, 1],
                              scope='fc3_g',
                              activation_fn=None,
                              normalizer_fn=None)

            tf.add_to_collection('ground_mlp', fc1)
            tf.add_to_collection('ground_mlp', fc2)
            tf.add_to_collection('ground_mlp', fc3)

    return fc3