Exemple #1
0
 def get_transforms(stage: str = None, mode: str = None):
     """
     @TODO: Docs. Contribution is welcome
     """
     return Compose([ToTensor(), Normalize((0.1307,), (0.3081,))])
    sys.exit()

# # Data

# In[ ]:

import collections
import torch

from catalyst.contrib.datasets import MNIST
from catalyst.contrib.data.transforms import ToTensor, Compose, Normalize

bs = 32
num_workers = 0

data_transform = Compose([ToTensor(), Normalize((0.1307, ), (0.3081, ))])

loaders = collections.OrderedDict()

trainset = MNIST("./data",
                 train=False,
                 download=True,
                 transform=data_transform)
trainloader = torch.utils.data.DataLoader(trainset,
                                          batch_size=bs,
                                          shuffle=True,
                                          num_workers=num_workers)

testset = MNIST("./data", train=False, download=True, transform=data_transform)
testloader = torch.utils.data.DataLoader(testset,
                                         batch_size=bs,
    loaders["train"] = train_loader
    loaders["valid"] = valid_loader

    return loaders


data_transform = Compose(
    [
        Augmentor(
            dict_key="features",
            augment_fn=lambda x: torch.from_numpy(
                x.copy().astype(np.float32) / 255.0
            ).unsqueeze_(0),
        ),
        Augmentor(dict_key="features", augment_fn=Normalize((0.5,), (0.5,)),),
        Augmentor(
            dict_key="targets",
            augment_fn=lambda x: torch.from_numpy(
                x.copy().astype(np.float32) / 255.0
            ).unsqueeze_(0),
        ),
    ]
)

loaders = get_loaders(data_transform)

# # Model

# In[ ]: