application_vnd.jupyter.stderr_output_2.png text_plain_output_3.png text_plain_output_1.png
from torch.utils.data import Dataset, DataLoader

from torch.utils.data.sampler import SubsetRandomSampler

from torchvision import transforms

import numpy as np

import pandas as pd

train_set = pd.read_csv('../input/digit-recognizer/train.csv')
test_set = pd.read_csv('../input/digit-recognizer/test.csv')

valid_size = 0.1
data_nums = len(train_set)
indices = list(range(data_nums))
np.random.shuffle(indices)
splits = int(np.floor(valid_size * data_nums))
train_ind, valid_ind = (indices[splits:], indices[:splits])
train_s = SubsetRandomSampler(train_ind)
valid_s = SubsetRandomSampler(valid_ind)

transforms_dic = {'train': transforms.Compose([transforms.ToPILImage(), transforms.RandomAffine(8, translate=(0, 0.1), scale=(0.8, 1.2)), transforms.ToTensor()]), 'valid': transforms.Compose([transforms.ToTensor()]), 'test': transforms.Compose([transforms.ToTensor()])}
train = Datamnist(train_set, transforms_dic['train'])
valid = Datamnist(train_set, transforms_dic['valid'])
test = Datamnist(test_set, transforms_dic['test'], labels=False)
train_loader = DataLoader(train, batch_size=128, sampler=train_s)
valid_loader = DataLoader(valid, sampler=valid_s)
test_loader = DataLoader(test)

Trainmodel = Runmodel(train_loader, valid_loader)
Trainmodel.train()