我正在学习这个 Keras 教程,该教程解释了如何编写您的自定义 train_step() 函数,同时仍然能够调用 model.fit() 来训练您的模型:
https://keras.io/guides/customizing_what_happens_in_fit/
model.fit() 应该能够支持 validation_data 但我不知道在哪里编写代码来计算 validation_data 的自定义指标和自定义损失。 我决定编写一个自定义循环,但我想使用 fit。
有什么想法吗?
最佳答案
我完全错过了指南中提到函数 test_step() 的段落:
def test_step(self, data):
# Unpack the data
x, y = data
# Compute predictions
y_pred = self(x, training=False)
# Updates the metrics tracking the loss
self.compiled_loss(y, y_pred, regularization_losses=self.losses)
# Update the metrics.
self.compiled_metrics.update_state(y, y_pred)
# Return a dict mapping metric names to current value.
# Note that it will include the loss (tracked in self.metrics).
return {m.name: m.result() for m in self.metrics}
关于python - 如何修改 train_step 以便在调用 model.fit() 时支持验证集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63508441/