我想打印LSTM层的状态值。
class CustomCallback(keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs=None):
encoder_outputs, state_h, state_c = self.model.layers[1].output
print(state_h)
print(state_c)
它正在打印这样的东西
32/32 - 0s - loss: 39.6719 - accuracy: 0.2420
KerasTensor(type_spec=TensorSpec(shape=(None, 5), dtype=tf.float32, name=None), name='lstm_5/PartitionedCall:3', description="created by layer 'lstm_5'")
Epoch 5/20000
32/32 - 0s - loss: 39.6549 - accuracy: 0.2420
KerasTensor(type_spec=TensorSpec(shape=(None, 5), dtype=tf.float32, name=None), name='lstm_5/PartitionedCall:3', description="created by layer 'lstm_5'")
如何打印Tensor的真实的值?
1条答案
按热度按时间p8ekf7hl1#
为了看到一些真实的值,你必须在
Callback
函数中向LSTM
层提供一些数据:请注意,我创建了一个
x_test
Tensor,但您也可以将x_train
提供给回调函数。lstm_layer
根据您的训练进度保存当前权重。您可以通过在Callback
函数中打印层权重来验证这一点:tf.print(lstm_layer.get_weights())
。