def featuremap_select(input, percentage, name='FeaturemapSelect', layer_collector=None):

    l = []
    for input_i in input:
        total_dim = input_i.get_shape().as_list()[-1]
        target_dim = int(total_dim * percentage)
        target_idxs = [i for i in range(total_dim)]
        target_idxs = np.random.choice(target_idxs, target_dim, replace=False)
        target_idxs = [[i] for i in target_idxs]
        input_i_t = tf.transpose(input_i, [3,1,2,0])
        input_i_s = tf.gather_nd(input_i_t, target_idxs)
        l.append(tf.transpose(input_i_s, [3,1,2,0]))

    safe_append(layer_collector, l, name)
    return l
def combine_score_layer(input,
                        shape,
                        name='CombineScore',
                        layer_collector=None,
                        param_collector=None):
    input_shape = tf.shape(input)

    l = tf.transpose(tf.reshape(tf.transpose(input, [0, 3, 1, 2]), [
        input_shape[0],
        int(shape),
        tf.cast(
            tf.cast(input_shape[1], tf.float32) / tf.cast(shape, tf.float32) *
            tf.cast(input_shape[3], tf.float32), tf.int32), input_shape[2]
    ]), [0, 2, 3, 1],
                     name=name)

    safe_append(layer_collector, l, name)

    return l
Beispiel #3
0
def proposal_layer(
    input,
    feature_stride,
    anchor_scales,
    name='ProposalLayer',
    layer_collector=None,
):
    with tf.variable_scope(name) as scope:
        l = tf.py_func(_proposal_layer, [
            input[0],
            input[1],
            input[2],
            input[3],
            feature_stride,
            anchor_scales,
        ], tf.float32)
        safe_append(layer_collector, l, name)

        return l
def anchor_target_layer(
    input,
    feature_stride,
    anchor_scales,
    name='AnchorLayer',
    layer_collector=None,
):
    with tf.variable_scope(name) as scope:
        layers = tf.py_func(_anchor_target_layer, [
            input[0],
            input[1],
            input[2],
            input[3],
            feature_stride,
            anchor_scales,
        ], [tf.float32, tf.float32, tf.float32, tf.float32])
        for layer in layers:
            safe_append(layer_collector, layer, name)

        return layers