Python Tensorflow InvalidargumeInterror:ConcatOp:输入的尺寸应匹配:形状[0]=[32,64]与形状[1]=[1,1]
有人能帮我处理这个错误消息吗?我不明白为什么维度会失败。我想我必须将数据保存到tf结构中,但我不知道如何保存。它在Python Tensorflow InvalidargumeInterror:ConcatOp:输入的尺寸应匹配:形状[0]=[32,64]与形状[1]=[1,1],python,tensorflow,Python,Tensorflow,有人能帮我处理这个错误消息吗?我不明白为什么维度会失败。我想我必须将数据保存到tf结构中,但我不知道如何保存。它在model.fit行失败 InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [32,64] vs. shape[1] = [1,1] [[node functional_15/tf_op_layer_concat_1/concat_1 (defined at <
model.fit
行失败
InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [32,64] vs. shape[1] = [1,1]
[[node functional_15/tf_op_layer_concat_1/concat_1 (defined at <ipython-input-111-a47d0926c8a7>:28) ]] [Op:__inference_train_function_1236905]
我正在调用列车功能,就是这个:
我通过这个输入和标签数组调用它:
有帮助,有帮助。
Model: "functional_1"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_2 (InputLayer) [(None, 10, 1)] 0
__________________________________________________________________________________________________
lstm (LSTM) (None, 64) 16896 input_2[0][0]
__________________________________________________________________________________________________
input_1 (InputLayer) [(None, 1)] 0
__________________________________________________________________________________________________
concatenate (Concatenate) (None, 65) 0 lstm[0][0]
input_1[0][0]
==================================================================================================
Total params: 16,896
Trainable params: 16,896
Non-trainable params: 0
__________________________________________________________________________________________________
None
Model: "functional_3"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_4 (InputLayer) [(None, 10, 1)] 0
__________________________________________________________________________________________________
lstm_1 (LSTM) (None, 64) 16896 input_4[0][0]
__________________________________________________________________________________________________
input_3 (InputLayer) [(None, 1)] 0
__________________________________________________________________________________________________
concatenate_1 (Concatenate) (None, 65) 0 lstm_1[0][0]
input_3[0][0]
==================================================================================================
Total params: 16,896
Trainable params: 16,896
Non-trainable params: 0
__________________________________________________________________________________________________
None
Model: "functional_5"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_6 (InputLayer) [(None, 10, 1)] 0
__________________________________________________________________________________________________
lstm_2 (LSTM) (None, 64) 16896 input_6[0][0]
__________________________________________________________________________________________________
input_5 (InputLayer) [(None, 1)] 0
__________________________________________________________________________________________________
concatenate_2 (Concatenate) (None, 65) 0 lstm_2[0][0]
input_5[0][0]
==================================================================================================
Total params: 16,896
Trainable params: 16,896
Non-trainable params: 0
__________________________________________________________________________________________________
None
Model: "functional_7"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_8 (InputLayer) [(None, 10, 1)] 0
__________________________________________________________________________________________________
lstm_3 (LSTM) (None, 64) 16896 input_8[0][0]
__________________________________________________________________________________________________
input_7 (InputLayer) [(None, 1)] 0
__________________________________________________________________________________________________
concatenate_3 (Concatenate) (None, 65) 0 lstm_3[0][0]
input_7[0][0]
==================================================================================================
Total params: 16,896
Trainable params: 16,896
Non-trainable params: 0
__________________________________________________________________________________________________
None
Model: "functional_9"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_10 (InputLayer) [(None, 10, 1)] 0
__________________________________________________________________________________________________
lstm_4 (LSTM) (None, 64) 16896 input_10[0][0]
__________________________________________________________________________________________________
input_9 (InputLayer) [(None, 1)] 0
__________________________________________________________________________________________________
concatenate_4 (Concatenate) (None, 65) 0 lstm_4[0][0]
input_9[0][0]
==================================================================================================
Total params: 16,896
Trainable params: 16,896
Non-trainable params: 0
__________________________________________________________________________________________________
None
Model: "functional_11"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_12 (InputLayer) [(None, 10, 1)] 0
__________________________________________________________________________________________________
lstm_5 (LSTM) (None, 64) 16896 input_12[0][0]
__________________________________________________________________________________________________
input_11 (InputLayer) [(None, 1)] 0
__________________________________________________________________________________________________
concatenate_5 (Concatenate) (None, 65) 0 lstm_5[0][0]
input_11[0][0]
==================================================================================================
Total params: 16,896
Trainable params: 16,896
Non-trainable params: 0
__________________________________________________________________________________________________
None
Model: "functional_13"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_14 (InputLayer) [(None, 10, 1)] 0
__________________________________________________________________________________________________
lstm_6 (LSTM) (None, 64) 16896 input_14[0][0]
__________________________________________________________________________________________________
input_13 (InputLayer) [(None, 1)] 0
__________________________________________________________________________________________________
concatenate_6 (Concatenate) (None, 65) 0 lstm_6[0][0]
input_13[0][0]
==================================================================================================
Total params: 16,896
Trainable params: 16,896
Non-trainable params: 0
__________________________________________________________________________________________________
None
model shape: (None, 10, 1)
output 2: Tensor("concat:0", shape=(1, 65), dtype=float32)
model shape: (None, 10, 1)
output 2: Tensor("concat_1:0", shape=(1, 65), dtype=float32)
model shape: (None, 10, 1)
output 2: Tensor("concat_2:0", shape=(1, 65), dtype=float32)
model shape: (None, 10, 1)
output 2: Tensor("concat_3:0", shape=(1, 65), dtype=float32)
model shape: (None, 10, 1)
output 2: Tensor("concat_4:0", shape=(1, 65), dtype=float32)
model shape: (None, 10, 1)
output 2: Tensor("concat_5:0", shape=(1, 65), dtype=float32)
model shape: (None, 10, 1)
output 2: Tensor("concat_6:0", shape=(1, 65), dtype=float32)
output penul: Tensor("dense/Relu:0", shape=(1, 30), dtype=float32)
output: Tensor("dense_1/BiasAdd:0", shape=(1, 1), dtype=float32)
Modelo completo
Model: "functional_15"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
Input1 (InputLayer) [(None, 10, 7)] 0
__________________________________________________________________________________________________
tf_op_layer_strided_slice (Tens [(None, 10, 1)] 0 Input1[0][0]
__________________________________________________________________________________________________
tf_op_layer_strided_slice_1 (Te [(None, 10, 1)] 0 Input1[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm/Shape_1 (Tenso [(3,)] 0 tf_op_layer_strided_slice[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm_1/Shape_1 (Ten [(3,)] 0 tf_op_layer_strided_slice_1[0][0]
__________________________________________________________________________________________________
tf_op_layer_strided_slice_2 (Te [(None, 10, 1)] 0 Input1[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm/strided_slice_ [()] 0 tf_op_layer_lstm/Shape_1[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm_1/strided_slic [()] 0 tf_op_layer_lstm_1/Shape_1[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm_2/Shape_1 (Ten [(3,)] 0 tf_op_layer_strided_slice_2[0][0]
__________________________________________________________________________________________________
tf_op_layer_strided_slice_3 (Te [(None, 10, 1)] 0 Input1[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm/zeros_2/packed [(2,)] 0 tf_op_layer_lstm/strided_slice_1[
__________________________________________________________________________________________________
tf_op_layer_lstm/zeros_3/packed [(2,)] 0 tf_op_layer_lstm/strided_slice_1[
__________________________________________________________________________________________________
tf_op_layer_lstm_1/zeros_2/pack [(2,)] 0 tf_op_layer_lstm_1/strided_slice_
__________________________________________________________________________________________________
tf_op_layer_lstm_1/zeros_3/pack [(2,)] 0 tf_op_layer_lstm_1/strided_slice_
__________________________________________________________________________________________________
tf_op_layer_lstm_2/strided_slic [()] 0 tf_op_layer_lstm_2/Shape_1[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm_3/Shape_1 (Ten [(3,)] 0 tf_op_layer_strided_slice_3[0][0]
__________________________________________________________________________________________________
tf_op_layer_strided_slice_4 (Te [(None, 10, 1)] 0 Input1[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm/zeros_2 (Tenso [(None, 64)] 0 tf_op_layer_lstm/zeros_2/packed[0
__________________________________________________________________________________________________
tf_op_layer_lstm/zeros_3 (Tenso [(None, 64)] 0 tf_op_layer_lstm/zeros_3/packed[0
__________________________________________________________________________________________________
tf_op_layer_lstm_1/zeros_2 (Ten [(None, 64)] 0 tf_op_layer_lstm_1/zeros_2/packed
__________________________________________________________________________________________________
tf_op_layer_lstm_1/zeros_3 (Ten [(None, 64)] 0 tf_op_layer_lstm_1/zeros_3/packed
__________________________________________________________________________________________________
tf_op_layer_lstm_2/zeros_2/pack [(2,)] 0 tf_op_layer_lstm_2/strided_slice_
__________________________________________________________________________________________________
tf_op_layer_lstm_2/zeros_3/pack [(2,)] 0 tf_op_layer_lstm_2/strided_slice_
__________________________________________________________________________________________________
tf_op_layer_lstm_3/strided_slic [()] 0 tf_op_layer_lstm_3/Shape_1[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm_4/Shape_1 (Ten [(3,)] 0 tf_op_layer_strided_slice_4[0][0]
__________________________________________________________________________________________________
tf_op_layer_strided_slice_5 (Te [(None, 10, 1)] 0 Input1[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm/PartitionedCal [(None, 64), (None, 0 tf_op_layer_strided_slice[0][0]
tf_op_layer_lstm/zeros_2[0][0]
tf_op_layer_lstm/zeros_3[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm_1/PartitionedC [(None, 64), (None, 0 tf_op_layer_strided_slice_1[0][0]
tf_op_layer_lstm_1/zeros_2[0][0]
tf_op_layer_lstm_1/zeros_3[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm_2/zeros_2 (Ten [(None, 64)] 0 tf_op_layer_lstm_2/zeros_2/packed
__________________________________________________________________________________________________
tf_op_layer_lstm_2/zeros_3 (Ten [(None, 64)] 0 tf_op_layer_lstm_2/zeros_3/packed
__________________________________________________________________________________________________
tf_op_layer_lstm_3/zeros_2/pack [(2,)] 0 tf_op_layer_lstm_3/strided_slice_
__________________________________________________________________________________________________
tf_op_layer_lstm_3/zeros_3/pack [(2,)] 0 tf_op_layer_lstm_3/strided_slice_
__________________________________________________________________________________________________
tf_op_layer_lstm_4/strided_slic [()] 0 tf_op_layer_lstm_4/Shape_1[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm_5/Shape_1 (Ten [(3,)] 0 tf_op_layer_strided_slice_5[0][0]
__________________________________________________________________________________________________
tf_op_layer_strided_slice_6 (Te [(None, 10, 1)] 0 Input1[0][0]
__________________________________________________________________________________________________
tf_op_layer_concat (TensorFlowO [(1, 65)] 0 tf_op_layer_lstm/PartitionedCall_
__________________________________________________________________________________________________
tf_op_layer_concat_1 (TensorFlo [(1, 65)] 0 tf_op_layer_lstm_1/PartitionedCal
__________________________________________________________________________________________________
tf_op_layer_lstm_2/PartitionedC [(None, 64), (None, 0 tf_op_layer_strided_slice_2[0][0]
tf_op_layer_lstm_2/zeros_2[0][0]
tf_op_layer_lstm_2/zeros_3[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm_3/zeros_2 (Ten [(None, 64)] 0 tf_op_layer_lstm_3/zeros_2/packed
__________________________________________________________________________________________________
tf_op_layer_lstm_3/zeros_3 (Ten [(None, 64)] 0 tf_op_layer_lstm_3/zeros_3/packed
__________________________________________________________________________________________________
tf_op_layer_lstm_4/zeros_2/pack [(2,)] 0 tf_op_layer_lstm_4/strided_slice_
__________________________________________________________________________________________________
tf_op_layer_lstm_4/zeros_3/pack [(2,)] 0 tf_op_layer_lstm_4/strided_slice_
__________________________________________________________________________________________________
tf_op_layer_lstm_5/strided_slic [()] 0 tf_op_layer_lstm_5/Shape_1[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm_6/Shape_1 (Ten [(3,)] 0 tf_op_layer_strided_slice_6[0][0]
__________________________________________________________________________________________________
add (Add) (1, 65) 0 tf_op_layer_concat[0][0]
tf_op_layer_concat_1[0][0]
add[6][0]
tf_op_layer_concat_2[0][0]
add[7][0]
tf_op_layer_concat_3[0][0]
add[8][0]
tf_op_layer_concat_4[0][0]
add[9][0]
tf_op_layer_concat_5[0][0]
add[10][0]
tf_op_layer_concat_6[0][0]
__________________________________________________________________________________________________
tf_op_layer_concat_2 (TensorFlo [(1, 65)] 0 tf_op_layer_lstm_2/PartitionedCal
__________________________________________________________________________________________________
tf_op_layer_lstm_3/PartitionedC [(None, 64), (None, 0 tf_op_layer_strided_slice_3[0][0]
tf_op_layer_lstm_3/zeros_2[0][0]
tf_op_layer_lstm_3/zeros_3[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm_4/zeros_2 (Ten [(None, 64)] 0 tf_op_layer_lstm_4/zeros_2/packed
__________________________________________________________________________________________________
tf_op_layer_lstm_4/zeros_3 (Ten [(None, 64)] 0 tf_op_layer_lstm_4/zeros_3/packed
__________________________________________________________________________________________________
tf_op_layer_lstm_5/zeros_2/pack [(2,)] 0 tf_op_layer_lstm_5/strided_slice_
__________________________________________________________________________________________________
tf_op_layer_lstm_5/zeros_3/pack [(2,)] 0 tf_op_layer_lstm_5/strided_slice_
__________________________________________________________________________________________________
tf_op_layer_lstm_6/strided_slic [()] 0 tf_op_layer_lstm_6/Shape_1[0][0]
__________________________________________________________________________________________________
tf_op_layer_concat_3 (TensorFlo [(1, 65)] 0 tf_op_layer_lstm_3/PartitionedCal
__________________________________________________________________________________________________
tf_op_layer_lstm_4/PartitionedC [(None, 64), (None, 0 tf_op_layer_strided_slice_4[0][0]
tf_op_layer_lstm_4/zeros_2[0][0]
tf_op_layer_lstm_4/zeros_3[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm_5/zeros_2 (Ten [(None, 64)] 0 tf_op_layer_lstm_5/zeros_2/packed
__________________________________________________________________________________________________
tf_op_layer_lstm_5/zeros_3 (Ten [(None, 64)] 0 tf_op_layer_lstm_5/zeros_3/packed
__________________________________________________________________________________________________
tf_op_layer_lstm_6/zeros_2/pack [(2,)] 0 tf_op_layer_lstm_6/strided_slice_
__________________________________________________________________________________________________
tf_op_layer_lstm_6/zeros_3/pack [(2,)] 0 tf_op_layer_lstm_6/strided_slice_
__________________________________________________________________________________________________
tf_op_layer_concat_4 (TensorFlo [(1, 65)] 0 tf_op_layer_lstm_4/PartitionedCal
__________________________________________________________________________________________________
tf_op_layer_lstm_5/PartitionedC [(None, 64), (None, 0 tf_op_layer_strided_slice_5[0][0]
tf_op_layer_lstm_5/zeros_2[0][0]
tf_op_layer_lstm_5/zeros_3[0][0]
__________________________________________________________________________________________________
tf_op_layer_lstm_6/zeros_2 (Ten [(None, 64)] 0 tf_op_layer_lstm_6/zeros_2/packed
__________________________________________________________________________________________________
tf_op_layer_lstm_6/zeros_3 (Ten [(None, 64)] 0 tf_op_layer_lstm_6/zeros_3/packed
__________________________________________________________________________________________________
tf_op_layer_concat_5 (TensorFlo [(1, 65)] 0 tf_op_layer_lstm_5/PartitionedCal
__________________________________________________________________________________________________
tf_op_layer_lstm_6/PartitionedC [(None, 64), (None, 0 tf_op_layer_strided_slice_6[0][0]
tf_op_layer_lstm_6/zeros_2[0][0]
tf_op_layer_lstm_6/zeros_3[0][0]
__________________________________________________________________________________________________
tf_op_layer_concat_6 (TensorFlo [(1, 65)] 0 tf_op_layer_lstm_6/PartitionedCal
__________________________________________________________________________________________________
dense (Dense) (1, 30) 1980 add[11][0]
__________________________________________________________________________________________________
dense_1 (Dense) (1, 1) 31 dense[0][0]
==================================================================================================
Total params: 2,011
Trainable params: 2,011
Non-trainable params: 0
__________________________________________________________________________________________________
None
MAX_EPOCHS = 10
def compile_and_fit_varios(model, window_dic, patience=2):
early_stopping = tf.keras.callbacks.EarlyStopping(monitor='val_loss',
patience=patience,
mode='min')
model.compile(loss=tf.losses.MeanSquaredError(), optimizer=tf.optimizers.Adam(),
metrics=[tf.metrics.MeanAbsoluteError(), tf.keras.metrics.MeanAbsolutePercentageError(), tf.keras.metrics.MeanSquaredLogarithmicError(), tf.keras.metrics.MeanSquaredError(),coeff_determination])
history = model.fit(
x=dataset_X_prueba[0],
y=dataset_Y_prueba[0],
epochs=MAX_EPOCHS)
return history
dataset_X_prueba[0].shape
>> (32, 10, 7, 1)
dataset_Y_prueba[0].shape
>> (32, 10, 7, 1)