'Adds box predictors to each feature map and returns concatenated results.
Args:
feature_maps: a list of tensors where the ith tensor has shape
[batch, height_i, width_i, depth_i]
Returns:
box_encodings: 4-D float tensor of shape [batch_size, num_anchors,
box_code_dimension] containing predicted boxes.
class_predictions_with_background: 2-D float tensor of shape
[batch_size, num_anchors, num_classes+1] containing class predictions
(logits) for each of the anchors.  Note that this tensor *includes*
background class predictions (at class index 0).
Raises:
RuntimeError: if the number of feature maps extracted via the
extract_features method does not match the length of the
num_anchors_per_locations list that was passed to the constructor.
RuntimeError: if box_encodings from the box_predictor does not have
shape of the form  [batch_size, num_anchors, 1, code_size].'

def _add_box_predictions_to_feature_maps(self, feature_maps):

    num_anchors_per_location_list = self._anchor_generator.num_anchors_per_location()
    if (len(feature_maps) != len(num_anchors_per_location_list)):
        raise RuntimeError('the    number    of    feature    maps    must    match    the    length    of    self.anchors.NumAnchorsPerLocation().')
    box_encodings_list = []
    cls_predictions_with_background_list = []
    for (idx, (feature_map, num_anchors_per_location)) in enumerate(zip(feature_maps, num_anchors_per_location_list)):
        box_predictor_scope = 'BoxPredictor_{}'.format(idx)
        box_predictions = self._box_predictor.predict(feature_map, num_anchors_per_location, box_predictor_scope)
        box_encodings = box_predictions[bpredictor.BOX_ENCODINGS]
        cls_predictions_with_background = box_predictions[bpredictor.CLASS_PREDICTIONS_WITH_BACKGROUND]
        box_encodings_shape = box_encodings.get_shape().as_list()
        if ((len(box_encodings_shape) != 4) or (box_encodings_shape[2] != 1)):
            raise RuntimeError('box_encodings    from    the    box_predictor    must    be    of    shape    `[batch_size,    num_anchors,    1,    code_size]`;    actual    shape', box_encodings_shape)
        box_encodings = tf.squeeze(box_encodings, axis=2)
        box_encodings_list.append(box_encodings)
        cls_predictions_with_background_list.append(cls_predictions_with_background)
    num_predictions = sum([tf.shape(box_encodings)[1] for box_encodings in box_encodings_list])
    num_anchors = self.anchors.num_boxes()
    anchors_assert = tf.assert_equal(num_anchors, num_predictions, ['Mismatch:    number    of    anchors    vs    number    of    predictions', num_anchors, num_predictions])
    with tf.control_dependencies([anchors_assert]):
        box_encodings = tf.concat(box_encodings_list, 1)
        class_predictions_with_background = tf.concat(cls_predictions_with_background_list, 1)
    return (box_encodings, class_predictions_with_background)
