Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mednet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
medai
software
mednet
Commits
edadec6d
Commit
edadec6d
authored
1 year ago
by
Daniel CARRON
Committed by
André Anjos
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Save and restore normalizer from checkpoint
parent
2fbbd899
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
Making use of LightningDataModule and simplification of data loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ptbench/models/pasa.py
+7
-0
7 additions, 0 deletions
src/ptbench/models/pasa.py
src/ptbench/scripts/train.py
+17
-13
17 additions, 13 deletions
src/ptbench/scripts/train.py
with
24 additions
and
13 deletions
src/ptbench/models/pasa.py
+
7
−
0
View file @
edadec6d
...
...
@@ -185,6 +185,13 @@ class Pasa(pl.LightningModule):
return
x
def
on_save_checkpoint
(
self
,
checkpoint
):
checkpoint
[
"
normalizer
"
]
=
self
.
normalizer
def
on_load_checkpoint
(
self
,
checkpoint
):
logger
.
info
(
"
Restoring normalizer from checkpoint.
"
)
self
.
normalizer
=
checkpoint
[
"
normalizer
"
]
def
set_normalizer
(
self
,
dataloader
:
torch
.
utils
.
data
.
DataLoader
)
->
None
:
"""
Initializes the input normalizer for the current model.
...
...
This diff is collapsed.
Click to expand it.
src/ptbench/scripts/train.py
+
17
−
13
View file @
edadec6d
...
...
@@ -252,16 +252,6 @@ def train(
datamodule
.
prepare_data
()
datamodule
.
setup
(
stage
=
"
fit
"
)
# Sets the model normalizer with the unaugmented-train-subset.
# this call may be a NOOP, if the model was pre-trained and expects
# different weights for the normalisation layer.
if
hasattr
(
model
,
"
set_normalizer
"
):
model
.
set_normalizer
(
datamodule
.
unshuffled_train_dataloader
())
else
:
logger
.
warning
(
f
"
Model
{
model
.
name
}
has no
'
set_normalizer
'
method. Skipping.
"
)
# If asked, rebalances the loss criterion based on the relative proportion
# of class examples available in the training set. Also affects the
# validation loss if a validation set is available on the data module.
...
...
@@ -276,9 +266,23 @@ def train(
)
logger
.
info
(
f
"
Training for at most
{
epochs
}
epochs.
"
)
# We only load the checkpoint to get some information about its state. The
# actual loading of the model is done in trainer.fit()
if
checkpoint_file
is
not
None
:
arguments
=
{}
arguments
[
"
max_epoch
"
]
=
epochs
arguments
[
"
epoch
"
]
=
0
if
checkpoint_file
is
None
or
not
hasattr
(
model
,
"
on_load_checkpoint
"
):
# Sets the model normalizer with the unaugmented-train-subset.
# this call may be a NOOP, if the model was pre-trained and expects
# different weights for the normalisation layer.
if
hasattr
(
model
,
"
set_normalizer
"
):
model
.
set_normalizer
(
datamodule
.
unshuffled_train_dataloader
())
else
:
logger
.
warning
(
f
"
Model
{
model
.
name
}
has no
'
set_normalizer
'
method. Skipping.
"
)
else
:
# Normalizer will be loaded during model.on_load_checkpoint
checkpoint
=
torch
.
load
(
checkpoint_file
)
start_epoch
=
checkpoint
[
"
epoch
"
]
logger
.
info
(
f
"
Resuming from epoch
{
start_epoch
}
...
"
)
...
...
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