Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
graph4stackoverflow
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Liam Byrne
graph4stackoverflow
Commits
a6d7f72c
Commit
a6d7f72c
authored
2 years ago
by
Liam Byrne
Browse files
Options
Downloads
Patches
Plain Diff
save model function
parent
bec698da
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
embeddings/hetero_GAT.py
+10
-3
10 additions, 3 deletions
embeddings/hetero_GAT.py
with
10 additions
and
3 deletions
embeddings/hetero_GAT.py
+
10
−
3
View file @
a6d7f72c
import
json
import
logging
import
os
import
string
import
time
...
...
@@ -161,6 +162,9 @@ def start_wandb_for_training(wandb_project_name: str, wandb_run_name: str):
wandb
.
init
(
project
=
wandb_project_name
,
name
=
wandb_run_name
)
#wandb.use_artifact("static-graphs:latest")
def
save_model
(
model
,
model_name
:
str
):
torch
.
save
(
model
.
state_dict
(),
os
.
path
.
join
(
"
..
"
,
"
models
"
,
model_name
))
if
__name__
==
'
__main__
'
:
device
=
torch
.
device
(
"
cuda
"
if
torch
.
cuda
.
is_available
()
else
"
cpu
"
)
log
.
info
(
f
"
Proceeding with
{
device
}
. .
"
)
...
...
@@ -210,7 +214,7 @@ if __name__ == '__main__':
sampler
=
torch
.
utils
.
data
.
WeightedRandomSampler
([
class_weights
[
x
]
for
x
in
train_labels
],
len
(
train_labels
))
# Dataloaders
train_loader
=
DataLoader
(
train_dataset
,
sampler
=
sampler
,
batch_size
=
512
)
train_loader
=
DataLoader
(
train_dataset
,
sampler
=
sampler
,
batch_size
=
64
)
val_loader
=
DataLoader
(
val_dataset
,
batch_size
=
16
)
test_loader
=
DataLoader
(
test_dataset
,
batch_size
=
16
)
...
...
@@ -220,14 +224,16 @@ if __name__ == '__main__':
optimizer
=
torch
.
optim
.
Adam
(
model
.
parameters
(),
lr
=
0.001
)
criterion
=
torch
.
nn
.
CrossEntropyLoss
()
for
epoch
in
range
(
1
,
10
):
for
epoch
in
range
(
1
,
5
):
log
.
info
(
f
"
Epoch:
{
epoch
:
03
d
}
> > >
"
)
train
(
model
,
train_loader
)
train_acc
,
train_f1
,
train_loss
,
train_table
=
test
(
train_loader
)
val_acc
,
val_f1
,
val_loss
,
val_table
=
test
(
val_loader
)
test_acc
,
test_f1
,
test_loss
,
test_table
=
test
(
test_loader
)
print
(
f
'
Epoch:
{
epoch
:
03
d
}
, Train F1:
{
train_f1
:
.
4
f
}
, Validation F1:
{
val_f1
:
.
4
f
}
'
)
print
(
f
'
Epoch:
{
epoch
:
03
d
}
, Train F1:
{
train_f1
:
.
4
f
}
, Validation F1:
{
val_f1
:
.
4
f
}
Test F1:
{
test_f1
:
.
4
f
}
'
)
checkpoint_file_name
=
f
"
../models/model-
{
epoch
}
.pt
"
torch
.
save
(
model
.
state_dict
(),
checkpoint_file_name
)
if
use_wandb
:
wandb
.
log
({
"
train/loss
"
:
train_loss
,
...
...
@@ -252,5 +258,6 @@ if __name__ == '__main__':
print
(
f
'
Test F1:
{
test_f1
:
.
4
f
}
'
)
save_model
(
model
,
"
model.pt
"
)
if
use_wandb
:
wandb
.
finish
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment