Spaces:
Build error
Build error
Download src/pixel3dmm/utils/misc.py from karolwoz/pixel3dmms: direct link, hf CLI and curl.
- Browser
- Download file 551 Bytes
-
https://huggingface.co/spaces/karolwoz/pixel3dmms/resolve/main/src/pixel3dmm/utils/misc.py
- Command line
-
hf download hf://spaces/karolwoz/pixel3dmms/src/pixel3dmm/utils/misc.py
-
curl -L -o misc.py https://huggingface.co/spaces/karolwoz/pixel3dmms/resolve/main/src/pixel3dmm/utils/misc.py
551 Bytes
| import numpy as np | |
| import torch | |
| def tensor2im(input_image, imtype=np.uint8): | |
| if isinstance(input_image, torch.Tensor): | |
| input_image = torch.clamp(input_image, -1.0, 1.0) | |
| image_tensor = input_image.data | |
| else: | |
| return input_image.reshape(3, 512, 512).transpose() | |
| image_numpy = image_tensor[0].cpu().float().numpy() | |
| if image_numpy.shape[0] == 1: | |
| image_numpy = np.tile(image_numpy, (3, 1, 1)) | |
| image_numpy = (np.transpose(image_numpy, (1, 2, 0)) + 1) / 2.0 * 255.0 | |
| return image_numpy.astype(imtype) | |