这就是问题,在使用自定义子模型构建的模型中,我可以成功构建和训练它,但是当我尝试使用该模型进行预测时,就会显示此错误:
ValueError:预期的批次大小与模型输出的批次大小不匹配。输出形状=(3,1),预期输出形状=形状(1,1)
模型输出应为(1,1),并且(3,1)的输出形状与模型中的3个子模型有关(我可以确认,调试后结论)。这些部分相互平行,详细信息如下。
这是model.summary()信息:
xdeepfm model summary:
Model: "xDeepFM"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_13 (InputLayer) [(None, 30)] 0
__________________________________________________________________________________________________
input_14 (InputLayer) [(None, 10028)] 0
__________________________________________________________________________________________________
input_15 (InputLayer) [(None, 4584)] 0
__________________________________________________________________________________________________
input_16 (InputLayer) [(None, 213)] 0
__________________________________________________________________________________________________
input_17 (InputLayer) [(None, 2281)] 0
__________________________________________________________________________________________________
input_18 (InputLayer) [(None, 55)] 0
__________________________________________________________________________________________________
Embedding_model (Model) (None, 600) 1719700 input_13[0][0]
input_14[0][0]
input_15[0][0]
input_16[0][0]
input_17[0][0]
input_18[0][0]
__________________________________________________________________________________________________
tf_op_layer_Reshape_1 (TensorFl [(1, None)] 0 Embedding_model[1][0]
__________________________________________________________________________________________________
tf_op_layer_Reshape (TensorFlow [(1, None)] 0 Embedding_model[1][0]
__________________________________________________________________________________________________
tf_op_layer_Reshape_2 (TensorFl [(1, 6, 100)] 0 Embedding_model[1][0]
__________________________________________________________________________________________________
DNN2 (Model) multiple 2885401 tf_op_layer_Reshape_1[0][0]
__________________________________________________________________________________________________
DNN1 (Model) multiple 241001 tf_op_layer_Reshape[0][0]
__________________________________________________________________________________________________
CIN (Model) (1, 1) 3000601 tf_op_layer_Reshape_2[0][0]
__________________________________________________________________________________________________
Combination_model (Model) multiple 2 DNN2[1][0]
DNN1[1][0]
CIN[1][0]
==================================================================================================
Total params: 7,846,705
Trainable params: 7,846,705
Non-trainable params: 0
__________________________________________________________________________________________________
有趣的是,CIN子模型由具有摘要输出形状的自定义图层组成,而使用tf api的2 DNN子模型则具有明显的输出形状。
所有3个并行子模型共享相同的输入,并且它们的所有输出形状应为(1,1)。
顺便说一句,当我使用sub-model.summary()检查子模型的结构时,输出形状没有问题。
我假设可以训练我的模型但无法预测模型的输出形状是“多个”的原因,但是如果我错了,请告诉我。