'Return sample of at most fg_fraction * num_rois foreground indicies, padding
the remaining num_rois with background indicies. Foreground and background labels
are determined based on max_overlaps and the thresholds fg_thresh, bg_thresh_hi,
bg_thresh_lo.
Returns:
keep_inds (array): (num_rois,) sampled indicies of bboxes.
fg_rois_per_this_image (int): number of fg rois sampled from the image.'

def _sample_fg_bg(self, max_overlaps):

    fg_inds = np.where((max_overlaps >= self.fg_thresh))[0]
    fg_rois_per_image = np.round((self.fg_fraction * self.num_rois))
    fg_rois_per_this_image = min(fg_rois_per_image, fg_inds.size)
    if ((fg_inds.size > 0) and (not self.deterministic)):
        fg_inds = self.be.rng.choice(fg_inds, size=int(fg_rois_per_this_image), replace=False)
    elif (fg_inds.size > 0):
        fg_inds = fg_inds[:fg_rois_per_this_image]
    bg_inds = np.where(((max_overlaps < self.bg_thresh_hi) & (max_overlaps >= self.bg_thresh_lo)))[0]
    bg_rois_per_this_image = (self.num_rois - fg_rois_per_this_image)
    bg_rois_per_this_image = min(bg_rois_per_this_image, bg_inds.size)
    if ((bg_inds.size > 0) and (not self.deterministic)):
        bg_inds = self.be.rng.choice(bg_inds, size=int(bg_rois_per_this_image), replace=False)
    elif (bg_inds.size > 0):
        bg_inds = bg_inds[:bg_rois_per_this_image]
    keep_inds = np.append(fg_inds, bg_inds)
    return (keep_inds, int(fg_rois_per_this_image))
