HybridRSC / inference /transforms.py
jinbo2277's picture
Initial commit
8defb25
Raw History Blame Contribute Delete
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
])