I am using Keras to train a cnn and I need to record accuracy and loss for each batch. Is there any way to save the statistics? Following is the code I am using but the accuracy is none. Also it looks like the callback is suppressing progress bar.
class Histories(keras.callbacks.Callback):
def __init__(self, test_data):
self.test_data = test_data
def on_train_begin(self, logs={}):
self.train_acc = []
self.test_acc = []
self.train_loss = []
self.test_loss = []
def on_batch_end(self, batch, logs={}):
train_loss_batch = logs.get('loss')
train_acc_batch = logs.get('accuracy')
self.train_loss.append(train_loss_batch)
self.train_acc.append(train_acc_batch)
print('\nTrain loss: {}, acc: {}\n'.format(train_loss_batch, train_acc_batch))
x, y = self.test_data
test_loss_batch, test_acc_batch = self.model.evaluate(x, y, verbose=0)
self.test_loss.append(test_loss_batch)
self.test_acc.append(test_acc_batch)
print('\nTesting loss: {}, acc: {}\n'.format(test_loss_batch, test_acc_batch))
To use the callback:
histories = my_callbacks.Histories((x_test, y_test))
model.fit(x_train_reduced, y_train_reduced, batch_size, epochs, verbose=1, callbacks=[histories])