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
1f931011
Unverified
Commit
1f931011
authored
Jul 26, 2023
by
Andrei Ivanov
Committed by
GitHub
Jul 27, 2023
Browse files
Improving the GATv2 example. (#6035)
Co-authored-by:
Hongzhi (Steve), Chen
<
chenhongzhi.nkcs@gmail.com
>
parent
017d9d40
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
22 deletions
+22
-22
examples/pytorch/gatv2/train.py
examples/pytorch/gatv2/train.py
+22
-22
No files found.
examples/pytorch/gatv2/train.py
View file @
1f931011
...
@@ -89,7 +89,7 @@ def main(args):
...
@@ -89,7 +89,7 @@ def main(args):
val_mask
=
g
.
ndata
[
"val_mask"
]
val_mask
=
g
.
ndata
[
"val_mask"
]
test_mask
=
g
.
ndata
[
"test_mask"
]
test_mask
=
g
.
ndata
[
"test_mask"
]
num_feats
=
features
.
shape
[
1
]
num_feats
=
features
.
shape
[
1
]
n_classes
=
data
.
num_la
bel
s
n_classes
=
data
.
num_
c
la
sse
s
n_edges
=
g
.
num_edges
()
n_edges
=
g
.
num_edges
()
print
(
print
(
"""----Data statistics------'
"""----Data statistics------'
...
@@ -138,7 +138,7 @@ def main(args):
...
@@ -138,7 +138,7 @@ def main(args):
)
)
# initialize graph
# initialize graph
dur
=
[]
mean
=
0
for
epoch
in
range
(
args
.
epochs
):
for
epoch
in
range
(
args
.
epochs
):
model
.
train
()
model
.
train
()
if
epoch
>=
3
:
if
epoch
>=
3
:
...
@@ -152,29 +152,29 @@ def main(args):
...
@@ -152,29 +152,29 @@ def main(args):
optimizer
.
step
()
optimizer
.
step
()
if
epoch
>=
3
:
if
epoch
>=
3
:
dur
.
append
(
time
.
time
()
-
t0
)
mean
=
(
mean
*
(
epoch
-
3
)
+
(
time
.
time
()
-
t0
)
)
/
(
epoch
-
2
)
train_acc
=
accuracy
(
logits
[
train_mask
],
labels
[
train_mask
])
train_acc
=
accuracy
(
logits
[
train_mask
],
labels
[
train_mask
])
if
args
.
fastmode
:
if
args
.
fastmode
:
val_acc
=
accuracy
(
logits
[
val_mask
],
labels
[
val_mask
])
val_acc
=
accuracy
(
logits
[
val_mask
],
labels
[
val_mask
])
else
:
else
:
val_acc
=
evaluate
(
g
,
model
,
features
,
labels
,
val_mask
)
val_acc
=
evaluate
(
g
,
model
,
features
,
labels
,
val_mask
)
if
args
.
early_stop
:
if
args
.
early_stop
:
if
stopper
.
step
(
val_acc
,
model
):
if
stopper
.
step
(
val_acc
,
model
):
break
break
print
(
print
(
"Epoch {:05d} | Time(s) {:.4f} | Loss {:.4f} | TrainAcc {:.4f} |"
"Epoch {:05d} | Time(s) {:.4f} | Loss {:.4f} | TrainAcc {:.4f} |"
" ValAcc {:.4f} | ETputs(KTEPS) {:.2f}"
.
format
(
" ValAcc {:.4f} | ETputs(KTEPS) {:.2f}"
.
format
(
epoch
,
epoch
,
np
.
mean
(
dur
),
mean
,
loss
.
item
(),
loss
.
item
(),
train_acc
,
train_acc
,
val_acc
,
val_acc
,
n_edges
/
np
.
mean
(
dur
)
/
1000
,
n_edges
/
mean
/
1000
,
)
)
)
)
print
()
print
()
if
args
.
early_stop
:
if
args
.
early_stop
:
...
...
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