def test_tf(img): img = tfs.Resize(256)(img) img, _ = tfs.CenterCrop(224)(img) normalize = tfs.Compose([ tfs.ToTensor(), tfs.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) ]) img = normalize(img) return img
def img_transforms(img, label, crop_size): img, label = random_crop(img, label, crop_size) img_tfs = tfs.Compose([ tfs.ToTensor(), tfs.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) ]) img = img_tfs(img) label = image2label(label) label = torch.from_numpy(label) return img, label
def pytorch_normalize(img): """Normalize input image in pytorch way. Use pytorch way to do normalize, taking from a numpy.ndarray. Args: img(~numpy.ndarray): Image to be normalized, which is a numpy.ndarray. Returns: An normalized torch.Tensor, CHW order and range from :math:`[0, 1]`. """ img = torch.from_numpy(img) / 255. normalize = tfs.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) img = normalize(img) return img.numpy()
from config import opt from mxtorch import meter from mxtorch import transforms as tfs from mxtorch.trainer import * from mxtorch.vision import model_zoo from torch import nn from torch.autograd import Variable from torch.utils.data import DataLoader from torchvision.datasets import ImageFolder from tqdm import tqdm train_tf = tfs.Compose([ tfs.RandomResizedCrop(224), tfs.RandomHorizontalFlip(), tfs.ToTensor(), tfs.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) ]) def test_tf(img): img = tfs.Resize(256)(img) img, _ = tfs.CenterCrop(224)(img) normalize = tfs.Compose([ tfs.ToTensor(), tfs.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) ]) img = normalize(img) return img def get_train_data():