Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
3d654843
Unverified
Commit
3d654843
authored
Aug 19, 2020
by
xiang song(charlie.song)
Committed by
GitHub
Aug 19, 2020
Browse files
Fix mxnet gin (#2048)
Co-authored-by:
Ubuntu
<
ubuntu@ip-172-31-51-214.ec2.internal
>
parent
65866989
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
5 deletions
+8
-5
examples/mxnet/gin/dataloader.py
examples/mxnet/gin/dataloader.py
+3
-2
examples/mxnet/gin/main.py
examples/mxnet/gin/main.py
+4
-2
python/dgl/data/gindt.py
python/dgl/data/gindt.py
+1
-1
No files found.
examples/mxnet/gin/dataloader.py
View file @
3d654843
...
@@ -30,7 +30,8 @@ def collate(samples):
...
@@ -30,7 +30,8 @@ def collate(samples):
g
.
ndata
[
key
]
=
nd
.
array
(
g
.
ndata
[
key
])
g
.
ndata
[
key
]
=
nd
.
array
(
g
.
ndata
[
key
])
# no edge feats
# no edge feats
batched_graph
=
dgl
.
batch
(
graphs
)
batched_graph
=
dgl
.
batch
(
graphs
)
labels
=
nd
.
array
(
labels
)
labels
=
[
nd
.
reshape
(
label
,
(
1
,))
for
label
in
labels
]
labels
=
nd
.
concat
(
*
labels
,
dim
=
0
)
return
batched_graph
,
labels
return
batched_graph
,
labels
class
GraphDataLoader
():
class
GraphDataLoader
():
...
@@ -78,7 +79,7 @@ class GraphDataLoader():
...
@@ -78,7 +79,7 @@ class GraphDataLoader():
skf
=
StratifiedKFold
(
n_splits
=
10
,
shuffle
=
shuffle
,
random_state
=
seed
)
skf
=
StratifiedKFold
(
n_splits
=
10
,
shuffle
=
shuffle
,
random_state
=
seed
)
idx_list
=
[]
idx_list
=
[]
for
idx
in
skf
.
split
(
np
.
zeros
(
len
(
labels
)),
labels
):
# split(x, y)
for
idx
in
skf
.
split
(
np
.
zeros
(
len
(
labels
)),
[
label
.
asnumpy
()
for
label
in
labels
]
):
# split(x, y)
idx_list
.
append
(
idx
)
idx_list
.
append
(
idx
)
train_idx
,
valid_idx
=
idx_list
[
fold_idx
]
train_idx
,
valid_idx
=
idx_list
[
fold_idx
]
...
...
examples/mxnet/gin/main.py
View file @
3d654843
...
@@ -24,6 +24,7 @@ def train(args, net, trainloader, trainer, criterion, epoch):
...
@@ -24,6 +24,7 @@ def train(args, net, trainloader, trainer, criterion, epoch):
feat
=
graphs
.
ndata
[
'attr'
].
astype
(
'float32'
).
as_in_context
(
args
.
device
)
feat
=
graphs
.
ndata
[
'attr'
].
astype
(
'float32'
).
as_in_context
(
args
.
device
)
with
mx
.
autograd
.
record
():
with
mx
.
autograd
.
record
():
graphs
=
graphs
.
to
(
args
.
device
)
outputs
=
net
(
graphs
,
feat
)
outputs
=
net
(
graphs
,
feat
)
loss
=
criterion
(
outputs
,
labels
)
loss
=
criterion
(
outputs
,
labels
)
loss
=
loss
.
sum
()
/
len
(
labels
)
loss
=
loss
.
sum
()
/
len
(
labels
)
...
@@ -54,9 +55,10 @@ def eval_net(args, net, dataloader, criterion):
...
@@ -54,9 +55,10 @@ def eval_net(args, net, dataloader, criterion):
feat
=
graphs
.
ndata
[
'attr'
].
astype
(
'float32'
).
as_in_context
(
args
.
device
)
feat
=
graphs
.
ndata
[
'attr'
].
astype
(
'float32'
).
as_in_context
(
args
.
device
)
total
+=
len
(
labels
)
total
+=
len
(
labels
)
graphs
=
graphs
.
to
(
args
.
device
)
outputs
=
net
(
graphs
,
feat
)
outputs
=
net
(
graphs
,
feat
)
predicted
=
nd
.
argmax
(
outputs
,
axis
=
1
)
predicted
=
nd
.
argmax
(
outputs
,
axis
=
1
)
predicted
=
predicted
.
astype
(
'int64'
)
total_correct
+=
(
predicted
==
labels
).
sum
().
asscalar
()
total_correct
+=
(
predicted
==
labels
).
sum
().
asscalar
()
loss
=
criterion
(
outputs
,
labels
)
loss
=
criterion
(
outputs
,
labels
)
...
...
python/dgl/data/gindt.py
View file @
3d654843
...
@@ -257,7 +257,7 @@ class GINDataset(DGLBuiltinDataset):
...
@@ -257,7 +257,7 @@ class GINDataset(DGLBuiltinDataset):
for
g
in
self
.
graphs
:
for
g
in
self
.
graphs
:
g
.
ndata
[
'attr'
]
=
F
.
tensor
(
np
.
zeros
((
g
.
ndata
[
'attr'
]
=
F
.
tensor
(
np
.
zeros
((
g
.
number_of_nodes
(),
len
(
label2idx
))))
g
.
number_of_nodes
(),
len
(
label2idx
))))
g
.
ndata
[
'attr'
][
range
(
g
.
number_of_nodes
()),
[
label2idx
[
F
.
as_scalar
(
nl
)]
for
nl
in
g
.
ndata
[
'label'
]]]
=
1
g
.
ndata
[
'attr'
][
range
(
g
.
number_of_nodes
()),
[
label2idx
[
F
.
as_scalar
(
F
.
reshape
(
nl
,
(
1
,))
)]
for
nl
in
g
.
ndata
[
'label'
]]]
=
1
# after load, get the #classes and #dim
# after load, get the #classes and #dim
self
.
gclasses
=
len
(
self
.
glabel_dict
)
self
.
gclasses
=
len
(
self
.
glabel_dict
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment