【发布时间】:2021-08-20 15:34:27
【问题描述】:
我正在使用 tf.Keras 中的 DNN,如下所示:
# Construct the DNN model with 2 inputs, 2 outputs and 3 hidden layers
c0_input = Input(shape=(1,), name="c0")
c1_input = Input(shape=(1,), name="c1")
# Concatenate the input into one layer
tensor_input = Concatenate(axis=-1)([c0_input, c1_input])
hidden_1 = Dense(100)(tensor_input)
activation_1 = LeakyReLU(alpha=0.1)(hidden_1)
hidden_2 = Dense(100)(activation_1)
activation_2 = LeakyReLU(alpha=0.1)(hidden_2)
hidden_3 = Dense(100)(activation_2)
activation_3 = LeakyReLU(alpha=0.1)(hidden_3)
# 2 outputs are named as x0 and x1
x0_output = Dense(1, name="x0")(activation_3)
x1_output = Dense(1, name="x1")(activation_3)
# The model
DNN_model = Model(inputs=[c0_input, c1_input], outputs=[x0_output, x1_output])
如您所见,此 DNN 有 2 个输入 (c0, c1) 和 2 个输出 (x0, x1)。我瞄准的损失函数是:c0 * (x0 - x1**2)**2 + c1 * (x1 - c0 * x0)**2,它包括两个输入和两个输出。以下是我的问题:
- 如何编写考虑所有
c0, c1, x0, x1的损失函数?我曾尝试使用 Keras 中的自定义损失函数,但从y_pred(应该是损失函数的一部分)中切片和提取x0和x1似乎是不正确的。 - 如何拟合训练数据?在这种情况下,我们有一个用于
c0和另一个用于c1的数组训练数据。 - 如果用 Keras 很难做到这一点,是否有任何其他更容易处理的包的建议?
非常感谢您阅读并回答我的问题。我尝试过自定义减肥和减肥,但到目前为止似乎没有帮助。
【问题讨论】:
标签: python tf.keras loss-function multiple-input