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

Method __init__

monai/transforms/post/dictionary.py:162–207  ·  view source on GitHub ↗

Args: keys: keys of the corresponding items to model output and label. See also: :py:class:`monai.transforms.compose.MapTransform` argmax: whether to execute argmax function on input data before transform. it also can be a sequence of

(
        self,
        keys: KeysCollection,
        argmax: Sequence[bool] | bool = False,
        to_onehot: Sequence[int | None] | int | None = None,
        threshold: Sequence[float | None] | float | None = None,
        rounding: Sequence[str | None] | str | None = None,
        allow_missing_keys: bool = False,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

160 backend = AsDiscrete.backend
161
162 def __init__(
163 self,
164 keys: KeysCollection,
165 argmax: Sequence[bool] | bool = False,
166 to_onehot: Sequence[int | None] | int | None = None,
167 threshold: Sequence[float | None] | float | None = None,
168 rounding: Sequence[str | None] | str | None = None,
169 allow_missing_keys: bool = False,
170 **kwargs,
171 ) -> None:
172 """
173 Args:
174 keys: keys of the corresponding items to model output and label.
175 See also: :py:class:`monai.transforms.compose.MapTransform`
176 argmax: whether to execute argmax function on input data before transform.
177 it also can be a sequence of bool, each element corresponds to a key in ``keys``.
178 to_onehot: if not None, convert input data into the one-hot format with specified number of classes.
179 defaults to ``None``. it also can be a sequence, each element corresponds to a key in ``keys``.
180 threshold: if not None, threshold the float values to int number 0 or 1 with specified threshold value.
181 defaults to ``None``. it also can be a sequence, each element corresponds to a key in ``keys``.
182 rounding: if not None, round the data according to the specified option,
183 available options: ["torchrounding"]. it also can be a sequence of str or None,
184 each element corresponds to a key in ``keys``.
185 allow_missing_keys: don't raise exception if key is missing.
186 kwargs: additional parameters to ``AsDiscrete``.
187 ``dim``, ``keepdim``, ``dtype`` are supported, unrecognized parameters will be ignored.
188 These default to ``0``, ``True``, ``torch.float`` respectively.
189
190 """
191 super().__init__(keys, allow_missing_keys)
192 self.argmax = ensure_tuple_rep(argmax, len(self.keys))
193 self.to_onehot = []
194 for flag in ensure_tuple_rep(to_onehot, len(self.keys)):
195 if isinstance(flag, bool):
196 raise ValueError("`to_onehot=True/False` is deprecated, please use `to_onehot=num_classes` instead.")
197 self.to_onehot.append(flag)
198
199 self.threshold = []
200 for flag in ensure_tuple_rep(threshold, len(self.keys)):
201 if isinstance(flag, bool):
202 raise ValueError("`threshold_values=True/False` is deprecated, please use `threshold=value` instead.")
203 self.threshold.append(flag)
204
205 self.rounding = ensure_tuple_rep(rounding, len(self.keys))
206 self.converter = AsDiscrete()
207 self.converter.kwargs = kwargs
208
209 def __call__(self, data: Mapping[Hashable, NdarrayOrTensor]) -> dict[Hashable, NdarrayOrTensor]:
210 d = dict(data)

Callers

nothing calls this directly

Calls 4

ensure_tuple_repFunction · 0.90
AsDiscreteClass · 0.90
__init__Method · 0.45
appendMethod · 0.45

Tested by

no test coverage detected