-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Make MONAI robust to non-default meta dict names #8411
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
base: dev
Are you sure you want to change the base?
Conversation
…ct names Signed-off-by: Ben Murray <atbenmurray@github.com>
Signed-off-by: Ben Murray <atbenmurray@github.com>
@@ -169,6 +169,7 @@ def __call__(self, data, reader: ImageReader | None = None): | |||
f"loader must return a tuple or list (because image_only=False was used), got {type(data)}." | |||
) | |||
d[key] = data[0] | |||
data[1]['tensor_name'] = key |
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.
@atbenmurray ,
Hi, since the method you proposed involves looping through the data, resulting in O(n) time complexity. We would like to ask if it’s possible to add a dictionary to make the lookup more intuitive and faster, achieving O(1) time complexity.
key_to_meta_key_map[key] = meta_key
...
d["key_meta_dict_map"] = key_to_meta_key_map
Then our d
would like:
--- image{}
|
--- image_meta_dict{}
|
--- lebel{}
|
--- lebel_meta_dict{}
|
--- key_meta_dict_map{"image": "image_meta_dict", "lebel": "lebel_meta_dict"}
with @slicepaste , @IamTingTing
@@ -358,6 +358,8 @@ def __call__(self, data) -> dict[Hashable, NdarrayOrTensor]: | |||
d, self.factor_key, self.meta_keys, self.meta_key_postfix | |||
): | |||
meta_key = meta_key or f"{key}_{meta_key_postfix}" | |||
if meta_key not in d: | |||
meta_key = get_meta_dict_name(key, d) |
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.
Is this part of the code to prevent meta_keys from being modified or deleted?
However, if a meta_key were deleted, the get_meta_dict_name() function would not be able to find the corresponding meta_key.
As for the possibility of meta_keys being modified, we have not found any function that could alter it.
Therefore, the condition here might be overlapping with the original code.
Could you kindly share the reason for adding it?
with @einsyang723 and @slicepaste
This PR adds a field to the meta dict indicating which tensor it belongs to, and a method get_meta_dict_key to find the meta_dict when it is present in a dictionary.
I have addressed many of the obvious places where there might be issues if the default meta_dict extension is not used but there are likely more that I need to find.
Description
A few sentences describing the changes proposed in this pull request.
Types of changes
./runtests.sh -f -u --net --coverage
../runtests.sh --quick --unittests --disttests
.make html
command in thedocs/
folder.