def read_lines_truth(csv_file_name, tower_gt): connected_pair = [] for start, stop, online_points in read_line_csv_data( csv_file_name, tower_gt): centers = add_point_if_not_nearby(start, stop, [tower_gt[a] for a in online_points]) for i in range(len(centers) - 1): # find the corresponding gt try: connected_pair.append( order_pair(find_point_id(tower_gt, centers[i]), find_point_id(tower_gt, centers[i + 1]))) except AssertionError: pass return connected_pair
def grid_score(tower_gt, tower_pred, line_gt, line_pred, link_list): cnt_obj = 0 for a in link_list: if a > -1: cnt_obj += 1 cnt_pred = 0 lp = [] for cp in line_pred: lp.append(order_pair(*cp)) lp = list(set(lp)) for cp in lp: if (link_list[cp[0]] > -1) and (link_list[cp[1]] > -1): if (link_list[cp[0]], link_list[cp[1]]) in line_gt: cnt_pred += 1 tp = cnt_obj + cnt_pred n_recall = len(tower_gt) + len(line_gt) n_precision = len(tower_pred) + len(line_pred) return tp, n_recall, n_precision
def grid_score(tower_gt, tower_pred, line_gt, line_pred, link_list, score_type='all'): assert score_type in ['Graph', 'Tower', 'Line'] cnt_obj = 0 for a in link_list: if a > -1: cnt_obj += 1 lp = [] for cp in line_pred: lp.append(order_pair(*cp)) lp = list(set(lp)) cnt_pred = 0 for cp in lp: if (link_list[cp[0]] > -1) and (link_list[cp[1]] > -1): if (link_list[cp[0]], link_list[cp[1]]) in line_gt: cnt_pred += 1 if score_type == 'Graph': tp = cnt_obj + cnt_pred n_recall = len(tower_gt) + len(line_gt) n_precision = len(tower_pred) + len(line_pred) elif score_type == 'Tower': tp = cnt_obj n_recall = len(tower_gt) n_precision = len(tower_pred) else: tp = cnt_pred n_recall = len(line_gt) n_precision = len(line_pred) return tp, n_recall, n_precision
save_file_name = os.path.join( dirs['task'], '{}_{}_cp.npy'.format(city_list[city_id], tile_id)) # load data line_gt, tower_gt = load_data(dirs, city_id, tile_id) # get tower connection info connected_pair = [] csv_file_name = os.path.join( dirs['raw'], 'USA_{}_{}.csv'.format(city_list[city_id], tile_id)) for start, stop, online_points in read_line_csv_data( csv_file_name, tower_gt): centers = add_point_if_not_nearby( start, stop, [tower_gt[a] for a in online_points]) for i in range(len(centers) - 1): # find the corresponding gt try: connected_pair.append( order_pair(find_point_id(tower_gt, centers[i]), find_point_id(tower_gt, centers[i + 1]))) except AssertionError: pass #visualize_results(img_dir, city_id, tile_id, raw_rgb, line_gt, tower_gt, tower_gt, connected_pair, # None, None) misc_utils.save_file(save_file_name, connected_pair)