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
I don't see transforms for linear normalization (e.g. between 0-1 or arbitrary ranges) or std normalization? Do these exist somewhere else or do people just implement this in the Dataset class? Any plans for this? It's useful when sampling from folders. It also could be useful so you can potential remove the automatic division by 255. in the ToTensor() transform and therefore support loading arbitrary numpy arrays from file (an area for which there is a high user demand). Idk.. just a thought.
Anyways, here's some code to do these things:
classRangeNormalize(object):
"""Given min_val: (R, G, B) and max_val: (R,G,B), will normalize each channel of the torch.*Tensor to the provided min and max values. Works by efficiently calculating a linear transform: a = (max'-min')/(max-min) b = max' - a * max new_value = a * value + b where min' & max' are given values, and min & max are observed min/max for each channel Example: >>> x = torch.rand(3,50,50) >>> rn = RangeNormalize((0,0,10),(1,1,11)) # normalize last channel between 10-11 >>> x_norm = rn(x) Also works with just one value for min/max across all channels: >>> x = torch.rand(3,50,50) >>> rn = RangeNormalize(-1,1) >>> x_norm = rn(x) """def__init__(self, min_, max_):
ifnotisinstance(min_, list) andnotisinstance(min_, tuple):
min_= [min_]*3ifnotisinstance(max_, list) andnotisinstance(max_, tuple):
max_= [max_]*3self.min_=min_self.max_=max_def__call__(self, tensor):
fort, min_, max_inzip(tensor, self.min_, self.max_):
max_val=torch.max(t)
min_val=torch.min(t)
a= (max_-min_)/float(max_val-min_val)
b=max_-a*max_valt.mul_(a).add_(b)
returntensor
I don't see transforms for linear normalization (e.g. between 0-1 or arbitrary ranges) or std normalization? Do these exist somewhere else or do people just implement this in the Dataset class? Any plans for this? It's useful when sampling from folders. It also could be useful so you can potential remove the automatic division by 255. in the ToTensor() transform and therefore support loading arbitrary numpy arrays from file (an area for which there is a high user demand). Idk.. just a thought.
Anyways, here's some code to do these things:
and
The text was updated successfully, but these errors were encountered: