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
torchani
Commits
3e296069
Unverified
Commit
3e296069
authored
Aug 03, 2018
by
Gao, Xiang
Committed by
GitHub
Aug 03, 2018
Browse files
checkpoint if validation gets better result (#55)
parent
f50cc0b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
+10
-2
examples/nnp_training.py
examples/nnp_training.py
+10
-2
No files found.
examples/nnp_training.py
View file @
3e296069
...
...
@@ -48,7 +48,7 @@ device = torch.device(parser.device)
writer
=
tensorboardX
.
SummaryWriter
(
log_dir
=
parser
.
log
)
start
=
timeit
.
default_timer
()
nnp
,
shift_energy
=
model
.
get_or_create_model
(
'/tmp/model.pt'
,
nnp
,
shift_energy
=
model
.
get_or_create_model
(
parser
.
model_checkpoint
,
True
,
device
=
device
)
training
,
validation
,
testing
=
torchani
.
data
.
load_or_create
(
parser
.
dataset_checkpoint
,
parser
.
dataset_path
,
parser
.
chunk_size
,
...
...
@@ -72,6 +72,11 @@ def hartree2kcal(x):
return
627.509
*
x
@
trainer
.
on
(
ignite
.
engine
.
Events
.
STARTED
)
def
initialize
(
trainer
):
trainer
.
state
.
best_validation_rmse
=
math
.
inf
@
trainer
.
on
(
ignite
.
engine
.
Events
.
EPOCH_STARTED
)
def
init_tqdm
(
trainer
):
trainer
.
state
.
tqdm
=
tqdm
.
tqdm
(
total
=
len
(
training
),
desc
=
'epoch'
)
...
...
@@ -88,11 +93,14 @@ def finalize_tqdm(trainer):
@
trainer
.
on
(
ignite
.
engine
.
Events
.
EPOCH_STARTED
)
def
log_
validation_
results
(
trainer
):
def
validation_
and_checkpoint
(
trainer
):
evaluator
.
run
(
validation
)
metrics
=
evaluator
.
state
.
metrics
rmse
=
hartree2kcal
(
metrics
[
'RMSE'
])
writer
.
add_scalar
(
'validation_rmse_vs_epoch'
,
rmse
,
trainer
.
state
.
epoch
)
if
rmse
<
trainer
.
state
.
best_validation_rmse
:
trainer
.
state
.
best_validation_rmse
=
rmse
torch
.
save
(
nnp
.
state_dict
(),
parser
.
model_checkpoint
)
@
trainer
.
on
(
ignite
.
engine
.
Events
.
EPOCH_STARTED
)
...
...
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