【发布时间】:2019-03-20 09:01:25
【问题描述】:
我正在尝试学习新的 TF 2.0 alpha 版本。我正在为二进制分类目的训练一个Sequential 模型。我的数据表是df,它是一个 numpy 数组。 classification 是我必须预测的类的 one-hot 编码数据帧。
模型的定义很明确,因为它是损失函数和准确率函数以及 (Adam) 优化器的定义。 但是,我在训练时遇到错误:
loss_history = []
accuracy_history = []
for epoch in range(n_epochs):
with tf.GradientTape() as tape:
# compute binary crossentropy loss (bce_loss)
current_loss = bce_loss(model(df), classification.astype(np.float64))
loss_history.append(current_loss)
# train the model based on the gradient of loss function
gradients = tape.gradient(current_loss, model.trainable_variables)
optimizer.apply_gradients([gradients, model.trainable_variables]) # optimizer = Adam
# print the training progress
print(str(epoch+1) + '. Train Loss: ' + str(metrics) + ', Accuracy: ' + str(current_accuracy))
print('\nTraining complete.')
此时,我收到指向optimizer.apply_gradients() 的错误。错误消息说:
ValueError:解包的值太多(预计 2 个)
我的错误在哪里?
我对此类错误进行了一些研究,但没有发现与此特定功能相关的任何有用信息。任何帮助表示赞赏。
【问题讨论】:
-
通过接受答案,问题已被标记为已解决。无需编辑问题。另见meta.stackexchange.com/questions/116101/…
标签: python tensorflow neural-network tensorflow2.0