0

I need to collect the targets and outputs vectors from my model after each batch using TensorFlow V2 and Keras 2.3.0. A similar question was previsously answered, but is valid only for TensorFlow V1. Did someone have an idea on how to proceed?

As I am using a batch_size of 1 file (this is very specific to my case), my initial idea was to define a metric that would return the target/ouput label (i.e. an integer), and collect it in a callback at each batch end. Unfortunately, this metric is processed as any other metrics an averaged after each batch. I cannot find a way to simply return the un-averaged value, or even better to fetch it in a 1D array.

beardybear
  • 159
  • 2
  • 15

1 Answers1

0

The simplest way to get the output tensor is to use train/predict_on_batch(). For example:

    for epoch in range(max_epoch):

        for batch_i in range(max_batch):
            x_i, y_true = next(training_generator)
            batch_i = model.train_on_batch(x_i, y_true, reset_metrics=True)
            print("metrics = {}".format(batch_i))
            print("outputs = {}".format(model.predict_on_batch(x_i)))
beardybear
  • 159
  • 2
  • 15