[英]ValueError: Layer model_2 expects 2 inputs, but it received 1 input tensors
I have this model I built and it is throwing the error in the title at model3.add(graph)
.我有我构建的这个 model,它在
model3.add(graph)
的标题中抛出错误。 From what I have read and understood, the second model which is model3
here expects two inputs at model3.add(graph)
but it is only received one.根据我的阅读和理解,第二个 model 在这里是
model3
预计在model3.add(graph)
有两个输入,但它只收到一个。 Why does it need 2 inputs?为什么需要2个输入? Am I overlooking something?
我忽略了什么吗? Please help?
请帮忙?
inputs3 = model.inputs[:2] # We are getting all layers EXCEPT last 2 layers
layer_output3 = model.get_layer('Encoder-12-FeedForward-Norm')).output #this is a layer from a pretrained BERT model
removed_layer = RemoveMask()(layer_output3) #the previous layer contains masks which are not compatible with a CNN layer in Keras
conv_blocks = []
filter_sizes = (2,3,4)
for fx in filter_sizes:
conv_layer = Conv1D(100, kernel_size=fx,
activation= 'softsign'), data_format='channels_first')(removed_layer)
maxpool_layer = MaxPooling1D(pool_size=2)(conv_layer)
flat_layer = Flatten()(maxpool_layer)
conv_blocks.append(flat_layer)
conc_layer = concatenate(conv_blocks, axis=1)
restored_layer = RestoreMask()([conc_layer, layer_output3])
graph = Model(input=inputs3, outputs=restored_layer)
model3 = Sequential()
model3.add(graph)
model3.add(Dropout(0.1))
model3.add(Dense(3, activation='softmax'))
model3.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model3.summary()
You are combining a Functional Model(graph) with Sequential Model(model3).您正在将功能模型(图)与顺序模型(模型 3)相结合。 Either convert both the model to be Functional Model(like graph) OR convert both the model to be Sequential Model(like model3).
要么将 model 都转换为功能模型(如图所示),要么将 model 都转换为顺序模型(如模型 3)。
You can find solution for converting Functional model to Sequential Model and vice versa here .您可以在此处找到将功能 model 转换为顺序 Model 的解决方案,反之亦然。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.