python - 当为多个输入调用 model.fit 函数时,会引发基数问题
问题描述
def build_model():
#input1 = Input(shape=(50,), dtype=tf.int32, name='x1')
inputs = keras.Input(shape=(150,150,3))
input2=keras.Input(shape = (248064,))
x = layers.Conv2D(16, 3, activation="relu")(inputs)
x = layers.Conv2D(32, 3, activation="relu")(x)
x = layers.MaxPooling2D(3)(x)
x = layers.Conv2D(32, 3, activation="relu")(x)
flat=layers.Flatten()(x)
print("Flat Shape:",flat.shape)
print("Type of flat",type(flat))
print("feature vector Shape:",input2.shape)
print("Type of input2",type(flat))
concatenatedFeatures = tf.concat([flat, input2],-1)
#concatenatedFeatures=np.append(flat,input2,axis=1)
print("Type of concatfeature",type(concatenatedFeatures))
print("concatenatedFeatures Shape:",concatenatedFeatures.shape)
dense = Dense(128)(concatenatedFeatures)
print("dense Shape:",dense.shape)
#y = layers.Dense(4)(dense)
y = layers.Dense(4,activation='softmax')(dense)
print("y Shape:",y.shape)
return (Model(inputs=[inputs,input2], outputs=y))
model = build_model()
model.summary()
model.compile(loss='categorical_crossentropy', optimizer='adam')
histrory=model.fit([x_train,File_data],y_train)
它遇到了一个model.fit()
错误
ValueError: Data cardinality is ambiguous:
x sizes: 20, 248064
y sizes: 20
Make sure all arrays contain the same number of samples.
我试图将 flatten 层的输出与来自 file_data 的额外功能连接起来......输入的形状如下:
Flat Shape: (None, 67712)
feature vector Shape: (None, 248064)
concatenatedFeatures Shape: (None, 315776)
解决方案
推荐阅读
- c++ - QSerialPort readyRead() 信号无法正常工作
- javascript - 仅与 Socket.io 中的房间进行私人聊天对话
- arangodb - 如何在 ArangoDB 中创建边缘集合?
- c++ - 连接 RadioStream 和 MP3 解码器
- wordpress - 尝试自定义主题时出现致命错误?
- ios - 在 Swift 中过滤具有属性和 Map 的自定义对象数组
- arrays - 如何使用 JAVA 按列比较数组中的元素
- javascript - 无法在“文档”上执行“写入”[MailChimp 存档嵌入]
- arrays - 如何解析json动态数组名
- cuda - CUDA中不同内核之间的设备变量