def single_obj_scoremap(scoremap):
    ' Applies my algorithm to figure out the most likely object from a given segmentation scoremap. '
    with tf.variable_scope('single_obj_scoremap'):
        filter_size = 21
        s = scoremap.get_shape().as_list()
        assert (len(s) == 4), 'Scoremap must be 4D.'
        scoremap_softmax = tf.nn.softmax(scoremap)
        scoremap_fg = tf.reduce_max(scoremap_softmax[:, :, :, 1:], 3)
        detmap_fg = tf.round(scoremap_fg)
        max_loc = find_max_location(scoremap_fg)
        objectmap_list = list()
        kernel_dil = (tf.ones((filter_size, filter_size, 1)) / float((filter_size * filter_size)))
        for i in range(s[0]):
            sparse_ind = tf.reshape(max_loc[i, :], [1, 2])
            objectmap = tf.sparse_to_dense(sparse_ind, [s[1], s[2]], 1.0)
            num_passes = (max(s[1], s[2]) // (filter_size // 2))
            for j in range(num_passes):
                objectmap = tf.reshape(objectmap, [1, s[1], s[2], 1])
                objectmap_dil = tf.nn.dilation2d(objectmap, kernel_dil, [1, 1, 1, 1], [1, 1, 1, 1], 'SAME')
                objectmap_dil = tf.reshape(objectmap_dil, [s[1], s[2]])
                objectmap = tf.round(tf.multiply(detmap_fg[i, :, :], objectmap_dil))
            objectmap = tf.reshape(objectmap, [s[1], s[2], 1])
            objectmap_list.append(objectmap)
        objectmap = tf.stack(objectmap_list)
        return objectmap
Applies my algorithm to figure out the most likely object from a given segmentation scoremap.
def single_obj_scoremap(scoremap):
    '  '
    with tf.variable_scope('single_obj_scoremap'):
        filter_size = 21
        s = scoremap.get_shape().as_list()
        assert (len(s) == 4), 'Scoremap must be 4D.'
        scoremap_softmax = tf.nn.softmax(scoremap)
        scoremap_fg = tf.reduce_max(scoremap_softmax[:, :, :, 1:], 3)
        detmap_fg = tf.round(scoremap_fg)
        max_loc = find_max_location(scoremap_fg)
        objectmap_list = list()
        kernel_dil = (tf.ones((filter_size, filter_size, 1)) / float((filter_size * filter_size)))
        for i in range(s[0]):
            sparse_ind = tf.reshape(max_loc[i, :], [1, 2])
            objectmap = tf.sparse_to_dense(sparse_ind, [s[1], s[2]], 1.0)
            num_passes = (max(s[1], s[2]) // (filter_size // 2))
            for j in range(num_passes):
                objectmap = tf.reshape(objectmap, [1, s[1], s[2], 1])
                objectmap_dil = tf.nn.dilation2d(objectmap, kernel_dil, [1, 1, 1, 1], [1, 1, 1, 1], 'SAME')
                objectmap_dil = tf.reshape(objectmap_dil, [s[1], s[2]])
                objectmap = tf.round(tf.multiply(detmap_fg[i, :, :], objectmap_dil))
            objectmap = tf.reshape(objectmap, [s[1], s[2], 1])
            objectmap_list.append(objectmap)
        objectmap = tf.stack(objectmap_list)
        return objectmap