'cache': tiles.cache, 'starting_locations': starting_locations, 'gc': tiles.gcs[tile.region], 'edge_counts': {}, }) print('extracted {} subtiles from {} tiles (missing {})'.format( len(subtiles), len(tiles.train_tiles), 4 * len(tiles.train_tiles) - len(subtiles))) # initialize paths, one per subtile print('loading initial paths') paths = [] for i, subtile in enumerate(subtiles): start_loc = random.choice(subtile['starting_locations']) paths.append(model_utils.Path(subtile['gc'], subtile, start_loc=start_loc)) num_sets = (len(paths) + PARALLEL_PATHS - 1) // PARALLEL_PATHS best_accuracy = None angle_losses = [] detect_losses = [] action_losses = [] losses = [] def vector_to_action(angle_outputs, stop_outputs): x = numpy.zeros((64, ), dtype='float32') if stop_outputs[0] > THRESHOLD: x[numpy.argmax(angle_outputs)] = 1 return x
r = geom.Rectangle(geom.Point(x * 4096, y * 4096), geom.Point((x + 1) * 4096, (y + 1) * 4096)) g = graph.read_graph(EXISTING_GRAPH_FNAME) gc = graph.GraphContainer(g) g = g.clone() graph.densify(g, SEGMENT_LENGTH) tile_data = { 'region': REGION, 'rect': r, 'search_rect': r.add_tol(-WINDOW_SIZE // 2), 'cache': tiles.cache, 'starting_locations': [], } #path = model_utils.Path(gc, tile_data, g=g) path = model_utils.Path(None, tile_data, g=g) for vertex in g.vertices: vertex.edge_pos = None path.prepend_search_vertex(vertex) big_ims = tile_data['cache'].get(tile_data['region'], tile_data['rect']) m6_old = tf_util.apply_conv(session, m, big_ims['input'], scale=4, channels=64) m6_new = tf_util.apply_conv(session, m, big_ims['input1'], scale=4,
pos2_pos = match_point(pos2_point) else: next_positions = graph.follow_graph(pos1_pos, SEGMENT_LENGTH) pos2_point = next_positions[0].point() pos2_pos = next_positions[0] start_loc = [{ 'point': pos1_point, 'edge_pos': pos1_pos, }, { 'point': pos2_point, 'edge_pos': pos2_pos, }] path = model_utils.Path(tile_data['gc'], tile_data, start_loc=start_loc) else: g = graph.read_graph(EXISTING_GRAPH_FNAME) graph.densify(g, SEGMENT_LENGTH) r = g.bounds() tile_data = { 'region': REGION, 'rect': r.add_tol(WINDOW_SIZE / 2), 'search_rect': r, 'cache': tiles.cache, 'starting_locations': [], } path = model_utils.Path(tiles.get_gc(REGION), tile_data, g=g) skip_vertices = set()
pos2_point = MANUAL_POINT2.add(MANUAL_RELATIVE) pos2_pos = match_point(pos2_point) else: next_positions = graph.follow_graph(pos1_pos, SEGMENT_LENGTH) pos2_point = next_positions[0].point() pos2_pos = next_positions[0] start_loc = [{ 'point': pos1_point, 'edge_pos': pos1_pos, }, { 'point': pos2_point, 'edge_pos': pos2_pos, }] path = model_utils.Path(tile_data['gc'], tile_data, start_loc=start_loc) else: g = graph.read_graph(EXISTING_GRAPH_FNAME) r = g.bounds() tile_data = { 'region': REGION, 'rect': r.add_tol(WINDOW_SIZE/2), 'search_rect': r, 'cache': cache, 'starting_locations': [], } path = model_utils.Path(None, tile_data, g=g) for vertex in g.vertices: path.prepend_search_vertex(vertex) compute_targets = SAVE_EXAMPLES or FOLLOW_TARGETS
g = graph.read_graph(EXISTING_GRAPH_FNAME) if not USE_GRAPH_RECT: rect = geom.Rectangle(TILE_START, TILE_END) g = g.edgeIndex().subgraph(rect) r = rect.add_tol(-WINDOW_SIZE / 2) else: r = g.bounds().add_tol(-WINDOW_SIZE / 2) graph.densify(g, SEGMENT_LENGTH) tile_data = { 'region': REGION, 'rect': r.add_tol(WINDOW_SIZE / 2), 'search_rect': r, 'cache': tiles.cache, 'starting_locations': [], } path = model_utils.Path(tiles.get_gc(REGION), tile_data, g=g) skip_vertices = set() if FILTER_BY_TAG: with open(FILTER_BY_TAG, 'r') as f: edge_tags = {int(k): v for k, v in json.load(f).items()} for edge in g.edges: tags = edge_tags[edge.orig_id()] if 'highway' not in tags or tags['highway'] in [ 'pedestrian', 'footway', 'path', 'cycleway', 'construction' ]: for vertex in [edge.src, edge.dst]: skip_vertices.add(vertex) for vertex in g.vertices: vertex.edge_pos = None if vertex not in skip_vertices: