Download inference/transforms.py from jinbo2277/HybridRSC: direct link, hf CLI and curl.
- Browser
- Download file 736 Bytes
-
https://huggingface.co/jinbo2277/HybridRSC/resolve/main/inference/transforms.py
- Command line
-
hf download hf://jinbo2277/HybridRSC/inference/transforms.py
-
curl -L -o transforms.py https://huggingface.co/jinbo2277/HybridRSC/resolve/main/inference/transforms.py
736 Bytes
| """Deterministic three-view RSCD evaluation preprocessing.""" | |
| import torch | |
| from torchvision import transforms | |
| from torchvision.transforms import InterpolationMode | |
| from torchvision.transforms import functional as TF | |
| class ThreeViewTransform: | |
| def __call__(self, image): | |
| image = transforms.Resize(256, interpolation=InterpolationMode.BICUBIC)(image.convert("RGB")) | |
| width, height = image.size | |
| left = int(round((width - 224) / 2)) | |
| tops = (0, int(round((height - 224) / 2)), height - 224) | |
| return torch.stack([ | |
| TF.normalize(TF.to_tensor(TF.crop(image, top, left, 224, 224)), | |
| (0.485, 0.456, 0.406), (0.229, 0.224, 0.225)) | |
| for top in tops | |
| ]) | |