简体   繁体   English

ValueError: 层 model_2 需要 2 个输入,但它接收到 1 个输入张量

[英]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.

相关问题 ValueError:层顺序需要 1 个输入,但它在 tensorflow 2.0 中收到 211 个输入张量 - ValueError: Layer sequential expects 1 inputs, but it received 211 input tensors in tensorflow 2.0 ValueError:层顺序_1 需要 1 个输入,但它收到 2 个输入张量 - ValueError: Layer sequential_1 expects 1 input(s), but it received 2 input tensors ValueError:创建预训练模型的集合时,模型的输出张量必须是Keras Layer的输出 - ValueError: Output tensors to a Model must be the output of a Keras `Layer` when creating ensemble of pre-trained model ValueError:当使用自定义回调绘制卷积层特征图时,函数模型的输出张量必须是 TensorFlow `Layer` 的输出 - ValueError: Output tensors of a Functional model must be the output of a TensorFlow `Layer` when using custom callback to plot conv layer feature maps “ValueError:……与图层不兼容:输入形状的预期轴 -1 的值为 8,但接收到的输入形状为(无、7、169)” - “ValueError: …incompatible with the layer: expected axis -1 of input shape to have value 8 but received input with shape (None, 7, 169)” ValueError: 层序号_6 的输入 0 与层不兼容:预期 ndim=4,发现 ndim=3。 收到的完整形状:[32、28、28] - ValueError: Input 0 of layer sequential_6 is incompatible with the layer: expected ndim=4, found ndim=3. Full shape received: [32, 28, 28] ValueError: 层 simple_rnn_1 的输入 0 与层不兼容:预期 ndim=3,发现 ndim=2。 收到的完整形状:[无,50] - ValueError: Input 0 of layer simple_rnn_1 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: [None, 50] ValueError:输入 0 层 bidirectional_1 与层不兼容:预期 ndim=3,发现 ndim=2。 收到的完整形状:(13、64) - ValueError: Input 0 of layer bidirectional_1 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (13, 64) TensorFlow ValueError: Input 0 is in compatible with layer model_1: expected shape=(None, 32, 32, 1), found shape=(1, 1, 32, 32) - TensorFlow ValueError: Input 0 is incompatible with layer model_1: expected shape=(None, 32, 32, 1), found shape=(1, 1, 32, 32) ValueError:将字典输入传递给没有 FeatureLayer 作为第一层的顺序模型是一个错误 - ValueError: Passing a dictionary input to a Sequential Model which doesn't have FeatureLayer as the first layer is an error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM