gpt4 book ai didi

machine-learning - 如何在 Keras 中拟合模型期间检查预测输出?

转载 作者:行者123 更新时间:2023-11-30 09:03:46 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com