Learning statistics

class slayerSNN.learningStats.learningStat[source]

This class collect the learning statistics over the epoch.

Usage:

This class is designed to be used with learningStats instance although it can be used separately.

>>> trainingStat = learningStat()
accuracy()[source]

Returns the average accuracy calculated from the point the stats was reset.

Usage:

>>> accuracy = trainingStat.accuracy()
loss()[source]

Returns the average loss calculated from the point the stats was reset.

Usage:

>>> loss = trainingStat.loss()
reset()[source]

Reset the learning staistics. This should usually be done before the start of an epoch so that new statistics counts can be accumulated.

Usage:

>>> trainingStat.reset()
update()[source]

Updates the stats of the current session and resets the measures for next session.

Usage:

>>> trainingStat.update()
class slayerSNN.learningStats.learningStats[source]

This class provides mechanism to collect learning stats for training and testing, and displaying them efficiently.

Usage:

stats = learningStats()

for epoch in range(100):
    tSt = datetime.now()

    stats.training.reset()
    for i in trainingLoop:
        # other main stuffs
        stats.training.correctSamples += numberOfCorrectClassification
        stats.training.numSamples     += numberOfSamplesProcessed
        stats.training.lossSum        += currentLoss
        stats.print(epoch, i, (datetime.now() - tSt).total_seconds())
    stats.training.update()

    stats.testing.reset()
    for i in testingLoop
        # other main stuffs
        stats.testing.correctSamples += numberOfCorrectClassification
        stats.testing.numSamples     += numberOfSamplesProcessed
        stats.testing.lossSum        += currentLoss
        stats.print(epoch, i)
    stats.training.update()
load(filename='', numEpoch=None, modulo=1)[source]

Loads the learning statistics logs from saved files.

Arguments:
  • filename: filename to save the logs. accuracy.txt and loss.txt will be appended.

  • numEpoch: number of epochs of logs to load. Default: None. numEpoch will be automatically determined from saved files.

  • modulo: the gap in number of epoch before model was saved.

Usage:

# save stats
stats.load(epoch=10) 

# save stats filename specified
stats.save(filename='Run101-0.001-', epoch=50) # Run101-0.001-accuracy.txt and Run101-0.001-loss.txt
plot(figures=1, 2, saveFig=False, path='')[source]

Plots the available learning statistics.

Arguments:
  • figures: Index of figure ID to plot on. Default is figure(1) for loss plot and figure(2) for accuracy plot.

  • saveFig``(``bool): flag to save figure into a file.

  • path: path to save the file. Defaule is ''.

Usage:

# plot stats
stats.plot() 

# plot stats figures specified
stats.print(figures=(10, 11)) 
print(epoch, iter=None, timeElapsed=None, header=None, footer=None)[source]

Prints the available learning statistics from the current session on the console. For Linux systems, prints the data on same terminal space (might not work properly on other systems).

Arguments:
  • epoch: epoch counter to display (required).

  • iter: iteration counter to display (not required).

  • timeElapsed: runtime information (not required).

  • header: things to be printed before printing learning statistics. Default: None.

  • footer: things to be printed after printing learning statistics. Default: None.

Usage:

# prints stats with epoch index provided
stats.print(epoch) 

# prints stats with epoch index and iteration index provided
stats.print(epoch, iter=i) 

# prints stats with epoch index, iteration index and time elapsed information provided
stats.print(epoch, iter=i, timeElapsed=time) 
save(filename='')[source]

Saves the learning satatistics logs.

Arguments:
  • filename: filename to save the logs. accuracy.txt and loss.txt will be appended.

Usage:

# save stats
stats.save() 

# save stats filename specified
stats.save(filename='Run101-0.001-') # Run101-0.001-accuracy.txt and Run101-0.001-loss.txt
update()[source]

Updates the stats for training and testing and resets the measures for next session.

Usage:

>>> stats.update()