(img)
| 78 | |
| 79 | # convert 2/3/4-dimensional torch tensor to uint |
| 80 | def tensor2uint(img): |
| 81 | img = img.data.squeeze().float().clamp_(0, 1).cpu().numpy() |
| 82 | if img.ndim == 3: |
| 83 | img = np.transpose(img, (1, 2, 0)) |
| 84 | return np.uint8((img*255.0).round()) |
| 85 | |
| 86 | |
| 87 | if __name__ == '__main__': |