Training a Network on MNIST dataset does not shows "metrics" values

Hi All,

I was training a network using MNIST dataset after completing Lesson 1 and below is the output that I am getting:

epoch train_loss valid_loss accuracy time
0 0.540953 #na# 01:32
1 0.232591 #na# 01:31
2 0.134819 #na# 01:30
3 0.110798 #na# 01:30

Below is the code I used:

path= untar_data(URLs.MNIST)
data= ImageDataBunch.from_folder(path= path, train=‘training’, test= ‘testing’, size=26 )
learn = cnn_learner(data,base_arch=models.resnet34, metrics= accuracy)
learn.fit_one_cycle(4)

I am not sure why I can’t see the accuracy or error rate in the output.

I am new to the fast.ai and this is my first post in the forum. I sincerely apologize for any formatting issues or incomplete information.

Blockquote

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
1 Like

Hey thanks a lot bro. It was so dumb of me to not include a validation set at all. I thought that if you dont mention it, it defaults to 20%. But today I learned something new. Thanks a lot! :slight_smile:

:ok_hand: