Skip to content

Commit

Permalink
Update for loading MetaTensor
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Kerfoot <[email protected]>
  • Loading branch information
ericspod committed Jan 29, 2025
1 parent a375354 commit d6152a3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions monai/data/meta_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,3 +607,6 @@ def print_verbose(self) -> None:
print(self)
if self.meta is not None:
print(self.meta.__repr__())


torch.serialization.add_safe_globals([MetaTensor])
2 changes: 1 addition & 1 deletion tests/test_meta_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_pickling(self):
with tempfile.TemporaryDirectory() as tmp_dir:
fname = os.path.join(tmp_dir, "im.pt")
torch.save(m, fname)
m2 = torch.load(fname)
m2 = torch.load(fname, weights_only=False)
if not isinstance(m2, MetaTensor) and not pytorch_after(1, 8, 1):
warnings.warn("Old version of pytorch. pickling converts `MetaTensor` to `torch.Tensor`.")
m = m.as_tensor()
Expand Down

0 comments on commit d6152a3

Please sign in to comment.