Some things about MNIST first:
datapath = untar_data(URLs.MNIST); datapath.ls()
you get:
[PosixPath('/home/tc256760/.fastai/data/mnist_png/testing'),
PosixPath('/home/tc256760/.fastai/data/mnist_png/training')]
As you can see, MNIST is divided in two folders, training and testing. So, probably you need to set a validation set, two options:
- You take a percentage of training for validation, using kwarg
valid_pct
- You set the folder
testing
as your validation, passing valid='testing'
Try both.
Now, as you build the databunch
you can check this by printing it:
db = ImageDataBunch.from_folder(path=datapath, train='training', test='testing', valid_pct=0.2); db
ImageDataBunch;
Train: LabelList (48000 items)
x: ImageList
Image (3, 28, 28),Image (3, 28, 28),Image (3, 28, 28),Image (3, 28, 28),Image (3, 28, 28)
y: CategoryList
6,6,6,6,6
Path: /home/tc256760/.fastai/data/mnist_png;
Valid: LabelList (12000 items)
x: ImageList
Image (3, 28, 28),Image (3, 28, 28),Image (3, 28, 28),Image (3, 28, 28),Image (3, 28, 28)
y: CategoryList
2,4,1,6,5
Path: /home/tc256760/.fastai/data/mnist_png;
Test: LabelList (10000 items)
x: ImageList
Image (3, 28, 28),Image (3, 28, 28),Image (3, 28, 28),Image (3, 28, 28),Image (3, 28, 28)
y: EmptyLabelList
,,,,
Path: /home/tc256760/.fastai/data/mnist_png
TL;DR
Try these:
datapath = untar_data(URLs.MNIST)
data = ImageDataBunch.from_folder(path=datapath, train='training', test='testing', valid_pct=0.2)
learn = cnn_learner(data,base_arch=models.resnet34, metrics= [error_rate, accuracy])
learn.fit_one_cycle(4)
epoch |
train_loss |
valid_loss |
error_rate |
accuracy |
time |
0 |
0.600209 |
0.423010 |
0.135750 |
0.864250 |
00:22 |