作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Keras 新手,我学会了拟合和评估模型。评估模型后,我们可以看到模型做出的实际预测。
我想知道在 Keras 中拟合期间是否也可以看到预测?到目前为止,我找不到任何执行此操作的代码。
最佳答案
由于这个问题没有指定“纪元”,并且由于使用回调可能代表额外的计算,因此我认为这并不完全是重复。
通过 tensorflow ,您可以使用自定义训练循环并打开急切执行。创建自定义训练循环的简单教程:https://www.tensorflow.org/tutorials/eager/custom_training_walkthrough
基本上你会:
#transform your data in to a Dataset:
dataset = tf.data.Dataset.from_tensor_slices(
(x_train, y_train)).shuffle(some_buffer).batch(batchSize)
#the above is buggy in some versions regarding shuffling, you may need to shuffle
#again between each epoch
#create an optimizer
optimizer = tf.keras.optimizers.Adam()
#create an epoch loop:
for e in range(epochs):
#create a batch loop
for i, (x, y_true) in enumerate(dataset):
#create a tape to record actions
with tf.GradientTape() as tape:
#take the model's predictions
y_pred = model(x)
#calculate loss
loss = tf.keras.losses.binary_crossentropy(y_true, y_pred)
#calculate gradients
gradients = tape.gradient(loss, model.trainable_weights)
#apply gradients
optimizer.apply_gradients(zip(gradients, model.trainable_weights)
您可以使用 y_pred
var 执行任何操作,包括获取其 numpy_pred = y_pred.numpy()
值。
本教程提供了有关指标和验证循环的更多详细信息。
关于machine-learning - 如何在 Keras 中拟合模型期间检查预测输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58114217/
我是一名优秀的程序员,十分优秀!