-
Notifications
You must be signed in to change notification settings - Fork 102
📝 Update 05-patch-prediction notebook for the New API
#977
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
Open
gozdeg
wants to merge
13
commits into
dev-define-engines-abc
Choose a base branch
from
dev-update-example-notebooks
base: dev-define-engines-abc
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5db61eb
📝 Make changes to 05-patch-prediction notebook
gozdeg e7273b9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ede9dfe
🐛 Bug fix for model/module assumption - implement helper logic to acc…
gozdeg 407b6f3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6da5741
📝 Update notebook-5 & fix engine_abc _get_model_attr() type checking
gozdeg 7d47b2b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] cffae15
:bug: Fix pre-commit errors
shaneahmed a8d28c1
:white_check_mark: Fix rendering issues
shaneahmed 709813b
:rewind: Revert changes to multi_task_segmentor.py and nucleus_instan…
shaneahmed cfe0d5e
:art: Improve Jupyter Notebook output
shaneahmed e1afce2
📝 Update-notebook-5
gozdeg 267133e
🐛 Small fix
gozdeg c960baf
Merge branch 'dev-define-engines-abc' into dev-update-example-notebooks
shaneahmed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 | ||
|---|---|---|---|---|
|
|
@@ -50,7 +50,8 @@ def main(files: list[Path]) -> None: | |||
|
|
||||
| """ | ||||
| for path in files: | ||||
| notebook = json.loads(path.read_text()) | ||||
| with Path.open(path, encoding="utf-8", errors="ignore") as f: | ||||
| notebook = json.load(f) | ||||
|
Member
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
|
||||
| formatted_notebook = format_notebook(copy.deepcopy(notebook)) | ||||
| changed = any( | ||||
| cell != formatted_cell | ||||
|
|
||||
This file contains hidden or 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 hidden or 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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -64,6 +64,7 @@ | |||||
|
|
||||||
| if TYPE_CHECKING: # pragma: no cover | ||||||
| import os | ||||||
| from collections.abc import Callable | ||||||
|
|
||||||
| from torch.utils.data import DataLoader | ||||||
|
|
||||||
|
|
@@ -374,6 +375,14 @@ def _initialize_model_ioconfig( | |||||
|
|
||||||
| return model, None | ||||||
|
|
||||||
| def _get_model_attr(self: EngineABC, attr_name: str) -> Callable: | ||||||
| """Return a model attribute, unwrapping DataParallel if required.""" | ||||||
| try: | ||||||
| return getattr(self.model, attr_name) | ||||||
| except AttributeError: | ||||||
|
Member
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
|
||||||
| module = getattr(self.model, "module", None) | ||||||
| return getattr(module, attr_name) | ||||||
|
|
||||||
| def get_dataloader( | ||||||
| self: EngineABC, | ||||||
| images: str | Path | list[str | Path] | np.ndarray, | ||||||
|
|
@@ -427,7 +436,7 @@ def get_dataloader( | |||||
| auto_get_mask=auto_get_mask, | ||||||
| ) | ||||||
|
|
||||||
| dataset.preproc_func = self.model.preproc_func | ||||||
| dataset.preproc_func = self._get_model_attr("preproc_func") | ||||||
|
|
||||||
| # preprocessing must be defined with the dataset | ||||||
| return torch.utils.data.DataLoader( | ||||||
|
|
@@ -443,7 +452,7 @@ def get_dataloader( | |||||
| inputs=images, labels=labels, patch_input_shape=ioconfig.patch_input_shape | ||||||
| ) | ||||||
|
|
||||||
| dataset.preproc_func = self.model.preproc_func | ||||||
| dataset.preproc_func = self._get_model_attr("preproc_func") | ||||||
|
|
||||||
| # preprocessing must be defined with the dataset | ||||||
| return torch.utils.data.DataLoader( | ||||||
|
|
@@ -528,8 +537,9 @@ def infer_patches( | |||||
| else self.dataloader | ||||||
| ) | ||||||
|
|
||||||
| infer_batch = self._get_model_attr("infer_batch") | ||||||
| for batch_data in tqdm_loop: | ||||||
| batch_output = self.model.infer_batch( | ||||||
| batch_output = infer_batch( | ||||||
| self.model, | ||||||
| batch_data["image"], | ||||||
| device=self.device, | ||||||
|
|
||||||
This file contains hidden or 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 hidden or 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
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.