From f480b59dad35db2c012db3e6fd7c3612fa10e704 Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Fri, 28 Jul 2023 15:32:38 +0800 Subject: [PATCH] fix mypy Signed-off-by: KumoLiu --- monai/transforms/intensity/array.py | 7 ++++--- monai/transforms/intensity/dictionary.py | 5 +---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/monai/transforms/intensity/array.py b/monai/transforms/intensity/array.py index 4b791f26e5..8cd15083c9 100644 --- a/monai/transforms/intensity/array.py +++ b/monai/transforms/intensity/array.py @@ -666,7 +666,7 @@ def randomize(self, data: Any | None = None) -> None: if not self._do_transform: return None if self.channel_wise: - self.factor = [self.R.uniform(low=self.factors[0], high=self.factors[1]) for _ in range(data.shape[0])] + self.factor = [self.R.uniform(low=self.factors[0], high=self.factors[1]) for _ in range(data.shape[0])] # type: ignore else: self.factor = self.R.uniform(low=self.factors[0], high=self.factors[1]) @@ -681,12 +681,13 @@ def __call__(self, img: NdarrayOrTensor, randomize: bool = True) -> NdarrayOrTen if not self._do_transform: return convert_data_type(img, dtype=self.dtype)[0] + ret: NdarrayOrTensor if self.channel_wise: out = [] for i, d in enumerate(img): - out_channel = ScaleIntensity(minv=None, maxv=None, factor=self.factor[i], dtype=self.dtype)(d) + out_channel = ScaleIntensity(minv=None, maxv=None, factor=self.factor[i], dtype=self.dtype)(d) # type: ignore out.append(out_channel) - ret = torch.stack(out) + ret = torch.stack(out) # type: ignore else: ret = ScaleIntensity(minv=None, maxv=None, factor=self.factor, dtype=self.dtype)(img) return ret diff --git a/monai/transforms/intensity/dictionary.py b/monai/transforms/intensity/dictionary.py index 4b856a4cd9..32052ad406 100644 --- a/monai/transforms/intensity/dictionary.py +++ b/monai/transforms/intensity/dictionary.py @@ -369,7 +369,6 @@ def __init__( keys: KeysCollection, offsets: tuple[float, float] | float, safe: bool = False, - channel_wise: bool = False, factor_key: str | None = None, meta_keys: KeysCollection | None = None, meta_key_postfix: str = DEFAULT_POST_FIX, @@ -384,8 +383,6 @@ def __init__( if single number, offset value is picked from (-offsets, offsets). safe: if `True`, then do safe dtype convert when intensity overflow. default to `False`. E.g., `[256, -12]` -> `[array(0), array(244)]`. If `True`, then `[256, -12]` -> `[array(255), array(0)]`. - channel_wise: if True, calculate on each channel separately. Please ensure - that the first dimension represents the channel of the image if True. factor_key: if not None, use it as the key to extract a value from the corresponding metadata dictionary of `key` at runtime, and multiply the random `offset` to shift intensity. Usually, `IntensityStatsd` transform can pre-compute statistics of intensity values @@ -412,7 +409,7 @@ def __init__( if len(self.keys) != len(self.meta_keys): raise ValueError("meta_keys should have the same length as keys.") self.meta_key_postfix = ensure_tuple_rep(meta_key_postfix, len(self.keys)) - self.shifter = RandShiftIntensity(offsets=offsets, safe=safe, channel_wise=channel_wise, prob=1.0) + self.shifter = RandShiftIntensity(offsets=offsets, safe=safe, prob=1.0) def set_random_state( self, seed: int | None = None, state: np.random.RandomState | None = None