Skip to content

Commit eaa6158

Browse files
authored
Create topology.py
1 parent 0a281e8 commit eaa6158

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

topology.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import numpy as np
2+
np.set_printoptions(threshold=np.inf)
3+
adj_file = './model/topology/coco_adj.pkl'
4+
num_classes = 80
5+
t = 0.4
6+
def gen_A(num_classes, t, adj_file):
7+
import pickle
8+
result = pickle.load(open(adj_file, 'rb'))
9+
_adj = result['adj']
10+
return _adj
11+
adj = gen_A(num_classes, t, adj_file)
12+
print(adj)
13+
14+
import networkx as nx
15+
from networkx.algorithms.community import greedy_modularity_communities, naive_greedy_modularity_communities
16+
# G = nx.from_numpy_matrix(adj,create_using=nx.DiGraph())
17+
G = nx.from_numpy_matrix(adj)
18+
c = list(naive_greedy_modularity_communities(G))
19+
print(c)
20+
21+
22+
# [frozenset({0, 2, 4, 5, 6, 8, 9, 10, 11, 16, 18, 25, 28, 30, 31, 33, 34, 36, 37, 40, 44, 48, 49, 56, 58, 59, 60, 62, 63, 64, 65, 67, 68, 72, 73, 74, 76, 79}),
23+
# frozenset({1, 3, 69, 70, 71, 77, 13, 15, 78, 14, 17, 19, 22, 26, 27, 29, 32, 35, 38, 41, 43, 46, 47, 50, 51, 52, 54, 57, 61}),
24+
# frozenset({66, 7, 39, 42, 75, 12, 45, 20, 21, 53, 55, 23, 24})]

0 commit comments

Comments
 (0)