def _sample_rois(roidb, fg_rois_per_image, rois_per_image, num_classes):
 labels = roidb['max_classes']
 overlaps = roidb['max_overlaps']
 rois = roidb['boxes']
 fg_inds = np.where((overlaps >= cfg.TRAIN.FG_THRESH))[0]
 fg_rois_per_this_image = np.minimum(fg_rois_per_image, fg_inds.size)
 if (fg_inds.size > 0):
  fg_inds = npr.choice(fg_inds, size=fg_rois_per_this_image, replace=False)
 bg_inds = np.where(((overlaps < cfg.TRAIN.BG_THRESH_HI) & (overlaps >= cfg.TRAIN.BG_THRESH_LO)))[0]
 bg_rois_per_this_image = (rois_per_image - fg_rois_per_this_image)
 bg_rois_per_this_image = np.minimum(bg_rois_per_this_image, bg_inds.size)
 if (bg_inds.size > 0):
  bg_inds = npr.choice(bg_inds, size=bg_rois_per_this_image, replace=False)
 keep_inds = np.append(fg_inds, bg_inds)
 labels = labels[keep_inds]
 labels[fg_rois_per_this_image:] = 0
 overlaps = overlaps[keep_inds]
 rois = rois[keep_inds]
 (bbox_targets, bbox_inside_weights) = _get_bbox_regression_labels(roidb['bbox_targets'][keep_inds, :], num_classes)
 return (labels, overlaps, rois, bbox_targets, bbox_inside_weights)

def _sample_rois ( roidb , fg_rois_per_image , rois_per_image , num_classes ) : labels = roidb [ 'max_classes' ] overlaps = roidb [ 'max_overlaps' ] rois = roidb [ 'boxes' ] fg_inds = np . where ( ( overlaps >= cfg . TRAIN . FG_THRESH ) ) [ 0 ] fg_rois_per_this_image = np . minimum ( fg_rois_per_image , fg_inds . size ) if ( fg_inds . size > 0 ) : fg_inds = npr . choice ( fg_inds , size = fg_rois_per_this_image , replace = False ) bg_inds = np . where ( ( ( overlaps < cfg . TRAIN . BG_THRESH_HI ) & ( overlaps >= cfg . TRAIN . BG_THRESH_LO ) ) ) [ 0 ] bg_rois_per_this_image = ( rois_per_image - fg_rois_per_this_image ) bg_rois_per_this_image = np . minimum ( bg_rois_per_this_image , bg_inds . size ) if ( bg_inds . size > 0 ) : bg_inds = npr . choice ( bg_inds , size = bg_rois_per_this_image , replace = False ) keep_inds = np . append ( fg_inds , bg_inds ) labels = labels [ keep_inds ] labels [ fg_rois_per_this_image : ] = 0 overlaps = overlaps [ keep_inds ] rois = rois [ keep_inds ] ( bbox_targets , bbox_inside_weights ) = _get_bbox_regression_labels ( roidb [ 'bbox_targets' ] [ keep_inds , : ] , num_classes ) return ( labels , overlaps , rois , bbox_targets , bbox_inside_weights )
generate a random sample of rois comprising foreground and background examples .