【发布时间】:2021-10-15 15:47:43
【问题描述】:
我正在使用 tensorflow/keras,我想在损失函数中使用输入
按照这里的答案
Custom loss function in Keras based on the input data
我就这样创建了我的损失函数
def custom_Loss_with_input(inp_1):
def loss(y_true, y_pred):
b = K.mean(inp_1)
return y_true - b
return loss
并设置具有层的模型,所有结束都像这样
model = Model(inp_1, x)
model.compile(loss=custom_Loss_with_input(inp_1), optimizer= Ada)
return model
但是,我收到以下错误:
TypeError: Cannot convert a symbolic Keras input/output to a numpy array. This error may indicate that you're trying to pass a symbolic value to a NumPy call, which is not supported. Or, you may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model.
关于如何消除此错误的任何建议? 提前致谢
【问题讨论】:
标签: python python-3.x tensorflow keras tensorflow2.0