From 125b3a9a3eeb8382f35e659f0b565350d17a2e6d Mon Sep 17 00:00:00 2001 From: Andreas Schuh <77496589+aschuh-hf@users.noreply.github.com> Date: Fri, 28 Jul 2023 06:09:33 -0700 Subject: [PATCH] [utils] Fix assert and torch.from_numpy() warning in MetaImage IO (#102) --- src/deepali/utils/imageio/meta.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/deepali/utils/imageio/meta.py b/src/deepali/utils/imageio/meta.py index c2b473c..7168932 100644 --- a/src/deepali/utils/imageio/meta.py +++ b/src/deepali/utils/imageio/meta.py @@ -53,7 +53,7 @@ def read_meta_image(arg: Union[PathUri, bytes, io.BufferedReader]) -> Tuple[Tens data = np.expand_dims(data, 0) else: data = np.squeeze(np.swapaxes(np.expand_dims(data, 0), 0, -1), -1) - size = meta.get("DimSize", data.shape[:0:-1]) + size = tuple(meta.get("DimSize", data.shape[:0:-1])) assert size[::-1] == data.shape[1:] origin = meta.get("Position", meta.get("Origin", meta.get("Offset"))) matrix = meta.get("Rotation", meta.get("Orientation", meta.get("TransformMatrix"))) @@ -292,6 +292,7 @@ def read_meta_image_from_fileobj(f: io.BufferedReader) -> Tuple[np.ndarray, Meta image = np.frombuffer(buffer, dtype=meta["ElementType"]).reshape(shape) if meta.get("BinaryDataByteOrderMSB") or meta.get("ElementByteOrderMSB"): image.byteswap(inplace=True) + image = image.copy() # remove unused metadata meta["ElementDataFile"] = None