提交 4fde0157 编写于 作者: Z Zhong Hui

small bug fix

上级 216e2829
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# limitations under the License. # limitations under the License.
import os import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0' os.environ['CUDA_VISIBLE_DEVICES'] = '3'
os.environ['CPU_NUM'] = str(20) os.environ['CPU_NUM'] = str(20)
import numpy as np import numpy as np
import copy import copy
...@@ -32,9 +32,13 @@ from pgl.utils.share_numpy import ToShareMemGraph ...@@ -32,9 +32,13 @@ from pgl.utils.share_numpy import ToShareMemGraph
def hetero2homo(heterograph): def hetero2homo(heterograph):
edge = [] edge = []
for edge_type in heterograph.edge_types_info(): for edge_type in heterograph.edge_types_info():
print('edge_type: ', edge_type, ' shape of edges : ',
heterograph[edge_type].edges.shape)
edge.append(heterograph[edge_type].edges) edge.append(heterograph[edge_type].edges)
edges = np.vstack(edge) edges = np.vstack(edge)
g = pgl.graph.Graph(num_nodes=heterograph.num_nodes, edges=edges) g = pgl.graph.Graph(num_nodes=heterograph.num_nodes, edges=edges)
print('homo graph nodes ', g.num_nodes)
print('homo graph edges ', g.num_edges)
g.outdegree() g.outdegree()
ToShareMemGraph(g) ToShareMemGraph(g)
return g return g
...@@ -83,9 +87,9 @@ def graph_saint_random_walk_sample(graph, ...@@ -83,9 +87,9 @@ def graph_saint_random_walk_sample(graph,
sample_nodes = [] sample_nodes = []
for walk in walks: for walk in walks:
sample_nodes.extend(walk) sample_nodes.extend(walk)
print("length of sample_nodes ", len(sample_nodes)) #print("length of sample_nodes ", len(sample_nodes))
sample_nodes = np.unique(sample_nodes) sample_nodes = np.unique(sample_nodes)
print("length of unique sample_nodes ", len(sample_nodes)) #print("length of unique sample_nodes ", len(sample_nodes))
eids = extract_edges_from_nodes(hetergraph, sample_nodes) eids = extract_edges_from_nodes(hetergraph, sample_nodes)
subgraph = hetergraph.subgraph( subgraph = hetergraph.subgraph(
...@@ -212,8 +216,8 @@ def run_epoch(exe, loss, acc, homograph, hetergraph, gw, train_program, ...@@ -212,8 +216,8 @@ def run_epoch(exe, loss, acc, homograph, hetergraph, gw, train_program,
phase, homograph, hetergraph, gw, phase, homograph, hetergraph, gw,
split_real_idx[phase]['paper'], split_real_idx[phase]['paper'],
all_label['paper'][split_idx[phase]['paper']]): all_label['paper'][split_idx[phase]['paper']]):
print("train_shape\t", feed_dict['train_index'].shape) #print("train_shape\t", feed_dict['train_index'].shape)
print("allnode_shape\t", feed_dict['sub_node_index'].shape) #print("allnode_shape\t", feed_dict['sub_node_index'].shape)
res = exe.run( res = exe.run(
train_program if phase == 'train' else test_program, train_program if phase == 'train' else test_program,
# test_program, # test_program,
...@@ -265,8 +269,8 @@ def main(): ...@@ -265,8 +269,8 @@ def main():
train_index = split_real_idx['train']['paper'] train_index = split_real_idx['train']['paper']
homograph._node_feat['train_label'][train_index] = train_label homograph._node_feat['train_label'][train_index] = train_label
#place = fluid.CUDAPlace(0) place = fluid.CUDAPlace(0)
place = fluid.CPUPlace() #place = fluid.CPUPlace()
train_program = fluid.Program() train_program = fluid.Program()
startup_program = fluid.Program() startup_program = fluid.Program()
test_program = fluid.Program() test_program = fluid.Program()
...@@ -288,7 +292,7 @@ def main(): ...@@ -288,7 +292,7 @@ def main():
default_initializer=fluid.initializer.NumpyArrayInitializer( default_initializer=fluid.initializer.NumpyArrayInitializer(
extact_index), extact_index),
name='paper_index') name='paper_index')
#paper_feature.stop_gradient=True paper_feature.stop_gradient = True
paper_index.stop_gradient = True paper_index.stop_gradient = True
sub_node_index = fluid.layers.data( sub_node_index = fluid.layers.data(
...@@ -314,7 +318,7 @@ def main(): ...@@ -314,7 +318,7 @@ def main():
#feat = paper_mask(feat, gw, start_paper_index) #feat = paper_mask(feat, gw, start_paper_index)
feat = fluid.layers.gather(feat, train_index) feat = fluid.layers.gather(feat, train_index)
loss, logit, acc = softmax_loss(feat, label, num_class) loss, logit, acc = softmax_loss(feat, label, num_class)
opt = fluid.optimizer.AdamOptimizer(learning_rate=0.002) opt = fluid.optimizer.AdamOptimizer(learning_rate=0.005)
opt.minimize(loss) opt.minimize(loss)
test_program = train_program.clone(for_test=True) test_program = train_program.clone(for_test=True)
......
...@@ -42,14 +42,14 @@ def rgcn_conv(graph_wrapper, ...@@ -42,14 +42,14 @@ def rgcn_conv(graph_wrapper,
output = None output = None
for i in range(len(edge_types)): for i in range(len(edge_types)):
assert feature is not None assert feature is not None
feature = fluid.layers.fc( tmp_feat = fluid.layers.fc(
feature, feature,
size=hidden_size, size=hidden_size,
param_attr=fluid.ParamAttr(name='%s_edge_fc_%s' % param_attr=fluid.ParamAttr(name='%s_node_fc_%s' %
(name, edge_types[i])), (name, edge_types[i].split("2")[0])),
act=None) act=None)
if output is None: if output is None:
output = fluid.layers.zeros_like(feature) output = fluid.layers.zeros_like(tmp_feat)
msg = gw[edge_types[i]].send(__message, nfeat_list=[('h', feature)]) msg = gw[edge_types[i]].send(__message, nfeat_list=[('h', feature)])
neigh_feat = gw[edge_types[i]].recv(msg, __reduce) neigh_feat = gw[edge_types[i]].recv(msg, __reduce)
# The weight of FC should be the same for the same type of node # The weight of FC should be the same for the same type of node
...@@ -57,10 +57,10 @@ def rgcn_conv(graph_wrapper, ...@@ -57,10 +57,10 @@ def rgcn_conv(graph_wrapper,
neigh_feat = fluid.layers.fc( neigh_feat = fluid.layers.fc(
neigh_feat, neigh_feat,
size=hidden_size, size=hidden_size,
param_attr=fluid.ParamAttr(name='%s_node_fc_%s' % param_attr=fluid.ParamAttr(name='%s_edge_fc_%s' %
(name, edge_types[i].split("2")[-1])), (name, edge_types[i])),
act=None) act=None)
output = output + neigh_feat output = output + neigh_feat * tmp_feat
#output = fluid.layers.relu(out) #output = fluid.layers.relu(out)
return output return output
......
...@@ -81,7 +81,7 @@ def read_csv_heterograph_pgl(raw_dir, ...@@ -81,7 +81,7 @@ def read_csv_heterograph_pgl(raw_dir,
inverse_v = np.array(v) inverse_v = np.array(v)
inverse_v[0, :] = v[1, :] inverse_v[0, :] = v[1, :]
inverse_v[1, :] = v[0, :] inverse_v[1, :] = v[0, :]
if k[0] != k[1]: if k[0] != k[2]:
edges_by_types["{}2{}".format(k[0][0], k[2][0])] = v.T edges_by_types["{}2{}".format(k[0][0], k[2][0])] = v.T
edges_by_types["{}2{}".format(k[2][0], k[0][0])] = inverse_v.T edges_by_types["{}2{}".format(k[2][0], k[0][0])] = inverse_v.T
else: else:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册