This is the code that I had
def train(net, loss_fn, train_data, epochs, batch_size):
train_acc= metric.Accuracy()
trainer= gluon.Trainer(net.collect_params(),
'sgd',{'learning_rate': 0.1})
for epoch in range(2):
train_loss = 0
for data, label in train_data:
with autograd.record():
output = net(data)
loss = loss_fn(output, label)
loss.backward()
trainer.step(batch_size)
train_loss += loss.mean().asscalar()
train_acc.update(label, output)
print("Epoch [%d] Loss:%.3f Acc:%.3f"%(
epoch, train_loss/len(train_data),
train_acc.get()[1]))
net.save_parameters('trained_net.params')
return train_data, train_acc.get()[1]
We are supposed to train for 5 epochs and achieve an accuracy of over 99%
net, ta = train(*get_network(), train_data, 5, batch_size)
The image showed that the accuracy has topped off at 98.8%, which obviously failed to surpass 99%. Plus, the training stopped at epoch[2] instead of epoch[4]
I must have made an error somewhere, but failed to locate that error. Need someone to point out the error