lib/roi_data/fast_rcnn_rel.py [401:465]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                  replace=False)

    rel_fg_inds = np.append(rel_pos_inds, rel_gt_inds)
    # duplicate low-shot predicates to increase their chances to be chosen
    if cfg.TRAIN.OVERSAMPLE2:
        rel_pos_labels = rel_gt_labels[gt_assignment_pair_min[rel_fg_inds]] - 1
        low_shot_inds = \
            np.array([rel_fg_inds[i] for i, p in enumerate(rel_pos_labels) if
                     low_shot_helper.check_low_shot_p([-1, p, -1])], dtype=np.int32)
        rel_fg_inds = np.append(low_shot_inds, rel_fg_inds)
    if rel_fg_inds.size > fg_rois_per_image:
        rel_fg_inds = npr.choice(rel_fg_inds, size=fg_rois_per_image, replace=False)

    rel_bg_inds = np.where((max_overlaps_pair_min < cfg.TRAIN.BG_THRESH_HI))[0]
    rel_bg_rois_per_this_image = min(rois_per_image - rel_fg_inds.size,
                                     rois_per_image - fg_rois_per_image,
                                     rel_bg_inds.size)
    if rel_bg_inds.size > 0:
        rel_bg_inds = npr.choice(rel_bg_inds,
                                 size=rel_bg_rois_per_this_image,
                                 replace=False)

    # This oversampling method has redundant computation on those
    # low-shot ROIs, but it's flexible in that those low-shot ROIs
    # can be fed into the oversampler immediately after ROI-pooling,
    # instead of as late as after fc7
    if cfg.TRAIN.OVERSAMPLE:
        # Only consider low-shot on P
        rel_pos_labels = rel_gt_labels[gt_assignment_pair_min[rel_fg_inds]] - 1
        # low_shot_inds contains one dummy ROI at the very beginning
        # This is to make sure that low_shot ROIs are never empty
        low_shot_inds = \
            np.array([rel_fg_inds[i] for i, p in enumerate(rel_pos_labels) if
                     low_shot_helper.check_low_shot_p([-1, p, -1])], dtype=np.int32)
        rel_fg_inds = np.append(low_shot_inds, rel_fg_inds)
    if cfg.TRAIN.ADD_LOSS_WEIGHTS:
        # low-shot on P
        rel_pos_labels = rel_gt_labels[gt_assignment_pair_min[rel_fg_inds]] - 1
        rel_pos_weights = np.ones_like(rel_pos_labels, dtype=np.float32)
        low_shot_idx = \
            np.array([i for i, p in enumerate(rel_pos_labels) if
                     low_shot_helper.check_low_shot_p([-1, p, -1])], dtype=np.int32)
        rel_pos_weights[low_shot_idx] *= 2.0
        rel_pos_weights /= np.mean(rel_pos_weights)
    if cfg.TRAIN.ADD_LOSS_WEIGHTS_SO:
        # low-shot on S
        sbj_pos_weights = np.ones_like(sbj_pos_labels, dtype=np.float32)
        low_shot_idx = \
            np.array([i for i, s in enumerate(sbj_pos_labels) if
                     low_shot_helper.check_low_shot_s([s, -1, -1])], dtype=np.int32)
        sbj_pos_weights[low_shot_idx] *= 2.0
        sbj_pos_weights /= np.mean(sbj_pos_weights)
        # low-shot on O
        obj_pos_weights = np.ones_like(obj_pos_labels, dtype=np.float32)
        low_shot_idx = \
            np.array([i for i, o in enumerate(obj_pos_labels) if
                     low_shot_helper.check_low_shot_o([-1, -1, o])], dtype=np.int32)
        obj_pos_weights[low_shot_idx] *= 2.0
        obj_pos_weights /= np.mean(obj_pos_weights)

    rel_keep_inds = np.append(rel_fg_inds, rel_bg_inds)

    rel_rois_sbj = rel_all_rois_sbj[rel_keep_inds]
    rel_rois_obj = rel_all_rois_obj[rel_keep_inds]
    rel_rois_prd = rel_all_rois_prd[rel_keep_inds]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



lib/roi_data/fast_rcnn_rel.py [624:688]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                 replace=False)

    rel_fg_inds = np.append(rel_pos_inds, rel_gt_inds)
    # duplicate low-shot predicates to increase their chances to be chosen
    if cfg.TRAIN.OVERSAMPLE2:
        rel_pos_labels = rel_gt_labels[gt_assignment_pair_min[rel_fg_inds]] - 1
        low_shot_inds = \
            np.array([rel_fg_inds[i] for i, p in enumerate(rel_pos_labels) if
                     low_shot_helper.check_low_shot_p([-1, p, -1])], dtype=np.int32)
        rel_fg_inds = np.append(low_shot_inds, rel_fg_inds)
    if rel_fg_inds.size > fg_rois_per_image:
        rel_fg_inds = npr.choice(rel_fg_inds, size=fg_rois_per_image, replace=False)

    rel_bg_inds = np.where((max_overlaps_pair_min < cfg.TRAIN.BG_THRESH_HI))[0]
    rel_bg_rois_per_this_image = min(rois_per_image - rel_fg_inds.size,
                                     rois_per_image - fg_rois_per_image,
                                     rel_bg_inds.size)
    if rel_bg_inds.size > 0:
        rel_bg_inds = npr.choice(rel_bg_inds,
                                 size=rel_bg_rois_per_this_image,
                                 replace=False)

    # This oversampling method has redundant computation on those
    # low-shot ROIs, but it's flexible in that those low-shot ROIs
    # can be fed into the oversampler immediately after ROI-pooling,
    # instead of as late as after fc7
    if cfg.TRAIN.OVERSAMPLE:
        # Only consider low-shot on P
        rel_pos_labels = rel_gt_labels[gt_assignment_pair_min[rel_fg_inds]] - 1
        # low_shot_inds contains one dummy ROI at the very beginning
        # This is to make sure that low_shot ROIs are never empty
        low_shot_inds = \
            np.array([rel_fg_inds[i] for i, p in enumerate(rel_pos_labels) if
                     low_shot_helper.check_low_shot_p([-1, p, -1])], dtype=np.int32)
        rel_fg_inds = np.append(low_shot_inds, rel_fg_inds)
    if cfg.TRAIN.ADD_LOSS_WEIGHTS:
        # low-shot on P
        rel_pos_labels = rel_gt_labels[gt_assignment_pair_min[rel_fg_inds]] - 1
        rel_pos_weights = np.ones_like(rel_pos_labels, dtype=np.float32)
        low_shot_idx = \
            np.array([i for i, p in enumerate(rel_pos_labels) if
                     low_shot_helper.check_low_shot_p([-1, p, -1])], dtype=np.int32)
        rel_pos_weights[low_shot_idx] *= 2.0
        rel_pos_weights /= np.mean(rel_pos_weights)
    if cfg.TRAIN.ADD_LOSS_WEIGHTS_SO:
        # low-shot on S
        sbj_pos_weights = np.ones_like(sbj_pos_labels, dtype=np.float32)
        low_shot_idx = \
            np.array([i for i, s in enumerate(sbj_pos_labels) if
                     low_shot_helper.check_low_shot_s([s, -1, -1])], dtype=np.int32)
        sbj_pos_weights[low_shot_idx] *= 2.0
        sbj_pos_weights /= np.mean(sbj_pos_weights)
        # low-shot on O
        obj_pos_weights = np.ones_like(obj_pos_labels, dtype=np.float32)
        low_shot_idx = \
            np.array([i for i, o in enumerate(obj_pos_labels) if
                     low_shot_helper.check_low_shot_o([-1, -1, o])], dtype=np.int32)
        obj_pos_weights[low_shot_idx] *= 2.0
        obj_pos_weights /= np.mean(obj_pos_weights)

    rel_keep_inds = np.append(rel_fg_inds, rel_bg_inds)

    rel_rois_sbj = rel_all_rois_sbj[rel_keep_inds]
    rel_rois_obj = rel_all_rois_obj[rel_keep_inds]
    rel_rois_prd = rel_all_rois_prd[rel_keep_inds]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



