Skip to content

Commit

Permalink
Fix network loading (#1533)
Browse files Browse the repository at this point in the history
* Add warning if the imported network does not have the right keys

Signed-off-by: Matthias Hadlich <[email protected]>

* Update warning

Signed-off-by: Matthias Hadlich <[email protected]>

* Set load_strict to false for deepedit

Signed-off-by: Matthias Hadlich <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Set load_strict=False for all existing models

Signed-off-by: Matthias Hadlich <[email protected]>

* Fix double load_strict=False

Signed-off-by: Matthias Hadlich <[email protected]>

---------

Signed-off-by: Matthias Hadlich <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: tangy5 <[email protected]>
Co-authored-by: SACHIDANAND ALLE <[email protected]>
  • Loading branch information
4 people authored Aug 31, 2023
1 parent 7208641 commit c90f42c
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions monailabel/tasks/infer/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def __init__(
extend_load_image: bool = True,
add_post_restore: bool = True,
dropout: float = 0.0,
load_strict=False,
**kwargs,
):
self.valid: bool = False
Expand Down Expand Up @@ -149,6 +150,7 @@ def __init__(
dimension=dimension,
description=description,
preload=strtobool(conf.get("preload", "false")),
load_strict=load_strict,
**kwargs,
)

Expand Down
1 change: 1 addition & 0 deletions sample-apps/endoscopy/lib/infers/deepedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(
labels=labels,
dimension=dimension,
description=description,
load_strict=False,
**kwargs,
)

Expand Down
2 changes: 1 addition & 1 deletion sample-apps/endoscopy/lib/infers/inbody.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class InBody(BundleInferTask):
"""

def __init__(self, path: str, conf: Dict[str, str], **kwargs):
super().__init__(path, conf, type=InferType.CLASSIFICATION, add_post_restore=False, **kwargs)
super().__init__(path, conf, type=InferType.CLASSIFICATION, add_post_restore=False, load_strict=False, **kwargs)

# Override Labels
self.labels = {"InBody": 0, "OutBody": 1}
Expand Down
2 changes: 1 addition & 1 deletion sample-apps/endoscopy/lib/infers/tooltracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ToolTracking(BundleInferTask):
"""

def __init__(self, path: str, conf: Dict[str, str], **kwargs):
super().__init__(path, conf, type=InferType.SEGMENTATION, **kwargs)
super().__init__(path, conf, type=InferType.SEGMENTATION, load_strict=False, **kwargs)

# Override Labels
self.labels = {"Tool": 1}
Expand Down
2 changes: 1 addition & 1 deletion sample-apps/pathology/lib/infers/classification_nuclei.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ClassificationNuclei(BundleInferTask):
"""

def __init__(self, path: str, conf: Dict[str, str], **kwargs):
super().__init__(path, conf, type=InferType.CLASSIFICATION, add_post_restore=False, **kwargs)
super().__init__(path, conf, type=InferType.CLASSIFICATION, add_post_restore=False, load_strict=False, **kwargs)

# Override Labels
self.labels = {
Expand Down
1 change: 1 addition & 0 deletions sample-apps/pathology/lib/infers/nuclick.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, path: str, conf: Dict[str, str], **kwargs):
conf,
type=InferType.ANNOTATION,
add_post_restore=False,
load_strict=False,
**kwargs,
pre_filter=[LoadImaged, SqueezeDimd],
post_filter=[KeepLargestConnectedComponentd, SaveImaged],
Expand Down
1 change: 1 addition & 0 deletions sample-apps/pathology/lib/infers/segmentation_nuclei.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(
labels=labels,
dimension=dimension,
description=description,
load_strict=False,
**kwargs,
)

Expand Down
1 change: 1 addition & 0 deletions sample-apps/radiology/lib/infers/deepedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(
input_key="image",
output_label_key="pred",
output_json_key="result",
load_strict=False,
**kwargs,
)

Expand Down
1 change: 1 addition & 0 deletions sample-apps/radiology/lib/infers/deepgrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(
labels=labels,
dimension=dimension,
description=description,
load_strict=False,
**kwargs,
)

Expand Down
1 change: 1 addition & 0 deletions sample-apps/radiology/lib/infers/deepgrow_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(
dimension=dimension,
description=description,
config={"cache_transforms": True, "cache_transforms_in_memory": True, "cache_transforms_ttl": 300},
load_strict=False,
)
self.model_3d = model_3d
self.spatial_size = spatial_size
Expand Down
1 change: 1 addition & 0 deletions sample-apps/radiology/lib/infers/localization_spine.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(
labels=labels,
dimension=dimension,
description=description,
load_strict=False,
**kwargs,
)
self.target_spacing = target_spacing
Expand Down
1 change: 1 addition & 0 deletions sample-apps/radiology/lib/infers/localization_vertebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(
labels=labels,
dimension=dimension,
description=description,
load_strict=False,
**kwargs,
)
self.target_spacing = target_spacing
Expand Down
1 change: 1 addition & 0 deletions sample-apps/radiology/lib/infers/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(
labels=labels,
dimension=dimension,
description=description,
load_strict=False,
**kwargs,
)
self.target_spacing = target_spacing
Expand Down
1 change: 1 addition & 0 deletions sample-apps/radiology/lib/infers/segmentation_spleen.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(
labels=labels,
dimension=dimension,
description=description,
load_strict=False,
**kwargs,
)
self.target_spacing = target_spacing
Expand Down
1 change: 1 addition & 0 deletions sample-apps/radiology/lib/infers/segmentation_vertebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(
labels=labels,
dimension=dimension,
description=description,
load_strict=False,
**kwargs,
)
self.target_spacing = target_spacing
Expand Down
1 change: 1 addition & 0 deletions sample-apps/radiology/lib/infers/vertebra_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(
labels=task_seg_vertebra.labels,
dimension=task_seg_vertebra.dimension,
description=description,
load_strict=False,
**kwargs,
)

Expand Down

0 comments on commit c90f42c

Please sign in to comment.