Python Keras-连接两个相同的第1维和第3维输入,但不同的第2维输入
我正在创建一个函数式API keras模型,以回归和预测基于两个混合数据输入的数值 该网络由两个模型组成,其输出拟串联并输入到另一个模型中,该模型将输出最终值与预测值进行比较 我的(未完成的)代码如下所示:Python Keras-连接两个相同的第1维和第3维输入,但不同的第2维输入,python,tensorflow,keras,Python,Tensorflow,Keras,我正在创建一个函数式API keras模型,以回归和预测基于两个混合数据输入的数值 该网络由两个模型组成,其输出拟串联并输入到另一个模型中,该模型将输出最终值与预测值进行比较 我的(未完成的)代码如下所示: def categorical_model(): inputA = Input(shape=(3, 1329, )) x = Dense(8, activation='relu')(inputA) x = Dense(4, activation='relu')(x)
def categorical_model():
inputA = Input(shape=(3, 1329, ))
x = Dense(8, activation='relu')(inputA)
x = Dense(4, activation='relu')(x)
return Model(inputs=inputA, outputs=x)
def continuous_model():
inputB = Input(shape=(1329, 2))
y = Dense(64, activation="relu")(inputB)
y = Dense(32, activation="relu")(y)
y = Dense(4, activation="relu")(y)
return Model(inputs=inputB, outputs=y)
cat = categorical_model()
con = continuous_model()
catcon_list = [cat.output, con.output]
concatenated = concatenate(catcon_list, axis=0, name = 'concatenate')
concatenated = Dense(2, activation='softmax')(concatenated)
merged = Model(input=[cat.input,
con.input],
output=concatenated)
merged.summary()
该代码会导致ValueError
,如下所示:
ValueError: A `Concatenate` layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 3, 4), (None, 1329, 4)]
这些输入可以连接起来吗?如何将轴更改为第二个维度?这应该可以:
concatenated = Concatenate(axis=1)(catcon_list)
merged = Model([cat.input,
con.input],
concatenated)
数据的形状是什么?A=(31329,),B=(1329,)@MarcoCerliani您能在(1329,3,)中转置A吗?此代码导致类型错误:
TypeError:('Keyword argument not understanding:','input')
第102行merged=Model(input=[cat.input,
还有一个错误:您使用“input”而不是“inputs”调用模型-请参见我的编辑