You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Now in ShiftIntensity, the default is to use the input dtype as the output dtype. As we discussed in #5535, it will cause an issue when the intensity goes beyond the original range.
>>> a = torch.tensor([175, 175], dtype=torch.uint8)
>>> b = convert_image_dtype(a, dtype=torch.float32)
>>> print(b, b.dtype)
tensor([0.6863, 0.6863]) torch.float32
I try to add some warning in this draft pr. But that still doesn't solve the problem. Because even if the user sees the warning, the user cannot modify it because the ShiftIntensity does not have the dtype parameter passed in. And if we add convert_data_dtype for each transform, it still doesn't look right, because we change the intensity inside the transform, which may not be what the user wants.
Like what @ericspod and @myron said in #5535, adding a clip transform is indeed a good solution, but it does not solve the current bug, because the data dtype has been changed inside the transform, that is, the intensity has been changed.
At the moment, I have not thought of a better way than adding a WARNING.
Do you have any suggestions? cc @wyli@ericspod@myron@Nic-Ma
Hi @wyli, thanks for your explanation, and yes I know that but it still clips intensity inside the dtype convert. What if the user does not want to clip?Not sure whether should do it? It looks like this is a clip operation shouldn't it be distinguished from convert_data_dtype?
Activity
wyli commentedon Dec 1, 2022
I meant something like this:
it'll remove the overflow:
KumoLiu commentedon Dec 1, 2022
Hi @wyli, thanks for your explanation, and yes I know that but it still clips intensity inside the dtype convert. What if the user does not want to clip?Not sure whether should do it? It looks like this is a clip operation shouldn't it be distinguished from convert_data_dtype?
wyli commentedon Dec 1, 2022
we can add a flag
safedefault to false (just doa.to(dtype));when
safe=True,we check and remove potential over/udnderflow
KumoLiu commentedon Dec 1, 2022
@wyli Ok, I will do that. Thanks!
Add `safe_dtype_convert` (#5620)