MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / Decollated

Class Decollated

monai/transforms/inverse_batch_transform.py:114–159  ·  view source on GitHub ↗

Decollate a batch of data. If input is a dictionary, it also supports to only decollate specified keys. Note that unlike most MapTransforms, it will delete the other keys that are not specified. if `keys=None`, it will decollate all the data in the input. It replicates the scalar va

Source from the content-addressed store, hash-verified

112
113
114class Decollated(MapTransform):
115 """
116 Decollate a batch of data. If input is a dictionary, it also supports to only decollate specified keys.
117 Note that unlike most MapTransforms, it will delete the other keys that are not specified.
118 if `keys=None`, it will decollate all the data in the input.
119 It replicates the scalar values to every item of the decollated list.
120
121 Args:
122 keys: keys of the corresponding items to decollate, note that it will delete other keys not specified.
123 if None, will decollate all the keys. see also: :py:class:`monai.transforms.compose.MapTransform`.
124 detach: whether to detach the tensors. Scalars tensors will be detached into number types
125 instead of torch tensors.
126 pad_batch: when the items in a batch indicate different batch size,
127 whether to pad all the sequences to the longest.
128 If False, the batch size will be the length of the shortest sequence.
129 fill_value: the value to fill the padded sequences when `pad_batch=True`.
130 allow_missing_keys: don't raise exception if key is missing.
131
132 """
133
134 def __init__(
135 self,
136 keys: KeysCollection | None = None,
137 detach: bool = True,
138 pad_batch: bool = True,
139 fill_value=None,
140 allow_missing_keys: bool = False,
141 ) -> None:
142 super().__init__(keys, allow_missing_keys)
143 self.detach = detach
144 self.pad_batch = pad_batch
145 self.fill_value = fill_value
146
147 def __call__(self, data: dict | list):
148 d: dict | list
149 if len(self.keys) == 1 and self.keys[0] is None:
150 # it doesn't support `None` as the key
151 d = data
152 else:
153 if not isinstance(data, dict):
154 raise TypeError("input data is not a dictionary, but specified keys to decollate.")
155 d = {}
156 for key in self.key_iterator(data):
157 d[key] = data[key]
158
159 return decollate_batch(d, detach=self.detach, pad=self.pad_batch, fill_value=self.fill_value)
160
161
162DecollateD = DecollateDict = Decollated

Callers 5

__init__Method · 0.90
_decollate_dataMethod · 0.90
test_nnunet_bundleMethod · 0.90
check_decollateMethod · 0.90
test_decollatedMethod · 0.90

Calls

no outgoing calls

Tested by 3

test_nnunet_bundleMethod · 0.72
check_decollateMethod · 0.72
test_decollatedMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…