Skip to content

Commit

Permalink
fix mypy
Browse files Browse the repository at this point in the history
Signed-off-by: KumoLiu <[email protected]>
  • Loading branch information
KumoLiu committed Jul 28, 2023
1 parent bea398c commit f480b59
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
7 changes: 4 additions & 3 deletions monai/transforms/intensity/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions monai/transforms/intensity/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f480b59

Please sign in to comment.