Class: DNN::Callbacks::Logger

Inherits:
Callback
  • Object
show all
Defined in:
lib/dnn/core/callbacks.rb

Overview

A callback that save the log. The following logs will be recorded. epoch: Current epoch. step: Current step in epoch. loss: Batch training loss. accuracy: Batch training accuracy. test_loss: Mean test loss. test_accuracy: Test accuracy.

Instance Attribute Summary

Attributes inherited from Callback

#model

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



121
122
123
124
125
126
127
128
129
130
# File 'lib/dnn/core/callbacks.rb', line 121

def initialize
  @log = {
    epoch: [],
    step: [],
    loss: [],
    accuracy: [],
    test_loss: [],
    test_accuracy: [],
  }
end

Instance Method Details

#after_epochObject



132
133
134
# File 'lib/dnn/core/callbacks.rb', line 132

def after_epoch
  logging(:epoch, :test_loss, :test_accuracy)
end

#after_train_on_batchObject



136
137
138
# File 'lib/dnn/core/callbacks.rb', line 136

def after_train_on_batch
  logging(:loss, :step)
end

#get_log(tag) ⇒ Numo::NArray

Get a log.

Parameters:

  • tag (Symbol)

    Tag indicating the type of Log.

Returns:

  • (Numo::NArray)

    Return the recorded log.



143
144
145
146
147
148
149
150
# File 'lib/dnn/core/callbacks.rb', line 143

def get_log(tag)
  case tag
  when :epoch, :step
    Xumo::UInt32.cast(@log[tag])
  else
    Xumo::SFloat.cast(@log[tag])
  end
end