(scores, bboxes, min_size_ratio, image_shape, net_input_shape, keep_top_k = 100, scope=None)
Only keep boxes with both sides >= min_size and center within the image.
    min_size_ratio is the ratio relative to net input shape
Only keep boxes with both sides >= min_size and center within the image.
    min_size_ratio is the ratio relative to net input shape
Only keep boxes with both sides > = min_size and center within the image . min_size_ratio is the ratio relative to net input shape
def filter_boxes(scores, bboxes, min_size_ratio, image_shape, net_input_shape, keep_top_k = 100, scope=None):
    """Only keep boxes with both sides >= min_size and center within the image.
    min_size_ratio is the ratio relative to net input shape
    """
    # Dictionaries as inputs.
    if isinstance(scores, dict) and isinstance(bboxes, dict):
        with tf.name_scope(scope, 'filter_boxes_dict'):
            d_scores = {}
            d_bboxes = {}
            for c in scores.keys():
                s, b = filter_boxes(scores[c], bboxes[c], min_size_ratio, image_shape, net_input_shape)
                d_scores[c] = s
                d_bboxes[c] = b
            return d_scores, d_bboxes

    # Tensors inputs.
    with tf.name_scope(scope, 'filter_boxes', [scores, bboxes]):
        # Scale min_size to match image scale
        min_size = tf.maximum(0.0001, min_size_ratio * tf.sqrt(tf.cast(image_shape[0] * image_shape[1], tf.float32) / (net_input_shape[0] * net_input_shape[1])))

        ymin = bboxes[:, 0]
        xmin = bboxes[:, 1]
        ymax = bboxes[:, 2]
        xmax = bboxes[:, 3]

        ws = xmax - xmin
        hs = ymax - ymin
        x_ctr = xmin + ws / 2.
        y_ctr = ymin + hs / 2.

        keep_mask = tf.logical_and(tf.greater(ws, min_size), tf.greater(hs, min_size))
        keep_mask = tf.logical_and(keep_mask, tf.greater(x_ctr, 0.))
        keep_mask = tf.logical_and(keep_mask, tf.greater(y_ctr, 0.))
        keep_mask = tf.logical_and(keep_mask, tf.less(x_ctr, 1.))
        keep_mask = tf.logical_and(keep_mask, tf.less(y_ctr, 1.))

        scores = pad_axis(tf.boolean_mask(scores, keep_mask), 0, keep_top_k, axis=0)
        bboxes = pad_axis(tf.boolean_mask(bboxes, keep_mask), 0, keep_top_k, axis=0)

        return scores, bboxes
def filter_boxes ( scores , bboxes , min_size_ratio , image_shape , net_input_shape , keep_top_k = 100 , scope = None ) : # Dictionaries as inputs. if isinstance ( scores , dict ) and isinstance ( bboxes , dict ) : with tf . name_scope ( scope , 'filter_boxes_dict' ) : d_scores = { } d_bboxes = { } for c in scores . keys ( ) : s , b = filter_boxes ( scores [ c ] , bboxes [ c ] , min_size_ratio , image_shape , net_input_shape ) d_scores [ c ] = s d_bboxes [ c ] = b return d_scores , d_bboxes # Tensors inputs. with tf . name_scope ( scope , 'filter_boxes' , [ scores , bboxes ] ) : # Scale min_size to match image scale min_size = tf . maximum ( 0.0001 , min_size_ratio * tf . sqrt ( tf . cast ( image_shape [ 0 ] * image_shape [ 1 ] , tf . float32 ) / ( net_input_shape [ 0 ] * net_input_shape [ 1 ] ) ) ) ymin = bboxes [ : , 0 ] xmin = bboxes [ : , 1 ] ymax = bboxes [ : , 2 ] xmax = bboxes [ : , 3 ] ws = xmax - xmin hs = ymax - ymin x_ctr = xmin + ws / 2. y_ctr = ymin + hs / 2. keep_mask = tf . logical_and ( tf . greater ( ws , min_size ) , tf . greater ( hs , min_size ) ) keep_mask = tf . logical_and ( keep_mask , tf . greater ( x_ctr , 0. ) ) keep_mask = tf . logical_and ( keep_mask , tf . greater ( y_ctr , 0. ) ) keep_mask = tf . logical_and ( keep_mask , tf . less ( x_ctr , 1. ) ) keep_mask = tf . logical_and ( keep_mask , tf . less ( y_ctr , 1. ) ) scores = pad_axis ( tf . boolean_mask ( scores , keep_mask ) , 0 , keep_top_k , axis = 0 ) bboxes = pad_axis ( tf . boolean_mask ( bboxes , keep_mask ) , 0 , keep_top_k , axis = 0 ) return scores , bboxes