'Computes encoded object locations and corresponding confidences.
Args:
image_features: A float tensor of shape [batch_size, height, width,
channels] containing features for a batch of images.
num_predictions_per_location: an integer representing the number of box
predictions to be made per spatial location in the feature map.
Currently, this must be set to 1, or an error will be raised.
proposal_boxes: A float tensor of shape [batch_size, num_proposals,
box_code_size].
Returns:
box_encodings: A float tensor of shape
[batch_size, 1, num_classes, code_size] representing the
location of the objects.
class_predictions_with_background: A float tensor of shape
[batch_size, 1, num_classes + 1] representing the class
predictions for the proposals.
Raises:
ValueError: if num_predictions_per_location is not 1.'

def _predict(self, image_features, num_predictions_per_location, proposal_boxes):

    if (num_predictions_per_location != 1):
        raise ValueError('Currently    RfcnBoxPredictor    only    supports    predicting    a    single    box    per    class    per    location.')
    batch_size = tf.shape(proposal_boxes)[0]
    num_boxes = tf.shape(proposal_boxes)[1]
    def get_box_indices(proposals):
        proposals_shape = proposals.get_shape().as_list()
        if any(((dim is None) for dim in proposals_shape)):
            proposals_shape = tf.shape(proposals)
        ones_mat = tf.ones(proposals_shape[:2], dtype=tf.int32)
        multiplier = tf.expand_dims(tf.range(start=0, limit=proposals_shape[0]), 1)
        return tf.reshape((ones_mat * multiplier), [(-1)])
    net = image_features
    with slim.arg_scope(self._conv_hyperparams):
        net = slim.conv2d(net, self._depth, [1, 1], scope='reduce_depth')
        location_feature_map_depth = (((self._num_spatial_bins[0] * self._num_spatial_bins[1]) * self.num_classes) * self._box_code_size)
        location_feature_map = slim.conv2d(net, location_feature_map_depth, [1, 1], activation_fn=None, scope='refined_locations')
        box_encodings = ops.position_sensitive_crop_regions(location_feature_map, boxes=tf.reshape(proposal_boxes, [(-1), self._box_code_size]), box_ind=get_box_indices(proposal_boxes), crop_size=self._crop_size, num_spatial_bins=self._num_spatial_bins, global_pool=True)
        box_encodings = tf.squeeze(box_encodings, squeeze_dims=[1, 2])
        box_encodings = tf.reshape(box_encodings, [(batch_size * num_boxes), 1, self.num_classes, self._box_code_size])
        total_classes = (self.num_classes + 1)
        class_feature_map_depth = ((self._num_spatial_bins[0] * self._num_spatial_bins[1]) * total_classes)
        class_feature_map = slim.conv2d(net, class_feature_map_depth, [1, 1], activation_fn=None, scope='class_predictions')
        class_predictions_with_background = ops.position_sensitive_crop_regions(class_feature_map, boxes=tf.reshape(proposal_boxes, [(-1), self._box_code_size]), box_ind=get_box_indices(proposal_boxes), crop_size=self._crop_size, num_spatial_bins=self._num_spatial_bins, global_pool=True)
        class_predictions_with_background = tf.squeeze(class_predictions_with_background, squeeze_dims=[1, 2])
        class_predictions_with_background = tf.reshape(class_predictions_with_background, [(batch_size * num_boxes), 1, total_classes])
    return {BOX_ENCODINGS: box_encodings, CLASS_PREDICTIONS_WITH_BACKGROUND: class_predictions_with_background}
