from fastai.vision import *
path = untar_data(URLs.CIFAR)
ds_tfms = ([*rand_pad(4, 32), flip_lr(p=0.5)], [])
data = ImageDataBunch.from_folder(path, valid='test', ds_tfms=ds_tfms, bs=512).normalize(cifar_stats)
class Net(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(3, 32, 3, 1)
self.conv2 = nn.Conv2d(32, 64, 3, 1)
self.pool = nn.AdaptiveAvgPool2d((1,1))
self.fc1 = nn.Linear(64, 10)
def forward(self, x):
x = F.relu(self.conv1(x))
x = F.relu(self.conv2(x))
x = self.pool(x)
x = x.view(x.shape[0], -1)
x = self.fc1(x)
return x
net = Net()
learn = Learner(data, net, metrics=[accuracy])
learn.fit_one_cycle(3, 1e-3)
epoch | train_loss | valid_loss | accuracy | time |
---|---|---|---|---|
0 | 1.921551 | 1.865704 | 0.320800 | 00:07 |
1 | 1.831898 | 1.771576 | 0.341300 | 00:07 |
2 | 1.788265 | 1.754561 | 0.356600 | 00:07 |