New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Processing model checkpointing #256
Merged
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9bf1ff4
First pass at segmentation model checkpoints.
ohinds 15bb946
Output and argument massaging.
ohinds 06d304c
Add a checkpoint tracker to save and load estimators.
ohinds 17b9bad
Make CheckpointTracker inherit from ModelCheckpoint for flexibility.
ohinds 61ccc9f
Add a test for checkpointing.
ohinds fbbc4c2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] cded43c
Rework checkpoint loading to statically load.
ohinds c7d7cfe
Merge branch 'ohinds-model-checkpointing' of https://github.com/neuro…
ohinds 29991dd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8c3fc54
Add a test of a workflow for warm starting when possible.
ohinds 2f51db2
Merge branch 'ohinds-model-checkpointing' of https://github.com/neuro…
ohinds 9286eb7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8e6839d
Better checks that warm start is loading the model properly
ohinds eb32be3
Pre-commit failure fixes.
ohinds 9fe59a6
All estimator init uses static loading
ohinds 0185eff
Merge branch 'master' into ohinds-model-checkpointing
satra File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,13 +1,15 @@ | ||||
"""Tests for `nobrainer.processing.checkpoint`.""" | ||||
|
||||
from nobrainer.processing.segmentation import Segmentation | ||||
from nobrainer.models import meshnet | ||||
import os | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
|
||||
import numpy as np | ||||
from numpy.testing import assert_allclose | ||||
import os | ||||
import pytest | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
import tensorflow as tf | ||||
|
||||
from nobrainer.models import meshnet | ||||
from nobrainer.processing.segmentation import Segmentation | ||||
|
||||
|
||||
def _assert_model_weights_allclose(model1, model2): | ||||
for layer1, layer2 in zip(model1.model.layers, model2.model.layers): | ||||
|
@@ -17,17 +19,17 @@ def _assert_model_weights_allclose(model1, model2): | |||
for index in range(len(weights1)): | ||||
assert_allclose(weights1[index], weights2[index], rtol=1e-06, atol=1e-08) | ||||
|
||||
|
||||
def test_checkpoint(tmp_path): | ||||
data_shape = (8, 8, 8, 8, 1) | ||||
train = tf.data.Dataset.from_tensors( | ||||
(np.random.rand(*data_shape), | ||||
np.random.randint(0, 1, data_shape)) | ||||
(np.random.rand(*data_shape), np.random.randint(0, 1, data_shape)) | ||||
) | ||||
train.scalar_labels = False | ||||
train.n_volumes = data_shape[0] | ||||
train.volume_shape = data_shape[1:4] | ||||
|
||||
checkpoint_filepath = os.path.join(tmp_path, 'checkpoint-epoch_{epoch:03d}') | ||||
checkpoint_filepath = os.path.join(tmp_path, "checkpoint-epoch_{epoch:03d}") | ||||
model1 = Segmentation(meshnet, checkpoint_filepath=checkpoint_filepath) | ||||
model1.fit( | ||||
dataset_train=train, | ||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.