English
DeepChoice / image_baseline /utils /transforms.py
antoine.carreaud67
Clean and reorganize repository for public release
4a48212
Raw
History Blame Contribute Delete
458 Bytes
import numpy as np
import torch
class ToTensorNormalize:
def __init__(self, mean, std):
self.mean = torch.tensor(mean, dtype=torch.float32).view(-1, 1, 1)
self.std = torch.tensor(std, dtype=torch.float32).view(-1, 1, 1)
def __call__(self, image):
image_np = np.asarray(image, dtype=np.float32) / 255.0
tensor = torch.from_numpy(image_np).permute(2, 0, 1).contiguous()
return (tensor - self.mean) / self.std