Ejemplo n.º 1
0
def main(det_thresh=0.05,
         gallery_size=-1,
         ignore_cam_id=True,
         input_path=None):
    #results_path = '/raid/ljp/code/chao_mmdetection/jobs/dcn_base_focal/'

    # change here
    results_path = '/home/yy1/2021/mmdetection-public/work_dirs/' + input_path
    data_root = '/home/yy1/2021/data/prw/PRW-v16.04.20/'
    probe_set = load_probes(data_root)
    gallery_set = gt_roidbs(data_root)

    name_id = dict()
    for i, gallery in enumerate(gallery_set):
        name = gallery['im_name']
        name_id[name] = i
    # print(name_id)

    with open(os.path.join(results_path, 'results_1000.pkl'), 'rb') as fid:
        all_dets = pickle.load(fid)

    gallery_det, gallery_feat = [], []
    for det in all_dets:
        gallery_det.append(det[0][:, :5])
        if det[0].shape[0] > 0:
            feat = normalize(det[0][:, 5:], axis=1)
        else:
            feat = det[0][:, 5:]
        # feat = normalize(det[0][:, 5:], axis=1)
        gallery_feat.append(feat)

    probe_feat = []
    for probe in probe_set:
        name = probe['im_name']
        query_gt_box = probe['boxes'][0]
        id = name_id[name]
        det = gallery_det[id]
        feat = gallery_feat[id]

        iou, iou_max, nmax = get_max_iou(det, query_gt_box)
        if iou_max < 0.1:
            print("not detected", name, iou_max)
        feat = feat[nmax]
        probe_feat.append(feat)

    # gallery_det, gallery_feat = [], []
    # for det in all_dets:
    # det[0] = det[0][det[0][:, 4]>thresh]
    # gallery_det.append(det[0][:, :5])
    # if det[0].shape[0] > 0:
    #     feat = normalize(det[0][:, 5:], axis=1)
    # else:
    #     feat = det[0][:, 5:]
    # feat = normalize(det[0][:, 5:], axis=1)
    # gallery_feat.append(feat)

    search_performance_calc(gallery_set, probe_set, gallery_det, gallery_feat,
                            probe_feat, det_thresh, gallery_size,
                            ignore_cam_id)
Ejemplo n.º 2
0
            aps = []
            accs = []
            topk = [1, 5, 10]
            for index, item in enumerate(test):
                # query
                y_true, y_score = [], []
                count_gt, count_tp = 0, 0

                im_name = str(item["Query"][0, 0][0][0])
                query_gt_box = item["Query"][0,
                                             0][1].squeeze().astype(np.int32)
                query_gt_box[2:] += query_gt_box[:2]
                query_dict = gallery_dicts[img_to_id[im_name]]
                query_boxes = query_dict['bbox']
                iou, iou_max, nmax = get_max_iou(query_boxes, query_gt_box)
                #print(iou_max)
                '''
                if iou_max <= iou_thresh:
                    query_feat = query_dict['feats'][nmax]
                    #print("not detected", im_name, iou_max)
                    #continue
                else:
                    iou_good, good_idx = get_good_iou(query_boxes, query_gt_box, iou_thresh)
                    query_feats = query_dict['feats'][good_idx]
                    query_feat = iou_good[np.newaxis,:].dot(query_feats) / np.sum(iou_good)
                    query_feat = query_feat.ravel()
                '''

                query_feat = query_dict['feats'][nmax]
                query_feat = normalize(query_feat[np.newaxis, :],
Ejemplo n.º 3
0
def main(det_thresh=0.05,
         gallery_size=-1,
         ignore_cam_id=True,
         input_path=None):
    #results_path = '/raid/ljp/code/chao_mmdetection/jobs/dcn_base_focal/'
    results_path = '/home/jx1/yy1/mmdetection/work_dirs/' + input_path
    # thresh = 0.2

    data_root = '/home/jx1/yy1/data/PRW-v16.04.20/'
    probe_set = load_probes(data_root)
    gallery_set = gt_roidbs(data_root)

    name_id = dict()
    for i, gallery in enumerate(gallery_set):
        name = gallery['im_name']
        name_id[name] = i
    # print(name_id)

    with open(os.path.join(results_path, 'results_1000.pkl'), 'rb') as fid:
        all_dets = pickle.load(fid)
        # print(len(all_dets))

    all_dets1 = all_dets[0]
    all_dets2 = all_dets[1]
    print(len(all_dets1), len(all_dets2))

    gallery_det1, gallery_feat1 = [], []
    gallery_det2, gallery_feat2 = [], []
    gallery_det3, gallery_feat3 = [], []
    for det1, det2 in zip(all_dets1, all_dets2):
        gallery_det1.append(det1[0][:, :5])
        feat1 = normalize(det1[0][:, 5:], axis=1)
        # print('feat1', feat1.shape)
        gallery_feat1.append(feat1)

        gallery_det2.append(det2[:, :5])
        feat2 = normalize(det2[:, 5:], axis=1)
        # print('feat2', feat2.shape)
        gallery_feat2.append(feat2)

        gallery_det3 = gallery_det1
        gallery_feat3.append(np.concatenate((feat1, feat2), axis=1))

    probe_feat1 = []
    probe_feat2 = []
    probe_feat3 = []
    for probe in probe_set:
        name = probe['im_name']
        query_gt_box = probe['boxes'][0]
        id = name_id[name]

        det1 = gallery_det1[id]
        feat1 = gallery_feat1[id]
        iou, iou_max, nmax = get_max_iou(det1, query_gt_box)
        if iou_max < 0.1:
            print("not detected", name, iou_max)
        feat1 = feat1[nmax]
        probe_feat1.append(feat1)

        feat3 = gallery_feat3[id]
        feat3 = feat3[nmax]
        probe_feat3.append(feat3)

        det2 = gallery_det2[id]
        feat2 = gallery_feat2[id]
        iou, iou_max, nmax = get_max_iou(det2, query_gt_box)
        if iou_max < 0.1:
            print("not detected", name, iou_max)
        feat2 = feat2[nmax]
        probe_feat2.append(feat2)

    # gallery_det, gallery_feat = [], []
    # for det in all_dets:
    #     # det[0] = det[0][det[0][:, 4]>thresh]
    #     gallery_det.append(det[:, :5])
    #     # if det[0].shape[0] > 0:
    #     #     feat = normalize(det[0][:, 5:], axis=1)
    #     # else:
    #     #     feat = det[0][:, 5:]
    #     feat = normalize(det[:, 5:], axis=1)
    #     gallery_feat.append(feat)
    all_gallery_det = [gallery_det1, gallery_det2, gallery_det3]
    all_gallery_feat = [gallery_feat1, gallery_feat2, gallery_feat3]
    all_probe_feat = [probe_feat1, probe_feat2, probe_feat3]
    # all_gallery_det = [gallery_det1, gallery_det2]
    # all_gallery_feat = [gallery_feat1, gallery_feat2]
    # all_probe_feat = [probe_feat1, probe_feat2]
    for gallery_det, gallery_feat, probe_feat in zip(all_gallery_det,
                                                     all_gallery_feat,
                                                     all_probe_feat):
        search_performance_calc(gallery_set, probe_set, gallery_det,
                                gallery_feat, probe_feat, det_thresh,
                                gallery_size, ignore_cam_id)