我正在尝试学习新的 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)
我的错误在哪里?
我对这种类型的错误进行了一些研究,但没有发现与此特定功能相关的任何有用信息。任何帮助表示赞赏。