(predictions_layer, localizations_layer,
                               select_threshold=None,
                               num_classes=21,
                               ignore_class=0,
                               scope=None)
Extract classes, scores and bounding boxes from features in one layer.
    Batch-compatible: inputs are supposed to have batch-type shapes.

    Args:
      predictions_layer: A SSD prediction layer;
      localizations_layer: A SSD localization layer;
      select_threshold: Classification threshold for selecting a box. All boxes
        under the threshold are set to 'zero'. If None, no threshold applied.
    Return:
      d_scores, d_bboxes: Dictionary of scores and bboxes Tensors of
        size Batches X N x 1 | 4. Each key corresponding to a class.
Extract classes, scores and bounding boxes from features in one layer.
    Batch-compatible: inputs are supposed to have batch-type shapes.
Extract classes scores and bounding boxes from features in one layer . Batch - compatible : inputs are supposed to have batch - type shapes .
def xdet_predict_clswise(predictions_layer, localizations_layer,
                               select_threshold=None,
                               num_classes=21,
                               ignore_class=0,
                               scope=None):
    """Extract classes, scores and bounding boxes from features in one layer.
    Batch-compatible: inputs are supposed to have batch-type shapes.

    Args:
      predictions_layer: A SSD prediction layer;
      localizations_layer: A SSD localization layer;
      select_threshold: Classification threshold for selecting a box. All boxes
        under the threshold are set to 'zero'. If None, no threshold applied.
    Return:
      d_scores, d_bboxes: Dictionary of scores and bboxes Tensors of
        size Batches X N x 1 | 4. Each key corresponding to a class.
    """
    select_threshold = 0.0 if select_threshold is None else select_threshold
    with tf.name_scope(scope, 'ssd_bboxes_select_layer',
                       [predictions_layer, localizations_layer]):
        # Reshape features: Batches x N x N_labels | 4
        p_shape = tfe.get_shape(predictions_layer)
        predictions_layer = tf.reshape(predictions_layer,
                                       tf.stack([p_shape[0], -1, p_shape[-1]]))
        l_shape = tfe.get_shape(localizations_layer)
        localizations_layer = tf.reshape(localizations_layer,
                                         tf.stack([l_shape[0], -1, l_shape[-1]]))
        # just consider those legal bboxes
        # localizations_mask = (localizations_layer[:, :, 0] < localizations_layer[:, :, 2])
        # localizations_mask = tf.logical_and(localizations_mask, (localizations_layer[:, :, 1] < localizations_layer[:, :, 3]))
        # localizations_mask = tf.Print(localizations_mask,[localizations_mask], message='localizations_mask: ', summarize=30)
        d_scores = {}
        d_bboxes = {}
        for c in range(0, num_classes):
            if c != ignore_class:
                # Remove boxes under the threshold.
                scores = predictions_layer[:, :, c]
                fmask = tf.cast(tf.greater(scores, select_threshold), scores.dtype)
                # fmask = tf.cast(tf.logical_and(tf.greater(scores, select_threshold), localizations_mask), scores.dtype)
                scores = scores * fmask
                bboxes = localizations_layer * tf.expand_dims(fmask, axis=-1)
                # Append to dictionary.
                d_scores[c] = scores
                d_bboxes[c] = bboxes

        return d_scores, d_bboxes
def xdet_predict_clswise ( predictions_layer , localizations_layer , select_threshold = None , num_classes = 21 , ignore_class = 0 , scope = None ) : select_threshold = 0.0 if select_threshold is None else select_threshold with tf . name_scope ( scope , 'ssd_bboxes_select_layer' , [ predictions_layer , localizations_layer ] ) : # Reshape features: Batches x N x N_labels | 4 p_shape = tfe . get_shape ( predictions_layer ) predictions_layer = tf . reshape ( predictions_layer , tf . stack ( [ p_shape [ 0 ] , - 1 , p_shape [ - 1 ] ] ) ) l_shape = tfe . get_shape ( localizations_layer ) localizations_layer = tf . reshape ( localizations_layer , tf . stack ( [ l_shape [ 0 ] , - 1 , l_shape [ - 1 ] ] ) ) # just consider those legal bboxes # localizations_mask = (localizations_layer[:, :, 0] < localizations_layer[:, :, 2]) # localizations_mask = tf.logical_and(localizations_mask, (localizations_layer[:, :, 1] < localizations_layer[:, :, 3])) # localizations_mask = tf.Print(localizations_mask,[localizations_mask], message='localizations_mask: ', summarize=30) d_scores = { } d_bboxes = { } for c in range ( 0 , num_classes ) : if c != ignore_class : # Remove boxes under the threshold. scores = predictions_layer [ : , : , c ] fmask = tf . cast ( tf . greater ( scores , select_threshold ) , scores . dtype ) # fmask = tf.cast(tf.logical_and(tf.greater(scores, select_threshold), localizations_mask), scores.dtype) scores = scores * fmask bboxes = localizations_layer * tf . expand_dims ( fmask , axis = - 1 ) # Append to dictionary. d_scores [ c ] = scores d_bboxes [ c ] = bboxes return d_scores , d_bboxes