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
logger.debug('Detects input has negative values, auto rescaling input to 0-1.')
returnrescale_0_1(x)
ifrange_0_255andall_intand (notrange_0_1): # if image is all integer and between 0 - 255. Normalize it to 0-1.
logger.debug('Detects input are all integers within range 0-255. Divided all values by 255.')
returnx/255.
ifrange_0_1:
logger.debug('Inputs already within 0-1, no unnormalization is performed.')
returnx
logger.debug('Auto rescaling input to 0-1.')
returnrescale_0_1(x)
defrescale_0_1(x):
"""
Rescaling tensor to 0-1 using min-max normalization
"""
return (x-x.min()) / (x.max() -x.min())
However, usually people use transforms.Normalize((0.5,), (0.5,)) to normalize image.
So I think when x is between -1 and 1, it should be x * 0.5 + 0.5 to keep the image color consistent.
I know it can be achieved by setting set_image_mean([0.5, 0.5, 0.5]) and set_image_std([0.5, 0.5, 0.5]), but this may be used for other special cases. For the most common cases, i think we should adopt the above method.
Any idea?
The text was updated successfully, but these errors were encountered:
Good suggestion! I think we could do it if this is a common normalization preset. In fact, what you described can be extended to all the zero-centralize normalizations as well. The tricky part that I can think of is how to determine if the data is zero-centralized rather than just happen to fall between that range. In other word, is simply checking the [-1, 1] range (or [-M, M] for more general cases) sufficient to determine these kind of inputs?
I think simply checking [-1, 1] is enough. Is there any other possible situation? For normal images it seems that these are the only cases. For other special cases, they can use set_image_mean and set_image_std.
Right, maybe we can try to handle the [-1, 1] case for now. Would you be able to create an PR for this feature and some testing cases so we can review and discuss further?
Currently, it seems that for input pytorch float tensor between -1 and 1, a min-max normalization is taken:
torchshow/torchshow/visualization.py
Lines 264 to 287 in 3008c23
However, usually people use
transforms.Normalize((0.5,), (0.5,))
to normalize image.So I think when x is between -1 and 1, it should be
x * 0.5 + 0.5
to keep the image color consistent.I know it can be achieved by setting
set_image_mean([0.5, 0.5, 0.5])
andset_image_std([0.5, 0.5, 0.5])
, but this may be used for other special cases. For the most common cases, i think we should adopt the above method.Any idea?
The text was updated successfully, but these errors were encountered: