This module allows to perform training from a given network, dataset and options.
trainer.initialize(network, criterion, opt)
This functions initializes the basic states of the optimizer.
It must be called before any other method on the trainer.
It takes as input the network
, the criterion
and an option table.
The possible options are:
opt.lr
: the learning rateopt.lrd
: the learning rate decayopt.mom
: the momentumopt.wd
: the weight decayopt.no_cuda
: to disable the use of cudaopt.bs
: the minibatch size
trainer.train(dataset)
This function performs one epoch of training using the given dataset. It returns the total error on the dataset.
trainer.test(dataset)
This function evaluates the current network on the given dataset. It returns both the total error and accuracy on the dataset.
local trainer = require 'trainer'
local train_dataset, test_dataset, network, criterion
------
-- Initialize all these elements with the other modules
local opt = {}
opt.lr = 0.01
trainer.initialize(network, criterion, opt)
local accuracy
for epoch=1,10 do
trainer.train(train_dataset)
_, accuracy = trainer.test(test_dataset)
end
print("Final accuracy: "..accuracy)