MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / default_normalizer

Function default_normalizer

monai/visualize/class_activation_maps.py:31–47  ·  view source on GitHub ↗

A linear intensity scaling by mapping the (min, max) to (1, 0). If the input data is PyTorch Tensor, the output data will be Tensor on the same device, otherwise, output data will be numpy array. Note: This will flip magnitudes (i.e., smallest will become biggest and vice versa).

(x: NdarrayTensor)

Source from the content-addressed store, hash-verified

29
30
31def default_normalizer(x: NdarrayTensor) -> NdarrayTensor:
32 """
33 A linear intensity scaling by mapping the (min, max) to (1, 0).
34 If the input data is PyTorch Tensor, the output data will be Tensor on the same device,
35 otherwise, output data will be numpy array.
36
37 Note: This will flip magnitudes (i.e., smallest will become biggest and vice versa).
38 """
39
40 def _compute(data: np.ndarray) -> np.ndarray:
41 scaler = ScaleIntensity(minv=1.0, maxv=0.0)
42 return np.stack([scaler(i) for i in data], axis=0)
43
44 if isinstance(x, torch.Tensor):
45 return torch.as_tensor(_compute(x.detach().cpu().numpy()), device=x.device) # type: ignore
46
47 return _compute(x) # type: ignore
48
49
50class ModelWithHooks:

Callers

nothing calls this directly

Calls 2

_computeFunction · 0.85
as_tensorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…