解决方案
好吧,我确实找到了一个解决方案,也许不是最好的。实际上,我们刚刚创建了一个新方法,它使用了TensorFlow中的GradientTape。基本上,得到预测,生成目标,计算损失,然后更新梯度
with tf.GradientTape() as tape:
# Forward pass
y_preds = self.model(x, training=True)
# Generate the target values from the predictions
actual_deltas, actual_objectness = self.generate_target_values(y_preds, labels)
#Get the loss
loss = self.model.compiled_loss([actual_deltas, actual_objectness], y_preds, regularization_losses=self.model.losses)
# Compute gradients
trainable_vars = self.model.trainable_variables
gradients = tape.gradient(loss, trainable_vars)
# Update weights
self.model.optimizer.apply_gradients(zip(gradients, trainable_vars))
我知道有更好的方法可以通过Keras子类化来实现这一点,但这确实起到了作用
原创帖子
我目前正在尝试创建一个模型,其中预测需要通过一个函数运行,该函数将它们与训练标签进行比较。然后,此函数将返回目标值。我如何训练我的模型,这样预测将被输入到我的函数中,它将返回函数pred。 我使用的是Tensorflow 2.1.0和Keras 2.2.4-tf
编辑:
该模型是一种改进的快速RCNN模型。 我尝试添加函数,该函数接受预测(2xN和4xN向量),将它们转换为边界框,将它们与地面真值边界框进行比较,然后返回每个建议的边界框值应该是什么,以便正确覆盖该边界框
好吧,我确实找到了一个解决方案,也许不是最好的。实际上,我们刚刚创建了一种新方法,它使用了TensorFlow的GradientTape。基本上,得到预测,生成目标,计算损失,然后更新梯度
我知道有更好的方法可以通过Keras子类化来实现这一点,但这确实起到了作用
相关问题 更多 >
编程相关推荐