def get_train_data(): train_x_y = [] global flag0_count global flag1_count flag0_count = 0 flag1_count = 0 sess = tf.InteractiveSession() for i in range(1, 10): file_path_community = './0814data/%d/community-standard.txt' % i file_path_network = './0814data/%d/network.txt' % i # print(file_path_network) social_list = cnn_socialNet_read_data.get_standard_network( file_path_community) my_graph = cnn_socialNet_read_data.get_graph(file_path_network) cnn_socialNet_read_data.add_flag_graph(my_graph, social_list) edges = [] for (u, v, flag) in my_graph.edges.data('flag'): # print(u, v, flag) if int(flag) == 0: flag0_count = flag0_count + 1 else: flag1_count = flag1_count + 1 edges.append(((u, v), flag)) for j in range(len(edges)): matrix1, row1, clown1 = cnn_socialNet_deal_data.get_jump1_3dimension_different_size_matrix( my_graph, edges[j][0]) image1 = tf.convert_to_tensor(matrix1) image1 = tf.image.convert_image_dtype(image1, tf.float32) resize_image1 = tf.image.resize_images(image1, [128, 128], method=3) img_numpy1 = resize_image1.eval(session=sess) matrix2, row2, clown2 = cnn_socialNet_deal_data.get_jump2_3dimension_different_size_matrix( my_graph, edges[j][0]) image2 = tf.convert_to_tensor(matrix2) image2 = tf.image.convert_image_dtype(image2, tf.float32) resize_image2 = tf.image.resize_images(image2, [128, 128], method=3) img_numpy2 = resize_image2.eval(session=sess) # print('resize_iamge', img_numpy) # matrix1 = tf.constant(resize_image).eval() # print(edges[j][1]) if int(edges[j][1]) == 1: label = [1, 0] else: label = [0, 1] train_x_y.append((img_numpy1, img_numpy2, label)) sess.close() return train_x_y, flag0_count, flag1_count
def get_train_data(): train_x_y = [] global flag0_count global flag1_count flag0_count = 0 flag1_count = 0 sess = tf.InteractiveSession() file_path_community = './small_data/karate-standard.txt' file_path_network = './small_data/karate-edges.txt' # print(file_path_network) social_list = cnn_socialNet_read_data.get_standard_network( file_path_community) print(social_list) my_graph = cnn_socialNet_read_data.get_graph(file_path_network, split=',') print(my_graph.edges) cnn_socialNet_read_data.add_flag_graph(my_graph, social_list) edges = [] for (u, v, flag) in my_graph.edges.data('flag'): print(u, v, flag) if int(flag) == 0: flag0_count = flag0_count + 1 else: flag1_count = flag1_count + 1 edges.append(((u, v), flag)) for j in range(len(edges)): matrix, row, clown = cnn_socialNet_deal_data.get_jump1_3dimension_different_size_matrix( my_graph, edges[j][0]) image = tf.convert_to_tensor(matrix) image = tf.image.convert_image_dtype(image, tf.float32) resize_image = tf.image.resize_images(image, [128, 128], method=3) img_numpy = resize_image.eval(session=sess) # print('resize_iamge', img_numpy) # matrix1 = tf.constant(resize_image).eval() # print(edges[j][1]) if int(edges[j][1]) == 1: label = [1, 0] else: label = [0, 1] train_x_y.append((img_numpy, label)) sess.close() return train_x_y, flag0_count, flag1_count
import networkx as nx import cnn_socialNet_read_data file_path = './0814data/1/community-standard.txt' test_file_path = './0814data/test_community.txt' social_list = cnn_socialNet_read_data.get_standard_network(test_file_path) print(social_list) # 测试获取网络 test_network = './0814data/test_nodes.txt' network_file_path = '0814data/1/network.txt' test_G = cnn_socialNet_read_data.get_graph(test_network) print(test_G.edges()) # 测试为网络中每条边添加flag属性 edges = [] cnn_socialNet_read_data.add_flag_graph(test_G, social_list) for (u, v, flag) in test_G.edges.data('flag'): print(u, v, flag) edges.append(((u, v), int(flag))) # 划分社区算法 visited = {} def breadth_first_search(root=None): queue = [] social = [] nodes = test_G.nodes def bfs(first_node): order = [first_node]