def load_data(self, data): self.gt = {} self.instr_ids = [] scans = [] for item in data: self.gt[str(item['path_id'])] = item if isinstance(item['path_id'], int): self.instr_ids.extend([ '%d_%d' % (item['path_id'], i) for i in range(len(item['instructions'])) ]) else: self.instr_ids.extend([ '%s_%d' % (item['path_id'], i) for i in range(len(item['instructions'])) ]) scans.append(item['scan']) self.instr_ids = set(self.instr_ids) scans = set(scans) new_scans = set.difference(scans, self.scans) if new_scans: for scan in new_scans: self.graphs[scan] = load_nav_graphs(scan) self.distances[scan] = dict( nx.all_pairs_dijkstra_path_length(self.graphs[scan])) self.scans.update(new_scans)
def __init__(self, splits, path_type='planner_path'): self.error_margin = 3.0 self.splits = splits self.gt = {} self.instr_ids = [] self.scans = [] for item in load_datasets(splits): self.gt[item['inst_idx']] = item self.instr_ids.append(item['inst_idx']) self.scans.append(item['scan']) # Add 'trusted_path' to gt metadata if necessary. if path_type == 'trusted_path': planner_goal = item['planner_path'][-1] if planner_goal in item['player_path'][1:]: self.gt[item['inst_idx']]['trusted_path'] = item[ 'player_path'][:] else: self.gt[item['inst_idx']]['trusted_path'] = item[ 'planner_path'][:] self.scans = set(self.scans) self.instr_ids = set(self.instr_ids) self.graphs = load_nav_graphs(self.scans) self.distances = {} self.path_type = path_type for scan, G in self.graphs.iteritems(): # compute all shortest paths self.distances[scan] = dict(nx.all_pairs_dijkstra_path_length(G))
def _compute_shortest_paths(self, scan, path=None): ''' Load connectivity graph for each scan, useful for reasoning about shortest paths ''' graph = utils.load_nav_graphs(scan, path=path) paths = dict( nx.all_pairs_dijkstra_path(graph)) # paths from graph of scan distances = dict(nx.all_pairs_dijkstra_path_length( graph)) # distances for respective paths return graph, paths, distances
def _load_nav_graphs(self): ''' Load connectivity graph for each scan, useful for reasoning about shortest paths ''' print 'Loading navigation graphs for %d scans' % len(self.scans) self.graphs = load_nav_graphs(self.scans) self.paths = {} for scan,G in self.graphs.iteritems(): # compute all shortest paths self.paths[scan] = dict(nx.all_pairs_dijkstra_path(G)) self.distances = {} for scan,G in self.graphs.iteritems(): # compute all shortest paths self.distances[scan] = dict(nx.all_pairs_dijkstra_path_length(G))
def _load_nav_graphs(self): """ Load connectivity graph for each scan, useful for reasoning about shortest paths """ print('Loading navigation graphs for %d scans' % len(self.scans)) self.graphs = load_nav_graphs(self.scans) self.paths = {} for scan, G in self.graphs.items(): # compute all shortest paths self.paths[scan] = dict(nx.all_pairs_dijkstra_path(G)) self.distances = {} for scan, G in self.graphs.items(): # compute all shortest paths self.distances[scan] = dict(nx.all_pairs_dijkstra_path_length(G))
def __init__(self, splits): self.error_margin = 3.0 self.splits = splits self.gt = {} self.instr_ids = [] self.scans = [] for item in load_datasets(splits): self.gt[item['path_id']] = item self.scans.append(item['scan']) self.instr_ids += ['%d_%d' % (item['path_id'],i) for i in range(3)] self.scans = set(self.scans) self.instr_ids = set(self.instr_ids) self.graphs = load_nav_graphs(self.scans) self.distances = {} for scan,G in self.graphs.items(): # compute all shortest paths self.distances[scan] = dict(nx.all_pairs_dijkstra_path_length(G))
def __init__(self, splits): self.error_margin = 3.0 self.splits = splits self.gt = {} self.instr_ids = [] self.scans = [] for item in load_datasets(splits): self.gt[item['path_id']] = item self.scans.append(item['scan']) self.instr_ids += ['%d_%d' % (item['path_id'],i) for i in range(3)] self.scans = set(self.scans) self.instr_ids = set(self.instr_ids) self.graphs = load_nav_graphs(self.scans) self.distances = {} for scan,G in self.graphs.iteritems(): # compute all shortest paths self.distances[scan] = dict(nx.all_pairs_dijkstra_path_length(G))
def _load_nav_graphs(self): """ load graph from self.scan, Store the graph {scan_id: graph} in self.graphs Store the shortest path {scan_id: {view_id_x: {view_id_y: [path]} } } in self.paths Store the distances in self.distances. (Structure see above) Load connectivity graph for each scan, useful for reasoning about shortest paths :return: None """ print('Loading navigation graphs for %d scans' % len(self.scans)) self.graphs = load_nav_graphs(self.scans) self.paths = {} for scan, G in self.graphs.items(): # compute all shortest paths self.paths[scan] = dict(nx.all_pairs_dijkstra_path(G)) self.distances = {} for scan, G in self.graphs.items(): # compute all shortest paths self.distances[scan] = dict(nx.all_pairs_dijkstra_path_length(G))
def __init__(self, splits, path_type='planner_path'): self.error_margin = 3.0 self.splits = splits self.gt = {} self.instr_ids = [] self.scans = [] for item in load_datasets(splits): self.gt[item['inst_idx']] = item self.instr_ids.append(item['inst_idx']) self.scans.append(item['scan']) self.scans = set(self.scans) self.instr_ids = set(self.instr_ids) self.graphs = load_nav_graphs(self.scans) self.distances = {} self.path_type = path_type for scan, G in self.graphs.iteritems(): # compute all shortest paths self.distances[scan] = dict(nx.all_pairs_dijkstra_path_length(G))
def __init__(self, splits, encoder_type): # , subgoal): self.error_margin = 3.0 self.splits = splits self.gt = {} self.instr_ids = [] self.scans = [] for item in load_datasets(splits, "lstm"): # no matter what encoder type ? self.gt[item["path_id"]] = item self.scans.append(item["scan"]) self.instr_ids += [ "%d_%d" % (item["path_id"], i) for i in range(3) ] self.scans = set(self.scans) self.instr_ids = set(self.instr_ids) self.graphs = load_nav_graphs(self.scans) self.distances = {} for scan, G in self.graphs.items(): # compute all shortest paths self.distances[scan] = dict(nx.all_pairs_dijkstra_path_length(G))
def __init__(self, splits, scans, tok): self.error_margin = 3.0 self.splits = splits self.tok = tok self.gt = {} self.instr_ids = [] self.scans = [] for split in splits: for item in load_datasets([split]): if scans is not None and item['scan'] not in scans: continue self.gt[str(item['path_id'])] = item self.scans.append(item['scan']) self.instr_ids += ['%s_%d' % (item['path_id'], i) for i in range(len(item['instructions']))] self.scans = set(self.scans) self.instr_ids = set(self.instr_ids) self.graphs = load_nav_graphs(self.scans) self.distances = {} for scan,G in self.graphs.items(): # compute all shortest paths self.distances[scan] = dict(nx.all_pairs_dijkstra_path_length(G))
def __init__(self, args, splits=['train']): self.args = args # Check for vocabs, build if necessary if not os.path.exists(self.args.train_vocab): tu.write_vocab( tu.build_vocab(self.args.data_dir, splits=["train"]), self.args.train_vocab, ) if not os.path.exists(self.args.trainval_vocab): tu.write_vocab( tu.build_vocab(self.args.data_dir, splits=["train", "val_seen", "val_unseen"]), self.args.trainval_vocab, ) # Load vocab and set tokenizer etc if self.args.train_split == 'trainval': self.vocab = tu.read_vocab(self.args.trainval_vocab) else: self.vocab = tu.read_vocab(self.args.train_vocab) self.args.vocab_size = len(self.vocab) self.tokenizer = tu.Tokenizer(self.vocab, self.args.max_input_length) # Load training and val data # data: [{"scan", "instr_id", "path", "heading", "instruction", "encoding", "xyzhe"}] self.data = [] self.scans = [] for item in tu.load_datasets(self.args.data_dir, splits): # Split multiple instructions into separate entries for j,instr in enumerate(item['instructions']): self.scans.append(item['scan']) train_obj = { 'heading': item['heading'], 'scan': item['scan'], 'instruction': instr, 'instr_id': '%d_%d' % (item['path_id'], j), 'encoding': self.text_to_encoding(instr), 'path': item['path'] } self.data.append(train_obj) self.scans = set(self.scans) self.splits = splits random.shuffle(self.data) self.reset_epoch() print('Loaded %d data tuples from %s' % (len(self.data), self.splits)) # Load connectivity graph for each scan, useful for reasoning about shortest paths print('Loading navigation graphs for %d scans' % len(self.scans)) self.graphs = load_nav_graphs(self.scans) self.paths = {} for scan,G in self.graphs.items(): # compute all shortest paths self.paths[scan] = dict(nx.all_pairs_dijkstra_path(G)) self.distances = {} for scan,G in self.graphs.items(): # compute all shortest paths self.distances[scan] = dict(nx.all_pairs_dijkstra_path_length(G)) # Pre-calculate the position and heading along each path for item in self.data: G = self.graphs[item['scan']] item['xyzhe'] = xyzhe_from_viewpoints(G, item['path'], item['heading'])
def __init__( self, splits, sim=None, args=None, ): prefix = args.prefix error_margin = args.error_margin add_asterix = args.add_asterix self.error_margin = error_margin self.splits = splits self.gt = {} self.instr_ids = [] self.scans = [] self.instructions = {} counts = defaultdict(int) if prefix in ['r2r', 'R2R'] or 'RxR' in prefix: instr_key = 'path_id' elif prefix == 'REVERIE': instr_key = 'id' else: raise NotImplementedError( 'dataset prefix {} not implemented'.format(prefix)) for item in load_datasets(splits, prefix=prefix): path_id = item[instr_key] count = counts[path_id] counts[path_id] += 1 if add_asterix: new_path_id = '{}*{}'.format(path_id, count) item['path_id'] = new_path_id self.gt['{}'.format(item[instr_key])] = item self.scans.append(item['scan']) if prefix == 'R2R': self.instr_ids += [ '{}_{}'.format(item[instr_key], i) for i in range(3) ] elif 'RxR' in prefix: self.instr_ids += [ '{}_{}'.format(item[instr_key], i) for i in range(1) ] elif 'REVERIE' == prefix: self.instr_ids += [ '{}_{}'.format(item[instr_key], i) for i in range(len(item['instructions'])) ] # pdb.set_trace() else: raise NotImplementedError() for j, instruction in enumerate(item['instructions']): self.instructions['{}_{}'.format(item[instr_key], j)] = instruction self.scans = set(self.scans) self.instr_ids = set(self.instr_ids) self.graphs = load_nav_graphs(self.scans) self.distances = {} for scan, G in self.graphs.items(): # compute all shortest paths self.distances[scan] = dict(nx.all_pairs_dijkstra_path_length(G))
cnt[x] += 1 return cnt['lost'] / total * 100, cnt['uncertain_wrong'] / total * 100, \ cnt['already_asked'] / total * 100 data_path = '../../../data' graphs = {} distances = {} with open(os.path.join(data_path, 'hanna/scan_split.json')) as f: scan_split = json.load(f) for split in ['train', 'val', 'test']: for scan in scan_split[split]: graphs[scan] = load_nav_graphs(scan) distances[scan] = dict(nx.all_pairs_dijkstra_path_length(graphs[scan])) filename = sys.argv[1] with open(filename) as f: data = json.load(f) print('Success rate: %.2f' % success_rate(data)) print('SPL: %.2f' % spl_score(data)) print('Navigation error: %.2f' % navigation_error(data)) print('Requests: %.1f' % num_requests(data)) print('Nav mistake repeat: %.2f' % nav_mistake_repeat(data)) print('Ask repeat: %.2f' % ask_repeat(data)) for reason in ['lost', 'uncertain_wrong', 'already_asked']: print_values = (reason, ) + reason_metrics(data, reason)