Trainer

This module contains the trainer code and other codes regarding training.

class lenet.trainer.trainer(network, dataset)[source][source]

Trainer for networks

Parameters:
  • network – A network class object
  • dataset – A tensorflow dataset object
network[source]

This is the network we initialized with. We pass this as an argument and we add it to the current trainer class.

dataset[source]

This is also the initializer. It comes from the lenet.dataset.mnist module.

session[source]

This is a session created with trainer. This session is used for training.

tensorboard[source]

Is a summary writer tool. This writes things into the tensorboard that is then setup on the tensorboard server. At the end of the trainer, it closes this tensorboard.

accuracy(images, labels)[source][source]

Return accuracy

Parameters:
  • images – images
  • labels – labels
Returns:

accuracy

Return type:

float

bp_step(mini_batch_size)[source][source]

Sample a minibatch of data and run one step of BP.

Parameters:mini_batch_size – Integer
Returns:total objective and cost of that step
Return type:tuple of tensors
summaries(name='tensorboard')[source][source]

Just creates a summary merge bufer

Parameters:name – a name for the tensorboard directory
test()[source][source]

Run validation of the model

Returns:accuracy
Return type:float
train(iter=10000, mini_batch_size=500, update_after_iter=1000, training_accuracy=False, summarize=True)[source][source]

Run backprop for iter iterations

Parameters:
  • iter – number of iterations to run
  • mini_batch_size – Size of the mini batch to process with
  • training_accuracy – if True, will calculate accuracy on training data also.
  • update_after_iter – This is the iteration for validation
  • summarize – Tensorboard operation
training_accuracy(mini_batch_size=500)[source][source]

Run validation of the model on training set

Parameters:mini_batch_size – Number of samples in a mini batch
Returns:accuracy
Return type:float
write_summary(iter=0, mini_batch_size=500)[source][source]

This method updates the summaries

Parameters:
  • iter – iteration number to index values with.
  • mini_batch_size – Mini batch to evaluate on.