模型拟合:使用另一个模型的中间层作为Keras的输入

时间:2020-07-03 03:24:05

标签: python tensorflow keras

我查找了线程,但似乎没人能解决我遇到的相同问题。

enter image description here

我正在尝试重建Bi-CNN的模型,并且为了调试目的,我正在创建3个单独的模型。我为图片中突出显示的model_cross做的是:

cross = something like tf.transpose(tf.matmul(left_intermediate, right_intermediate))`
cross_input = Input(shape=cross[1:])
cross_output = GlobalMaxPooling2D()(cross_input)
cross_model = Model(inputs=cross_input, outputs=cross_output)
cross_model.summary()

然后我将左,叉和右模型的输出串联起来:

combined = Concatenate(aixs=1)([left_output, cross_ouput, right_output])
combined_output = Dense(1, activation='softmax')(combined)
model = Model(inputs=[left_input, right_input, cross_input], outputs=combined_output)

这一切都很好,但是当我这样做时:

model.compile(...)
model.fit(x=[left, right, cross], y=labels)

我得到了错误:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

cross的输出为:

Tensor("Transpose_2:0", shape=(None, 6, 5, 20), dtype=float32)

我想知道哪里出了问题,快速解决方案是什么? 我可以通过以下方法解决问题:

cross = something like tf.transpose(tf.matmul(left_intermediate, right_intermediate))`
# cross_input = Input(shape=cross[1:])
cross_output = GlobalMaxPooling2D()(cross)

但是我想让cross_model输出其摘要,因此我认为我需要一个Input

谢谢。

0 个答案:

没有答案
相关问题