Python Keras中的连接层

Python Keras中的连接层,python,tensorflow,keras,Python,Tensorflow,Keras,我试图接受2个输入到我的模型中。但它有一个奇怪的问题 x1= layers.Input((20000,)) x2= layers.Reshape((200,100), input_shape=(20000,))(x1) y1= layers.Input((200000,)) y2= layers.Reshape((2000,100), input_shape=(200000,))(y1) combine = layers.Concatenate(axis=1)([x2, y2]) model

我试图接受2个输入到我的模型中。但它有一个奇怪的问题

x1= layers.Input((20000,))
x2= layers.Reshape((200,100), input_shape=(20000,))(x1)

y1= layers.Input((200000,))
y2= layers.Reshape((2000,100), input_shape=(200000,))(y1)

combine = layers.Concatenate(axis=1)([x2, y2])
model = tf.keras.Model(inputs=[x1, y1], outputs=combine)
model.predict([datasetA, datasetB])
如果我接受一个输入,模型就可以运行

model = tf.keras.Model(inputs=[x1], output=x2)
model.predict(datasetA)
但是如果我接受两个输入,模型就死了

Failed to find data adapter that can handle input: (<class 'list'> containing values of types {"<class 'tensorflow.python.data.ops.dataset_ops.PrefetchDataset'>"}), <class 'NoneType'>

您是否使用
tensoflow.keras
导入图层? 您还可以打印
型号摘要

唯一可能存在问题的是通过模型的形状

此代码工作正常。 tensorflow==2.0.0

import tensorflow as tf
import numpy as np

datasetA = np.zeros((10,20000),dtype=int)
datasetB = np.zeros((10,200000),dtype=int)

x1= tf.keras.layers.Input((20000,))
x2= tf.keras.layers.Reshape((200,100), input_shape=(20000,))(x1)

y1= tf.keras.layers.Input((200000,))
y2= tf.keras.layers.Reshape((2000,100), input_shape=(200000,))(y1)

combine = tf.keras.layers.Concatenate(axis=1)([x2, y2])
model = tf.keras.Model(inputs=[x1, y1], outputs=combine)
model.summary()
model.predict([datasetA, datasetB])
print('the predict done')], outputs=combine)

你能制作一个生成的数据集,这样我们就可以复制/粘贴你的代码并重现错误吗?使用一个numpy从张量切片中得到的tf数据集array@h4nk我传递了一个带有您定义的形状的NumPy zeros数组,该数组工作正常。@h4nk您上面提到的示例将文本和标签放在一起,就像在这个方法中一样
vectorize_text
可能您将其用作“数据集”,而“数据集”同时包含文本和标签
model.summary()
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_3 (InputLayer)            [(None, 20000)]      0                                            
__________________________________________________________________________________________________
input_4 (InputLayer)            [(None, 200000)]     0                                            
__________________________________________________________________________________________________
reshape_2 (Reshape)             (None, 200, 100)     0           input_3[0][0]                    
__________________________________________________________________________________________________
reshape_3 (Reshape)             (None, 2000, 100)    0           input_4[0][0]                    
__________________________________________________________________________________________________
concatenate_1 (Concatenate)     (None, 2200, 100)    0           reshape_2[0][0]                  
                                                                 reshape_3[0][0]                  
import tensorflow as tf
import numpy as np

datasetA = np.zeros((10,20000),dtype=int)
datasetB = np.zeros((10,200000),dtype=int)

x1= tf.keras.layers.Input((20000,))
x2= tf.keras.layers.Reshape((200,100), input_shape=(20000,))(x1)

y1= tf.keras.layers.Input((200000,))
y2= tf.keras.layers.Reshape((2000,100), input_shape=(200000,))(y1)

combine = tf.keras.layers.Concatenate(axis=1)([x2, y2])
model = tf.keras.Model(inputs=[x1, y1], outputs=combine)
model.summary()
model.predict([datasetA, datasetB])
print('the predict done')], outputs=combine)