K.in_train_phase() 在训练集和验证集中返回相同的值

问题描述

我制作了一个自定义损失函数,它在训练集和验证集之间返回不同的值。 为了测试损失函数,我想让它在验证集中返回 0。 这是我所做的一个例子。

def custom_loss(y_true,y_pred):
  ...
  return K.in_train_phase(train_loss,0 * train_loss)

我用

训练模型
model.compile(optimizer=..,loss=custom_loss)
model.fit(X,Y,validation_split=0.2)

我用 dropout 层测试,没有 dropout 和使用

model.outputs[0]._uses_learning_phase = True

但是 loss 和 val_loss 总是一样的。 当 K.learning_phase 为 0 时返回 0,当 K.learning_phase 设置为 1 时返回正常的 loss。 如何在训练集和验证集之间设置 learning_phase?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)