Download scripts/sanity.py from drbh/img2gray: direct link, hf CLI and curl.
- Browser
- Download file 490 Bytes
-
https://huggingface.co/drbh/img2gray/resolve/main/scripts/sanity.py
- Command line
-
hf download hf://drbh/img2gray/scripts/sanity.py
-
curl -L -o sanity.py https://huggingface.co/drbh/img2gray/resolve/main/scripts/sanity.py
490 Bytes
| import torch | |
| import img2gray | |
| from PIL import Image | |
| import numpy as np | |
| print(dir(img2gray)) | |
| img = Image.open("kernel-builder-logo-color.png").convert("RGB") | |
| img = np.array(img) | |
| img_tensor = torch.from_numpy(img).cuda() | |
| print(img_tensor.shape) # HWC | |
| gray_tensor = img2gray.img2gray(img_tensor).squeeze() | |
| print(gray_tensor.shape) # HW | |
| # save the output image | |
| gray_img = Image.fromarray(gray_tensor.cpu().numpy().astype(np.uint8), mode="L") | |
| gray_img.save("kernel-builder-logo-gray.png") | |