Description
Normalize ignores an explicitly supplied in_min when in_max is None, and vice versa.
Both bounds are calculated from the input data instead.
The parameter documentation describes automatic calculation when the corresponding bound is None, so I would expect an explicitly supplied bound to be preserved.
Reproduction
import torch
import torchio as tio
image = tio.ScalarImage(
torch.tensor([0., 50., 100.]).reshape(1, 1, 1, 3)
)
for bounds in ({"in_min": 50.}, {"in_max": 50.}):
result = tio.Normalize(
out_min=0.,
out_max=1.,
**bounds,
)(image)
print(bounds, result.data.flatten().tolist())
Actual behavior
{'in_min': 50.0} [0.0, 0.5, 1.0]
{'in_max': 50.0} [0.0, 0.5, 1.0]
Expected behavior
{'in_min': 50.0} [0.0, 0.0, 1.0]
{'in_max': 50.0} [0.0, 1.0, 1.0]
Possible cause
Normalize.make_params() uses the explicit bounds only when both are non-None:
if self.in_min is not None and self.in_max is not None:
Otherwise, it computes both bounds from percentiles.
Each bound could be resolved independently, calculating only the missing one.
Version
Reproduced on main, commit 2b019d2a9659c838408c73ae77327ac5eb87b190, TorchIO 2.0.0a2, using synthetic CPU tensors.
Description
Normalizeignores an explicitly suppliedin_minwhenin_maxisNone, and vice versa.Both bounds are calculated from the input data instead.
The parameter documentation describes automatic calculation when the corresponding bound is
None, so I would expect an explicitly supplied bound to be preserved.Reproduction
Actual behavior
Expected behavior
Possible cause
Normalize.make_params()uses the explicit bounds only when both are non-None:Otherwise, it computes both bounds from percentiles.
Each bound could be resolved independently, calculating only the missing one.
Version
Reproduced on
main, commit2b019d2a9659c838408c73ae77327ac5eb87b190, TorchIO2.0.0a2, using synthetic CPU tensors.