我真的希望有人可以帮助我。我正在尝试构建一个具有 2 个输出 [[1 个数字]、[3 个数字]] 的网络,而我想使用两个不同的损失函数。我也使用生成器。所以我的问题是将 keras 生成器与多输出、多损失网络结合起来。在下面,我将向您展示我的部分代码以及我收到的相应错误消息:
发电机输出
...
while True:
it1 = gen1.next()
it2 = gen2.next()
it3 = gen3.next()
it4 = gen4.next()
# If generator is used for training and validating
if to_predict == False:
yield [it1[0], it2[0], it3[0]], [it1[1], it2[1], it3[1], it4[1]] #Yield both images and their mutual label
网络
...
model = keras.Model(inputs=[Input1, Input2, Input3], outputs=[Output1, Output2])
OPTIMIZER = keras.optimizers.Adam(HP_lr)
### Compile
model.compile(loss = {'out1': Loss1(),
'out2': Loss2()},
loss_weights={'out1': 1,
'out2': 1},
metrics = {'out1': Loss1(),
'out2': Loss1()},
optimizer=OPTIMIZER
)
调谐器
...
atuner.search(train_generator, ...)
错误信息
ValueError: The two structures don't have the same sequence length. Input structure has length 4, while shallow structure has length 2.