'Crops to a set of proposals from the feature map for a batch of images.
Helper function for self._postprocess_rpn. This function calls
`tf.image.crop_and_resize` to create the feature map to be passed to the
second stage box classifier for each proposal.
Args:
features_to_crop: A float32 tensor with shape
[batch_size, height, width, depth]
proposal_boxes_normalized: A float32 tensor with shape [batch_size,
num_proposals, box_code_size] containing proposal boxes in
normalized coordinates.
Returns:
A float32 tensor with shape [K, new_height, new_width, depth].'

def _compute_second_stage_input_feature_maps(self, features_to_crop, proposal_boxes_normalized):

    def get_box_inds(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)])
    cropped_regions = tf.image.crop_and_resize(features_to_crop, self._flatten_first_two_dimensions(proposal_boxes_normalized), get_box_inds(proposal_boxes_normalized), (self._initial_crop_size, self._initial_crop_size))
    return slim.max_pool2d(cropped_regions, [self._maxpool_kernel_size, self._maxpool_kernel_size], stride=self._maxpool_stride)
