'Unpads proposals and samples a minibatch for second stage.
Args:
proposal_boxes: A float tensor with shape
[batch_size, num_proposals, 4] representing the (potentially zero
padded) proposal boxes for all images in the batch.  These boxes are
represented as normalized coordinates.
proposal_scores:  A float tensor with shape
[batch_size, num_proposals] representing the (potentially zero
padded) proposal objectness scores for all images in the batch.
num_proposals: A Tensor of type `int32`. A 1-D tensor of shape [batch]
representing the number of proposals predicted for each image in
the batch.
groundtruth_boxlists: A list of BoxLists containing (absolute) coordinates
of the groundtruth boxes.
groundtruth_classes_with_background_list: A list of 2-D one-hot
(or k-hot) tensors of shape [num_boxes, num_classes+1] containing the
class targets with the 0th index assumed to map to the background class.
Returns:
proposal_boxes: A float tensor with shape
[batch_size, second_stage_batch_size, 4] representing the (potentially
zero padded) proposal boxes for all images in the batch.  These boxes
are represented as normalized coordinates.
proposal_scores:  A float tensor with shape
[batch_size, second_stage_batch_size] representing the (potentially zero
padded) proposal objectness scores for all images in the batch.
num_proposals: A Tensor of type `int32`. A 1-D tensor of shape [batch]
representing the number of proposals predicted for each image in
the batch.'

def _unpad_proposals_and_sample_box_classifier_batch(self, proposal_boxes, proposal_scores, num_proposals, groundtruth_boxlists, groundtruth_classes_with_background_list):

    single_image_proposal_box_sample = []
    single_image_proposal_score_sample = []
    single_image_num_proposals_sample = []
    for (single_image_proposal_boxes, single_image_proposal_scores, single_image_num_proposals, single_image_groundtruth_boxlist, single_image_groundtruth_classes_with_background) in zip(tf.unstack(proposal_boxes), tf.unstack(proposal_scores), tf.unstack(num_proposals), groundtruth_boxlists, groundtruth_classes_with_background_list):
        static_shape = single_image_proposal_boxes.get_shape()
        sliced_static_shape = tf.TensorShape([tf.Dimension(None), static_shape.dims[(-1)]])
        single_image_proposal_boxes = tf.slice(single_image_proposal_boxes, [0, 0], [single_image_num_proposals, (-1)])
        single_image_proposal_boxes.set_shape(sliced_static_shape)
        single_image_proposal_scores = tf.slice(single_image_proposal_scores, [0], [single_image_num_proposals])
        single_image_boxlist = box_list.BoxList(single_image_proposal_boxes)
        single_image_boxlist.add_field(fields.BoxListFields.scores, single_image_proposal_scores)
        sampled_boxlist = self._sample_box_classifier_minibatch(single_image_boxlist, single_image_groundtruth_boxlist, single_image_groundtruth_classes_with_background)
        sampled_padded_boxlist = box_list_ops.pad_or_clip_box_list(sampled_boxlist, num_boxes=self._second_stage_batch_size)
        single_image_num_proposals_sample.append(tf.minimum(sampled_boxlist.num_boxes(), self._second_stage_batch_size))
        bb = sampled_padded_boxlist.get()
        single_image_proposal_box_sample.append(bb)
        single_image_proposal_score_sample.append(sampled_padded_boxlist.get_field(fields.BoxListFields.scores))
    return (tf.stack(single_image_proposal_box_sample), tf.stack(single_image_proposal_score_sample), tf.stack(single_image_num_proposals_sample))
