Skip to content
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

default val for config parsed content #6756

Merged
merged 3 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions monai/bundle/reference_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def _resolve_one_item(
item = look_up_option(id, self.items, print_all_options=False, default=kwargs.get("default", "no_default"))
except ValueError as err:
raise KeyError(f"id='{id}' is not found in the config resolver.") from err
if not isinstance(item, ConfigItem):
return item
item_config = item.get_config()

if waiting_list is None:
Expand All @@ -151,11 +153,10 @@ def _resolve_one_item(
look_up_option(d, self.items, print_all_options=False)
except ValueError as err:
msg = f"the referring item `@{d}` is not defined in the config content."
if self.allow_missing_reference:
warnings.warn(msg)
continue
else:
if not self.allow_missing_reference:
raise ValueError(msg) from err
warnings.warn(msg)
continue
# recursively resolve the reference first
self._resolve_one_item(id=d, waiting_list=waiting_list, **kwargs)
waiting_list.discard(d)
Expand Down
10 changes: 2 additions & 8 deletions tests/test_cldice_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@
from monai.losses import SoftclDiceLoss, SoftDiceclDiceLoss

TEST_CASES = [
[ # shape: (1, 4), (1, 4)
{"y_pred": torch.ones((100, 3, 256, 256)), "y_true": torch.ones((100, 3, 256, 256))},
0.0,
],
[ # shape: (1, 5), (1, 5)
{"y_pred": torch.ones((100, 3, 256, 256, 5)), "y_true": torch.ones((100, 3, 256, 256, 5))},
0.0,
],
[{"y_pred": torch.ones((7, 3, 11, 10)), "y_true": torch.ones((7, 3, 11, 10))}, 0.0],
[{"y_pred": torch.ones((2, 3, 13, 14, 5)), "y_true": torch.ones((2, 3, 13, 14, 5))}, 0.0],
]


Expand Down
1 change: 1 addition & 0 deletions tests/test_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def test_parse(self, config, expected_ids, output_types):
self.assertTrue(isinstance(v, cls))
# test default value
self.assertEqual(parser.get_parsed_content(id="abc", default=ConfigItem(12345, "abc")), 12345)
self.assertEqual(parser.get_parsed_content(id="abcd", default=1), 1)

@parameterized.expand([TEST_CASE_2])
def test_function(self, config):
Expand Down