Download Rad_IR/radir/data/utils.py from AIGeeksGroup/HMCLIP: direct link, hf CLI and curl.
- Browser
- Download file 513 Bytes
-
https://huggingface.co/AIGeeksGroup/HMCLIP/resolve/main/Rad_IR/radir/data/utils.py
- Command line
-
hf download hf://AIGeeksGroup/HMCLIP/Rad_IR/radir/data/utils.py
-
curl -L -o utils.py https://huggingface.co/AIGeeksGroup/HMCLIP/resolve/main/Rad_IR/radir/data/utils.py
513 Bytes
| from PIL import Image | |
| def get_imgs_from_pickle(img, transform=None): | |
| """ | |
| 将 H5/PKL 里读出的 numpy 图像数组转为 RGB PIL,再按需应用 transform。 | |
| 参数: | |
| img: numpy.ndarray,形状一般为 (H, W) 或 (H, W, C) | |
| transform: 可选的 torchvision transforms | |
| 返回: | |
| 已转换的图像(通常为张量) | |
| """ | |
| pil_img = Image.fromarray(img).convert("RGB") | |
| if transform is not None: | |
| pil_img = transform(pil_img) | |
| return pil_img | |