(
tensor: th.Tensor, x_max: Optional[float] = None, x_min: Optional[float] = None
)
| 52 | |
| 53 | |
| 54 | def tensor2rgb( |
| 55 | tensor: th.Tensor, x_max: Optional[float] = None, x_min: Optional[float] = None |
| 56 | ) -> np.ndarray: |
| 57 | x = tensor.data.cpu().numpy() |
| 58 | if x_min is None: |
| 59 | x_min = x.min() |
| 60 | if x_max is None: |
| 61 | x_max = x.max() |
| 62 | |
| 63 | gain = 255 / np.clip(x_max - x_min, 1e-3, None) |
| 64 | x = (x - x_min) * gain |
| 65 | x = x.clip(0.0, 255.0) |
| 66 | x = x.astype(np.uint8) |
| 67 | return x |
| 68 | |
| 69 | |
| 70 | def tensor2image( |
no outgoing calls
no test coverage detected