(x, to255=False)
| 89 | |
| 90 | |
| 91 | def array2grid(x, to255=False): |
| 92 | nrow = round(math.sqrt(x.size(0))) |
| 93 | x = make_grid(x, nrow=nrow, normalize=True, value_range=(-1, 1)) |
| 94 | if to255: |
| 95 | x = ( |
| 96 | x.mul(255) |
| 97 | .add_(0.5) |
| 98 | .clamp_(0, 255) |
| 99 | .permute(1, 2, 0) |
| 100 | .to("cpu", torch.uint8) |
| 101 | .numpy() |
| 102 | ) |
| 103 | else: |
| 104 | x = x.permute(1, 2, 0).to("cpu", torch.uint8).numpy() |
| 105 | return x |
| 106 | |
| 107 | |
| 108 | def array2grid_pixel(x): |