Skip to content

Commit 75dffd7

Browse files
Fixing std type issue for RandRicianNoise when the argument relative is True (#5674) (#5675)
Using .item() to get the value in the tensor that is returned by .std(). This should fix the issue where the type of the std calculation is not an int or float. Signed-off-by: Nishant Panchal <68797723+Nishantppanchal@users.noreply.github.com> Fixes #5674 . ### Description When we use .std() on a tensor, a tensor with the standard deviation inside is returned. To get this standard deviation, we also have to use .item(). However, this was not done, so I fixed it. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [x] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [x] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. Signed-off-by: Nishant Panchal <68797723+Nishantppanchal@users.noreply.github.com>
1 parent 7bebb6b commit 75dffd7

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

monai/transforms/intensity/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def __call__(self, img: NdarrayOrTensor, randomize: bool = True) -> NdarrayOrTen
207207
raise RuntimeError("If channel_wise is False, mean must be a float or int number.")
208208
if not isinstance(self.std, (int, float)):
209209
raise RuntimeError("If channel_wise is False, std must be a float or int number.")
210-
std = self.std * img.std() if self.relative else self.std
210+
std = self.std * img.std().item() if self.relative else self.std
211211
if not isinstance(std, (int, float)):
212212
raise RuntimeError("std must be a float or int number.")
213213
img = self._add_noise(img, mean=self.mean, std=std)

0 commit comments

Comments
 (0)