Keras 中的回调函数,用于在每个时期保存预测输出

callback function in Keras to save predicted output at every epoch

我是 Keras 的新手,我打算为每个时期存储我的网络的输出。为此,我想使用 Tensorbaord 来观察其环境中的输出层。

class OutputObserver(Callback):
""""
callback to observe the output of the network
"""

    def on_train_begin(self, logs={}):
        self.epoch = []
        self.out_log = []

    def on_epoch_end(self, epoch, logs={}):
        self.epoch.append(epoch) 
        self.out_log.append(self.model.get_layer('Dense03/Output').output)

这会将输出张量存储到列表中。问题是我都不能做 1. 将其转换为 Numpy 数组以便可以读取 CSV,...文件, 2. 使用 Tensorflow 编写摘要(因为 Keras 没有此功能)然后分析输出在张量板上。

我很高兴听到您对在每个训练阶段存储和可视化输出层的意见。

真诚的, 赛义德.

要为每个时期保存输出层,您需要将 training/validation 数据传递给回调对象。我使用的回调如下,

class OutputObserver(Callback):
""""
callback to observe the output of the network
"""

def __init__(self, xy):
    self.out_log = []
    self.xy = xy

def on_epoch_end(self, epoch, logs={}):
    self.out_log.append(self.model.predict(self.xy.x_train, batch_size=p.bath_size))

其中xy.x_train是训练数据。

现在,out_log 数组是 numpy.ndarray 形状(epoch_number、data_number、prediction_length):

type(prediction_logs[0])
Out[62]: numpy.ndarray