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

Method __init__

monai/inferers/splitter.py:119–147  ·  view source on GitHub ↗
(
        self,
        patch_size: Sequence[int] | int,
        overlap: Sequence[float] | float | Sequence[int] | int = 0.0,
        offset: Sequence[int] | int = 0,
        filter_fn: Callable | None = None,
        pad_mode: str | None = "constant",
        pad_value: float | int = 0,
        device: torch.device | str | None = None,
    )

Source from the content-addressed store, hash-verified

117 """
118
119 def __init__(
120 self,
121 patch_size: Sequence[int] | int,
122 overlap: Sequence[float] | float | Sequence[int] | int = 0.0,
123 offset: Sequence[int] | int = 0,
124 filter_fn: Callable | None = None,
125 pad_mode: str | None = "constant",
126 pad_value: float | int = 0,
127 device: torch.device | str | None = None,
128 ) -> None:
129 super().__init__(patch_size=patch_size, device=device)
130 self.offset = offset
131 # check if fraction overlaps are within the range of [0, 1)
132 if isinstance(ensure_tuple(overlap)[0], float) and any(ov < 0.0 or ov >= 1.0 for ov in ensure_tuple(overlap)):
133 raise ValueError(
134 f"Relative overlap must be between 0.0 and 1.0 but {overlap} is given. "
135 "If you wish to use number of pixels as overlap, please provide integer numbers."
136 )
137 elif any(ov < 0 for ov in ensure_tuple(overlap)):
138 raise ValueError(f"Number of pixels for overlap cannot be negative. {overlap} is given. ")
139
140 self.overlap = overlap
141 self.filter_fn = self._validate_filter_fn(filter_fn)
142 # padding
143 self.pad_mode = pad_mode
144 self.pad_value = pad_value
145 # check a valid padding mode is provided if there is any negative offset.
146 if not self.pad_mode and any(off < 0 for off in ensure_tuple(offset)):
147 raise ValueError(f"Negative `offset`requires a valid padding mode but `mode` is set to {self.pad_mode}.")
148
149 @staticmethod
150 def _validate_filter_fn(filter_fn):

Callers

nothing calls this directly

Calls 3

_validate_filter_fnMethod · 0.95
ensure_tupleFunction · 0.90
__init__Method · 0.45

Tested by

no test coverage detected