Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PGL
提交
4fde0157
P
PGL
项目概览
PaddlePaddle
/
PGL
通知
76
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
11
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PGL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
11
Issue
11
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4fde0157
编写于
7月 08, 2020
作者:
Z
Zhong Hui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
small bug fix
上级
216e2829
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
17 deletion
+21
-17
ogb_examples/nodeproppred/ogbn-mag/main.py
ogb_examples/nodeproppred/ogbn-mag/main.py
+13
-9
ogb_examples/nodeproppred/ogbn-mag/rgcn.py
ogb_examples/nodeproppred/ogbn-mag/rgcn.py
+7
-7
pgl/contrib/ogb/io/read_graph_pgl.py
pgl/contrib/ogb/io/read_graph_pgl.py
+1
-1
未找到文件。
ogb_examples/nodeproppred/ogbn-mag/main.py
浏览文件 @
4fde0157
...
...
@@ -13,7 +13,7 @@
# limitations under the License.
import
os
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
]
=
'
0
'
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
]
=
'
3
'
os
.
environ
[
'CPU_NUM'
]
=
str
(
20
)
import
numpy
as
np
import
copy
...
...
@@ -32,9 +32,13 @@ from pgl.utils.share_numpy import ToShareMemGraph
def
hetero2homo
(
heterograph
):
edge
=
[]
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
)
edges
=
np
.
vstack
(
edge
)
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
()
ToShareMemGraph
(
g
)
return
g
...
...
@@ -83,9 +87,9 @@ def graph_saint_random_walk_sample(graph,
sample_nodes
=
[]
for
walk
in
walks
:
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
)
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
)
subgraph
=
hetergraph
.
subgraph
(
...
...
@@ -212,8 +216,8 @@ def run_epoch(exe, loss, acc, homograph, hetergraph, gw, train_program,
phase
,
homograph
,
hetergraph
,
gw
,
split_real_idx
[
phase
][
'paper'
],
all_label
[
'paper'
][
split_idx
[
phase
][
'paper'
]]):
print
(
"train_shape
\t
"
,
feed_dict
[
'train_index'
].
shape
)
print
(
"allnode_shape
\t
"
,
feed_dict
[
'sub_node_index'
].
shape
)
#
print("train_shape\t", feed_dict['train_index'].shape)
#
print("allnode_shape\t", feed_dict['sub_node_index'].shape)
res
=
exe
.
run
(
train_program
if
phase
==
'train'
else
test_program
,
# test_program,
...
...
@@ -265,8 +269,8 @@ def main():
train_index
=
split_real_idx
[
'train'
][
'paper'
]
homograph
.
_node_feat
[
'train_label'
][
train_index
]
=
train_label
#
place = fluid.CUDAPlace(0)
place
=
fluid
.
CPUPlace
()
place
=
fluid
.
CUDAPlace
(
0
)
#
place = fluid.CPUPlace()
train_program
=
fluid
.
Program
()
startup_program
=
fluid
.
Program
()
test_program
=
fluid
.
Program
()
...
...
@@ -288,7 +292,7 @@ def main():
default_initializer
=
fluid
.
initializer
.
NumpyArrayInitializer
(
extact_index
),
name
=
'paper_index'
)
#paper_feature.stop_gradient=
True
paper_feature
.
stop_gradient
=
True
paper_index
.
stop_gradient
=
True
sub_node_index
=
fluid
.
layers
.
data
(
...
...
@@ -314,7 +318,7 @@ def main():
#feat = paper_mask(feat, gw, start_paper_index)
feat
=
fluid
.
layers
.
gather
(
feat
,
train_index
)
loss
,
logit
,
acc
=
softmax_loss
(
feat
,
label
,
num_class
)
opt
=
fluid
.
optimizer
.
AdamOptimizer
(
learning_rate
=
0.00
2
)
opt
=
fluid
.
optimizer
.
AdamOptimizer
(
learning_rate
=
0.00
5
)
opt
.
minimize
(
loss
)
test_program
=
train_program
.
clone
(
for_test
=
True
)
...
...
ogb_examples/nodeproppred/ogbn-mag/rgcn.py
浏览文件 @
4fde0157
...
...
@@ -42,14 +42,14 @@ def rgcn_conv(graph_wrapper,
output
=
None
for
i
in
range
(
len
(
edge_types
)):
assert
feature
is
not
None
feature
=
fluid
.
layers
.
fc
(
tmp_feat
=
fluid
.
layers
.
fc
(
feature
,
size
=
hidden_size
,
param_attr
=
fluid
.
ParamAttr
(
name
=
'%s_
edg
e_fc_%s'
%
(
name
,
edge_types
[
i
])),
param_attr
=
fluid
.
ParamAttr
(
name
=
'%s_
nod
e_fc_%s'
%
(
name
,
edge_types
[
i
]
.
split
(
"2"
)[
0
]
)),
act
=
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
)])
neigh_feat
=
gw
[
edge_types
[
i
]].
recv
(
msg
,
__reduce
)
# The weight of FC should be the same for the same type of node
...
...
@@ -57,10 +57,10 @@ def rgcn_conv(graph_wrapper,
neigh_feat
=
fluid
.
layers
.
fc
(
neigh_feat
,
size
=
hidden_size
,
param_attr
=
fluid
.
ParamAttr
(
name
=
'%s_
nod
e_fc_%s'
%
(
name
,
edge_types
[
i
]
.
split
(
"2"
)[
-
1
]
)),
param_attr
=
fluid
.
ParamAttr
(
name
=
'%s_
edg
e_fc_%s'
%
(
name
,
edge_types
[
i
])),
act
=
None
)
output
=
output
+
neigh_feat
output
=
output
+
neigh_feat
*
tmp_feat
#output = fluid.layers.relu(out)
return
output
...
...
pgl/contrib/ogb/io/read_graph_pgl.py
浏览文件 @
4fde0157
...
...
@@ -81,7 +81,7 @@ def read_csv_heterograph_pgl(raw_dir,
inverse_v
=
np
.
array
(
v
)
inverse_v
[
0
,
:]
=
v
[
1
,
:]
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
[
2
][
0
],
k
[
0
][
0
])]
=
inverse_v
.
T
else
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录