值错误:输入 0 与层序列 7 不兼容:预期形状=(无,无,1),发现形状=(无,1,7)

时间:2021-02-14 03:39:04

标签: keras lstm

from tensorflow.keras import models
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dropout, Dense, SimpleRNN
from tensorflow.keras.layers import LSTM
import matplotlib.pyplot as plt

# parameter
learning_rate = 0.01
training_cnt = 100
batch_size = 200
input_size = train_x.shape[1]

time_step = 1

# model structure
model = Sequential()
model.add(LSTM(512,input_shape=(1,input_size))) 
model.add(Dropout(0.2)) 
model.add(Dense(1,activation='tanh')) 

model.compile(loss='mse',optimizer='rmsprop',metrics=['mae','mape'])
model.summary()

# Training -> get error
history = model.fit(train_x,train_y,epochs=training_cnt, batch_size=batch_size, verbose=1)
val_mse, val_mae, val_mape = model.evaluate(test_x, test_y, verbose=0)

-> 得到错误 ValueError: Input 0 is incompatible with layer序列_7: 预期形状=(None, None, 1), found shape=(None, 1, 7)

0 个答案:

没有答案