-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
It's more of question to clarify, not a bug. can you help clarify plz
-
LoadImage() and LoadImaged() always return MetaTensor. Is it by design? I'm okay either way, just want to clarify. So we can't return the original data format ?
-
line 281
return img, img.meta if isinstance(img, MetaTensor) else meta_data. The img seems to be always a MetaTensor, is that check necessary?
MONAI/monai/transforms/io/array.py
Lines 273 to 281 in c27ab36
| meta_data[Key.FILENAME_OR_OBJ] = f"{ensure_tuple(filename)[0]}" # Path obj should be strings for data loader | |
| img = MetaTensor.ensure_torch_and_prune_meta( | |
| img_array, meta_data, self.simple_keys, pattern=self.pattern, sep=self.sep | |
| ) | |
| if self.ensure_channel_first: | |
| img = EnsureChannelFirst()(img) | |
| if self.image_only: | |
| return img | |
| return img, img.meta if isinstance(img, MetaTensor) else meta_data |
- inside of MetaTensor.ensure_torch_and_prune_meta(), we seems to do conversion to Tensor twice on lines 487 and 504. on 487 we
img = convert_to_tensor(im)andreturn MetaTensor(img, meta=meta)will internally call torch.as_tensor on img.
MONAI/monai/data/meta_tensor.py
Lines 487 to 504 in c27ab36
| img = convert_to_tensor(im) # potentially ascontiguousarray | |
| # if not tracking metadata, return `torch.Tensor` | |
| if not get_track_meta() or meta is None: | |
| return img | |
| # remove any superfluous metadata. | |
| if simple_keys: | |
| # ensure affine is of type `torch.Tensor` | |
| if MetaKeys.AFFINE in meta: | |
| meta[MetaKeys.AFFINE] = convert_to_tensor(meta[MetaKeys.AFFINE]) # bc-breaking | |
| remove_extra_metadata(meta) # bc-breaking | |
| if pattern is not None: | |
| meta = monai.transforms.DeleteItemsd(keys=pattern, sep=sep, use_re=True)(meta) | |
| # return the `MetaTensor` | |
| return MetaTensor(img, meta=meta) |
Thank you
Metadata
Metadata
Assignees
Labels
No labels