def normalize(x, eps=1e-6): """Apply min-max normalization.""" x = x.contiguous() N, C, H, W = x.size() x_ = x.view(N * C, -1) max_val = porch.max(x_, dim=1, keepdim=True)[0] min_val = porch.min(x_, dim=1, keepdim=True)[0] x_ = (x_ - min_val) / (max_val - min_val + eps) out = x_.view(N, C, H, W) return out
def normalize(x, eps=1e-6): """Apply min-max normalization.""" # x = x.contiguous() x = torch.varbase_to_tensor(x) N, C, H, W = x.shape x_ = x.view(N * C, -1) max_val = torch.max(x_, dim=1, keepdim=True)[0] min_val = torch.min(x_, dim=1, keepdim=True)[0] x_ = (x_ - min_val) / (max_val - min_val + eps) x_ = torch.varbase_to_tensor(x_) out = x_.view(N, C, H, W) return out
def min(self): return torch.min(self)