From 85ed7a94ddd2339d63c1a6c2d2e11fbf2fc8f07f Mon Sep 17 00:00:00 2001 From: skdas20 Date: Sun, 22 Feb 2026 19:32:04 +0000 Subject: [PATCH 1/3] fix: support more dtypes in pad_nd function - Removes hardcoded dtype exclusion list from pad_nd() - Enables torch.nn.functional.pad for bool and integer dtypes - Try-except fallback to numpy still handles unsupported combinations - Fixes #7842 --- monai/transforms/croppad/functional.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/monai/transforms/croppad/functional.py b/monai/transforms/croppad/functional.py index 653db43bc5..572d01ea1d 100644 --- a/monai/transforms/croppad/functional.py +++ b/monai/transforms/croppad/functional.py @@ -96,12 +96,7 @@ def pad_nd( return _np_pad(img, pad_width=to_pad, mode=mode, **kwargs) try: _pad = _np_pad - if mode in {"constant", "reflect", "edge", "replicate", "wrap", "circular"} and img.dtype not in { - torch.int16, - torch.int64, - torch.bool, - torch.uint8, - }: + if mode in {"constant", "reflect", "edge", "replicate", "wrap", "circular"}: _pad = _pt_pad return _pad(img, pad_width=to_pad, mode=mode, **kwargs) except (ValueError, TypeError, RuntimeError) as err: From 8fdad6d51ab239255d4ba6cb53f4e3fd690933e1 Mon Sep 17 00:00:00 2001 From: skdas20 Date: Sun, 22 Feb 2026 19:34:28 +0000 Subject: [PATCH 2/3] improve: add helpful error message for missing tensorboard package - Checks if tensorboard is installed before attempting to create SummaryWriter - Provides installation instructions when tensorboard is missing - Improves user experience for debugging missing dependencies - Addresses issue #7980 --- monai/handlers/tensorboard_handlers.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/monai/handlers/tensorboard_handlers.py b/monai/handlers/tensorboard_handlers.py index 20e2d74c8c..0a69ccfaba 100644 --- a/monai/handlers/tensorboard_handlers.py +++ b/monai/handlers/tensorboard_handlers.py @@ -50,6 +50,11 @@ class TensorBoardHandler: def __init__(self, summary_writer: SummaryWriter | SummaryWriterX | None = None, log_dir: str = "./runs"): if summary_writer is None: + if SummaryWriter is None: + raise RuntimeError( + "TensorBoardHandler requires tensorboard to be installed. " + "Please install it with: pip install tensorboard" + ) self._writer = SummaryWriter(log_dir=log_dir) self.internal_writer = True else: From 5f84f3547454e9a53d2437626135f81a7b28c38f Mon Sep 17 00:00:00 2001 From: skdas20 Date: Sun, 22 Feb 2026 19:34:49 +0000 Subject: [PATCH 3/3] enhance: support MetaTensor in ExtractDataKeyFromMetaKeyd - Adds image_only parameter to handle MetaTensor objects - Prevents redundant metadata extraction when image_only=True - Improves metadata handling for medical imaging workflows - Preserves MetaTensor metadata associations - Addresses issue #7562 Signed-off-by: skdas20 --- monai/apps/reconstruction/transforms/dictionary.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/monai/apps/reconstruction/transforms/dictionary.py b/monai/apps/reconstruction/transforms/dictionary.py index c166740768..0185974040 100644 --- a/monai/apps/reconstruction/transforms/dictionary.py +++ b/monai/apps/reconstruction/transforms/dictionary.py @@ -37,16 +37,19 @@ class ExtractDataKeyFromMetaKeyd(MapTransform): keys: keys to be transferred from meta to data meta_key: the meta key where all the meta-data is stored allow_missing_keys: don't raise exception if key is missing + image_only: if True, only extract metadata from MetaTensor images to avoid duplication Example: When the fastMRI dataset is loaded, "kspace" is stored in the data dictionary, but the ground-truth image with the key "reconstruction_rss" is stored in the meta data. In this case, ExtractDataKeyFromMetaKeyd moves "reconstruction_rss" to data. + For MetaTensor objects, setting image_only=True prevents extracting redundant metadata. """ - def __init__(self, keys: KeysCollection, meta_key: str, allow_missing_keys: bool = False) -> None: + def __init__(self, keys: KeysCollection, meta_key: str, allow_missing_keys: bool = False, image_only: bool = False) -> None: MapTransform.__init__(self, keys, allow_missing_keys) self.meta_key = meta_key + self.image_only = image_only def __call__(self, data: Mapping[Hashable, NdarrayOrTensor]) -> dict[Hashable, Tensor]: """ @@ -60,7 +63,12 @@ def __call__(self, data: Mapping[Hashable, NdarrayOrTensor]) -> dict[Hashable, T d = dict(data) for key in self.keys: if key in d[self.meta_key]: - d[key] = d[self.meta_key][key] # type: ignore + extracted_value = d[self.meta_key][key] + # When image_only is True, skip if the extracted value is a MetaTensor + # to preserve metadata associations + if self.image_only and isinstance(extracted_value, MetaTensor): + continue + d[key] = extracted_value # type: ignore elif not self.allow_missing_keys: raise KeyError( f"Key `{key}` of transform `{self.__class__.__name__}` was missing in the meta data"