def make_test_pairwise_fetaures(case1, case2, label, rng): import vtool as vt mu_fm = 50 if label == 1 else 10 sigma_fm = 10 if label == 1 else 20 mu_fs = 0.2 if label == 1 else 0.4 sigma_fs = 0.1 if label == 1 else 0.1 num_top = 4 max_feats = min(case1['nfeats'], case2['nfeats']) num_matches = ( np.clip(rng.normal(mu_fm, sigma_fm, size=1)[0], num_top + 1, max_feats).astype( np.int ), ) perb = np.abs(rng.normal(0.001, 0.001, size=num_matches)) sift_dists = np.clip(rng.normal(mu_fs, sigma_fs, size=num_matches), 0, 1) + perb sortx = np.argsort(sift_dists) local_feat_simvecs = np.vstack([sift_dists]).T[sortx] local_simvec = local_feat_simvecs[0:num_top] yaw1 = case1['yaw'] yaw2 = case2['yaw'] global_simvec = np.array( [ case1['qual'], case2['qual'], yaw1 / vt.TAU, yaw2 / vt.TAU, vt.ori_distance(yaw1, yaw2) / np.pi, np.abs(case1['qual'] - case1['qual']), ] ) simvec = np.hstack([global_simvec, local_simvec.ravel()]) return simvec
def make_test_pairwise_labels2(cases1, cases2): import vtool as vt is_same = np.array(cases1['name']) == np.array(cases2['name']) yaw1 = np.array(cases1['yaw']) yaw2 = np.array(cases2['yaw']) yaw_dist = vt.ori_distance(yaw1, yaw2) / np.pi qual1 = np.array(cases1['qual']) qual2 = np.array(cases2['qual']) _and = np.logical_and _or = np.logical_or _not = np.logical_not poorqual = _or(qual1 < 2, qual2 < 2) bestqual = _and(_or(qual1 > 3, qual2 > 3), _not(poorqual)) goodqual = _and(_not(bestqual), _not(poorqual)) is_comp = _or.reduce( [ _not(poorqual), _and(bestqual, yaw_dist <= (1 / 4)), _and(goodqual, yaw_dist <= (1 / 8)), ] ) label = is_same.astype(np.int32) label[_not(is_comp)] = 2 return label
def make_test_pairwise_fetaures(case1, case2, label, rng): import vtool as vt mu_fm = 50 if label == 1 else 10 sigma_fm = 10 if label == 1 else 20 mu_fs = .2 if label == 1 else .4 sigma_fs = .1 if label == 1 else .1 num_top = 4 max_feats = min(case1['nfeats'], case2['nfeats']) num_matches = np.clip(rng.normal(mu_fm, sigma_fm, size=1)[0], num_top + 1, max_feats).astype(np.int), perb = np.abs(rng.normal(.001, .001, size=num_matches)) sift_dists = np.clip(rng.normal(mu_fs, sigma_fs, size=num_matches), 0, 1) + perb sortx = np.argsort(sift_dists) local_feat_simvecs = np.vstack([sift_dists]).T[sortx] local_simvec = local_feat_simvecs[0:num_top] yaw1 = case1['yaw'] yaw2 = case2['yaw'] global_simvec = np.array([ case1['qual'], case2['qual'], yaw1 / vt.TAU, yaw2 / vt.TAU, vt.ori_distance(yaw1, yaw2) / np.pi, np.abs(case1['qual'] - case1['qual']), ]) simvec = np.hstack([global_simvec, local_simvec.ravel()]) return simvec
def make_test_similarity(test_case): # toy_params = { # True: {'mu': 0.9, 'sigma': .1}, # False: {'mu': 0.1, 'sigma': .4} # } # tau = np.pi * 2 from wbia import constants as const # view_to_ori = const.VIEWTEXT_TO_YAW_RADIANS view_to_ori = ut.map_dict_keys( lambda x: const.YAWALIAS[x], const.VIEWTEXT_TO_YAW_RADIANS ) # view_to_ori = { # 'F': -1 * tau / 4, # 'L': 0 * tau / 4, # 'B': 1 * tau / 4, # 'R': 2 * tau / 4, # } import vtool as vt nid_list = np.array(ut.dict_take_column(test_case, 'name')) yaw_list = np.array( ut.dict_take(view_to_ori, ut.dict_take_column(test_case, 'view')) ) rng = np.random.RandomState(0) pmat = [] for idx in range(len(test_case)): nid = nid_list[idx] yaw = yaw_list[idx] p_same = nid == nid_list p_comp = 1 - vt.ori_distance(yaw_list, yaw) / np.pi # estimate noisy measurements p_same_m = np.clip(p_same + rng.normal(0, 0.5, size=len(p_same)), 0, 0.9) p_comp_m = np.clip(p_comp + rng.normal(0, 0.5, size=len(p_comp)), 0, 0.9) # p_same_and_comp = p_same_m * p_comp_m pmat.append(p_same_and_comp) # P = np.array(pmat) P[np.diag_indices(len(P))] = 0 P = P + P.T / 2 P = np.clip(P, 0.01, 0.99) logger.info(ut.hz_str(' P = ', ut.repr2(P, precision=2, max_line_width=140))) return P
def make_test_pairwise_labels(case1, case2): import vtool as vt is_same = case1['name'] == case2['name'] yaw1 = case1['yaw'] yaw2 = case2['yaw'] yaw_dist = vt.ori_distance(yaw1, yaw2) / np.pi if case1['qual'] < 2 or case2['qual'] < 2: # Bad quality means not comparable is_comp = False else: if case1['qual'] > 3 or case2['qual'] > 3: # Better quality, better chance of being comparable is_comp = yaw_dist <= (1 / 4) else: is_comp = yaw_dist <= (1 / 8) if is_comp: label = int(is_same) else: label = 2 return label
def make_test_similarity(test_case): #toy_params = { # True: {'mu': 0.9, 'sigma': .1}, # False: {'mu': 0.1, 'sigma': .4} #} # tau = np.pi * 2 from ibeis import constants as const # view_to_ori = const.VIEWTEXT_TO_YAW_RADIANS view_to_ori = ut.map_dict_keys(lambda x: const.YAWALIAS[x], const.VIEWTEXT_TO_YAW_RADIANS) # view_to_ori = { # 'F': -1 * tau / 4, # 'L': 0 * tau / 4, # 'B': 1 * tau / 4, # 'R': 2 * tau / 4, # } import vtool as vt nid_list = np.array(ut.dict_take_column(test_case, 'name')) yaw_list = np.array(ut.dict_take(view_to_ori, ut.dict_take_column(test_case, 'view'))) rng = np.random.RandomState(0) pmat = [] for idx in range(len(test_case)): nid = nid_list[idx] yaw = yaw_list[idx] p_same = nid == nid_list p_comp = 1 - vt.ori_distance(yaw_list, yaw) / np.pi # estimate noisy measurements p_same_m = np.clip(p_same + rng.normal(0, .5, size=len(p_same)), 0, .9) p_comp_m = np.clip(p_comp + rng.normal(0, .5, size=len(p_comp)), 0, .9) # p_same_and_comp = p_same_m * p_comp_m pmat.append(p_same_and_comp) # P = np.array(pmat) P[np.diag_indices(len(P))] = 0 P = P + P.T / 2 P = np.clip(P, .01, .99) print(ut.hz_str(' P = ', ut.array_repr2(P, precision=2, max_line_width=140))) return P
def make_test_pairwise_labels2(cases1, cases2): import vtool as vt is_same = np.array(cases1['name']) == np.array(cases2['name']) yaw1 = np.array(cases1['yaw']) yaw2 = np.array(cases2['yaw']) yaw_dist = vt.ori_distance(yaw1, yaw2) / np.pi qual1 = np.array(cases1['qual']) qual2 = np.array(cases2['qual']) _and = np.logical_and _or = np.logical_or _not = np.logical_not poorqual = _or(qual1 < 2, qual2 < 2) bestqual = _and(_or(qual1 > 3, qual2 > 3), _not(poorqual)) goodqual = _and(_not(bestqual), _not(poorqual)) is_comp = _or.reduce([_not(poorqual), _and(bestqual, yaw_dist <= (1 / 4)), _and(goodqual, yaw_dist <= (1 / 8))]) label = is_same.astype(np.int32) label[_not(is_comp)] = 2 return label