def get_minibatch(roidb, num_classes):
    'Given a mini batch of roidb, construct a data blob from it.'
    num_images = len(roidb)
    random_scale_inds = npr.randint(0, high=len(cfg.TRAIN.SCALES), size=num_images)
    assert ((cfg.TRAIN.BATCH_SIZE % num_images) == 0), 'num_images ({}) must divide BATCH_SIZE ({})'.format(num_images, cfg.TRAIN.BATCH_SIZE)
    rois_per_image = (cfg.TRAIN.BATCH_SIZE / num_images)
    fg_rois_per_image = np.round((cfg.TRAIN.FG_FRACTION * rois_per_image))
    im_timer = Timer()
    im_timer.tic()
    (im_blob, im_scales) = _get_image_blob(roidb, random_scale_inds)
    im_timer.toc()
    blobs = {'ims': im_blob}
    rois_blob = np.zeros((0, 5), dtype=np.float32)
    labels_blob = np.zeros(0, dtype=np.float32)
    rels_blob = np.zeros((0, 3), dtype=np.int32)
    bbox_targets_blob = np.zeros((0, (4 * num_classes)), dtype=np.float32)
    bbox_inside_blob = np.zeros(bbox_targets_blob.shape, dtype=np.float32)
    all_overlaps = []
    box_idx_offset = 0
    d_timer = Timer()
    d_timer.tic()
    for im_i in xrange(num_images):
        (roi_inds, rels) = _sample_graph(roidb[im_i], fg_rois_per_image, rois_per_image, num_neg_rels=cfg.TRAIN.NUM_NEG_RELS)
        if (rels.size == 0):
            print('batch skipped')
            return None
        (rels, labels, overlaps, im_rois, bbox_targets, bbox_inside_weights) = _gather_samples(roidb[im_i], roi_inds, rels, num_classes)
        rois = _project_im_rois(im_rois, im_scales[im_i])
        batch_ind = (im_i * np.ones((rois.shape[0], 1)))
        rois_blob_this_image = np.hstack((batch_ind, rois))
        rois_blob = np.vstack((rois_blob, rois_blob_this_image))
        labels_blob = np.hstack((labels_blob, labels))
        bbox_targets_blob = np.vstack((bbox_targets_blob, bbox_targets))
        bbox_inside_blob = np.vstack((bbox_inside_blob, bbox_inside_weights))
        all_overlaps = np.hstack((all_overlaps, overlaps))
        rels_offset = rels.copy()
        rels_offset[:, :2] += box_idx_offset
        rels_blob = np.vstack([rels_blob, rels_offset])
        box_idx_offset += rois.shape[0]
    blobs['rois'] = rois_blob.copy()
    blobs['labels'] = labels_blob.copy().astype(np.int32)
    blobs['relations'] = rels_blob[:, :2].copy().astype(np.int32)
    blobs['predicates'] = rels_blob[:, 2].copy().astype(np.int32)
    blobs['bbox_targets'] = bbox_targets_blob.copy()
    blobs['bbox_inside_weights'] = bbox_inside_blob.copy()
    blobs['bbox_outside_weights'] = np.array((bbox_inside_blob > 0)).astype(np.float32).copy()
    num_roi = rois_blob.shape[0]
    num_rel = rels_blob.shape[0]
    blobs['rel_rois'] = data_utils.compute_rel_rois(num_rel, rois_blob, rels_blob)
    d_timer.toc()
    graph_dict = data_utils.create_graph_data(num_roi, num_rel, rels_blob[:, :2])
    for k in graph_dict:
        blobs[k] = graph_dict[k]
    return blobs
Given a mini batch of roidb, construct a data blob from it.
def get_minibatch(roidb, num_classes):
    
    num_images = len(roidb)
    random_scale_inds = npr.randint(0, high=len(cfg.TRAIN.SCALES), size=num_images)
    assert ((cfg.TRAIN.BATCH_SIZE % num_images) == 0), 'num_images ({}) must divide BATCH_SIZE ({})'.format(num_images, cfg.TRAIN.BATCH_SIZE)
    rois_per_image = (cfg.TRAIN.BATCH_SIZE / num_images)
    fg_rois_per_image = np.round((cfg.TRAIN.FG_FRACTION * rois_per_image))
    im_timer = Timer()
    im_timer.tic()
    (im_blob, im_scales) = _get_image_blob(roidb, random_scale_inds)
    im_timer.toc()
    blobs = {'ims': im_blob}
    rois_blob = np.zeros((0, 5), dtype=np.float32)
    labels_blob = np.zeros(0, dtype=np.float32)
    rels_blob = np.zeros((0, 3), dtype=np.int32)
    bbox_targets_blob = np.zeros((0, (4 * num_classes)), dtype=np.float32)
    bbox_inside_blob = np.zeros(bbox_targets_blob.shape, dtype=np.float32)
    all_overlaps = []
    box_idx_offset = 0
    d_timer = Timer()
    d_timer.tic()
    for im_i in xrange(num_images):
        (roi_inds, rels) = _sample_graph(roidb[im_i], fg_rois_per_image, rois_per_image, num_neg_rels=cfg.TRAIN.NUM_NEG_RELS)
        if (rels.size == 0):
            print('batch skipped')
            return None
        (rels, labels, overlaps, im_rois, bbox_targets, bbox_inside_weights) = _gather_samples(roidb[im_i], roi_inds, rels, num_classes)
        rois = _project_im_rois(im_rois, im_scales[im_i])
        batch_ind = (im_i * np.ones((rois.shape[0], 1)))
        rois_blob_this_image = np.hstack((batch_ind, rois))
        rois_blob = np.vstack((rois_blob, rois_blob_this_image))
        labels_blob = np.hstack((labels_blob, labels))
        bbox_targets_blob = np.vstack((bbox_targets_blob, bbox_targets))
        bbox_inside_blob = np.vstack((bbox_inside_blob, bbox_inside_weights))
        all_overlaps = np.hstack((all_overlaps, overlaps))
        rels_offset = rels.copy()
        rels_offset[:, :2] += box_idx_offset
        rels_blob = np.vstack([rels_blob, rels_offset])
        box_idx_offset += rois.shape[0]
    blobs['rois'] = rois_blob.copy()
    blobs['labels'] = labels_blob.copy().astype(np.int32)
    blobs['relations'] = rels_blob[:, :2].copy().astype(np.int32)
    blobs['predicates'] = rels_blob[:, 2].copy().astype(np.int32)
    blobs['bbox_targets'] = bbox_targets_blob.copy()
    blobs['bbox_inside_weights'] = bbox_inside_blob.copy()
    blobs['bbox_outside_weights'] = np.array((bbox_inside_blob > 0)).astype(np.float32).copy()
    num_roi = rois_blob.shape[0]
    num_rel = rels_blob.shape[0]
    blobs['rel_rois'] = data_utils.compute_rel_rois(num_rel, rois_blob, rels_blob)
    d_timer.toc()
    graph_dict = data_utils.create_graph_data(num_roi, num_rel, rels_blob[:, :2])
    for k in graph_dict:
        blobs[k] = graph_dict[k]
    return blobs