tf.Keras

问题描述

我正在 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 中使用自定义损失函数,但从 x0 中切片和提取 x1y_pred(这应该是损失函数)。
  • 如何拟合训练数据?在本例中,我们有一个用于 c0 的数组训练数据,另一个用于 c1
  • 如果使用 Keras 很难实现这一点,是否有任何其他更容易处理的软件包的推荐?

非常感谢您阅读并回答我的问题。我尝试过自定义减肥和减肥,但到目前为止似乎没有帮助。

解决方法

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

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

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