Normalize each sample in a batch independently with min-max normalization to [0, 1]
(x)
| 81 | |
| 82 | |
| 83 | def per_sample_min_max_normalization(x): |
| 84 | """ Normalize each sample in a batch independently |
| 85 | with min-max normalization to [0, 1] """ |
| 86 | bs, *shape = x.shape |
| 87 | x_ = einops.rearrange(x, "b ... -> b (...)") |
| 88 | min_val = einops.reduce(x_, "b ... -> b", "min")[..., None] |
| 89 | max_val = einops.reduce(x_, "b ... -> b", "max")[..., None] |
| 90 | x_ = (x_ - min_val) / (max_val - min_val) |
| 91 | return x_.reshape(bs, *shape) |
| 92 | |
| 93 | |
| 94 | class ImageDepthVisualizer: |