def generate_networkx_graphs(rand, num_examples, num_nodes_min_max, theta): """Generate graphs for training. Args: rand: A random seed (np.RandomState instance). num_examples: Total number of graphs to generate. num_nodes_min_max: A 2-tuple with the [lower, upper) number of nodes per graph. The number of nodes for a graph is uniformly sampled within this range. theta: (optional) A `float` threshold parameters for the geographic threshold graph's threshold. Default= the number of nodes. Returns: input_graphs: The list of input graphs. target_graphs: The list of output graphs. graphs: The list of generated graphs. """ input_graphs = [] target_graphs = [] graphs = [] for _ in range(num_examples): graph = generate_graph(rand, num_nodes_min_max, theta=theta)[0] graph = add_shortest_path(rand, graph) input_graph, target_graph = graph_to_input_target(graph) input_graphs.append(input_graph) target_graphs.append(target_graph) graphs.append(graph) return input_graphs, target_graphs, graphs
def generate_graphs(img_path, solution_path, region, j, placeholder=False): img = imageio.imread(img_path) img_solution = imageio.imread(solution_path) img = np.array(img) img_solution = np.array(img_solution) img_subsample = img[::2, ::2] img_solution_subsample = img_solution[::2, ::2] images = slice_blocks(img_subsample, 128, 128) #images = add_arrays(images, slice_blocks(img, 128, 128)) images_solutions = slice_blocks(img_solution_subsample, 128, 128) images_solutions = add_arrays(images_solutions, slice_blocks(img_solution, 128, 128)) # if placeholder == True: # index = j * 4096 - 1 # j2 = j + 1 # else: # # j2 = 1 graphs = [] # iterace radky a sloupce for i in range(len(images)): index = 0 * 4096 - 1 graph = nx.Graph() for row in range(0, 128): for column in range(0, 128): index += 1 node_solution = 0 value = images[i][row][column] / 255 if images_solutions[i][row][column] == 255: node_solution = 1 # pridani uzlu graph.add_node(index, value=value, solution=node_solution) # pridani hran add_edges_to_graph(index, graph, img, row, column, region, images_solutions[i]) graphs.append(graph) return graphs
def generate_networkx_graphs(graphcache,all_db,rand,num_examples,dataset): """Generate graphs for training. Args: rand: A random seed (np.RandomState instance). num_examples: Total number of graphs to generate. dataset: 'train', 'val', 'test' Returns: input_graphs: The list of input graphs. target_graphs: The list of output graphs. graphs: The list of generated graphs. """ input_graphs = [] target_graphs = [] graphs = [] totnum = len(all_db[dataset]) if totnum==num_examples: selids = np.arange(totnum) else: selids = rand.choice(totnum,num_examples) for ni in range(num_examples): #print(all_db[dataset][selids[ni]]) if dataset == 'test': tt = True da = False elif dataset == 'val': tt = False da = False else: tt = False da = True graph = generate_graph(graphcache,all_db[dataset][selids[ni]],rand,data_aug=da,test=tt) #graph = add_shortest_path(rand, graph) input_graph, target_graph = graph_to_input_target(graph) input_graphs.append(input_graph) target_graphs.append(target_graph) graphs.append(graph) return input_graphs, target_graphs, graphs, selids