我一直试图了解我在哪里收到此错误,并在堆栈溢出时浏览了此处的表单。似乎无法修复它。 TensorFlow 2.3 我正在尝试构建一个多输入 LSTM 模型
输入数据:
print(plot_data)
tensor_stack = tf.stack([plot_data,plot_data2])
print(tensor_stack)
tf.Tensor(
[[39.0991 39.09879 39.09845 ... 0. 0. 0. ]
[39.09889 39.09914 39.09887 ... 0. 0. 0. ]
[39.09889 39.09847 39.09858 ... 0. 0. 0. ]
[39.09889 39.09886 39.0989 ... 39.09906 39.09923 39.09919]], shape=(4, 484), dtype=float64)
tf.Tensor(
[[[ 39.0991 39.09879 39.09845 ... 0. 0. 0. ]
[ 39.09889 39.09914 39.09887 ... 0. 0. 0. ]
[ 39.09889 39.09847 39.09858 ... 0. 0. 0. ]
[ 39.09889 39.09886 39.0989 ... 39.09906 39.09923 39.09919]]
[[-77.57008 -77.5702 -77.57081 ... 0. 0. 0. ]
[-77.57014 -77.56999 -77.57015 ... 0. 0. 0. ]
[-77.57012 -77.5699 -77.57022 ... 0. 0. 0. ]
[-77.57033 -77.56998 -77.56963 ... -77.5701 -77.56991 -77.56992]]], shape=(2, 4, 484), dtype=float64)
这是我的模型:
import tensorflow as tf
from tensorflow.keras.layers import *
from tensorflow.keras.models import Sequential, Model
from tensorflow.keras.optimizers import Adam, RMSprop
import numpy as np
#from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from tensorflow import keras
from tensorflow.keras import layers
input1 = Input(shape=(plot_data.shape[0],plot_data.shape[1],))
input2 = Input(shape=(plot_data2.shape[0],plot_data.shape[1], ))
input = Concatenate()([input1, input2])
x = Dense(2)(input)
x = Dense(1)(x)
model = Model(inputs=[input1, input2], outputs=x)
model.summary()
print(input.shape[1])
print(input.shape[2])
maxlen = 484
#x_train = keras.preprocessing.sequence.pad_sequences(plot_data)
#x_train = x_train.reshape(-1, input.shape[1], input.shape[2])
# design network
model = Sequential()
model.add(LSTM(2, input_shape=( tensor_stack.shape[1],tensor_stack.shape[2]), return_sequences=True))
model.add(Dense(1))
model.compile(optimizer='adam',loss='mae', metrics=['mae'])
# fit network
history = model.fit(tensor_stack, epochs=50, batch_size=72, verbose=1, shuffle=False)