ValueError:检查输入时出错:预期input_1具有3维,但数组的形状为(45,5)

时间:2020-07-06 18:48:40

标签: python tensorflow machine-learning keras valueerror

我正在尝试使用x_train =(45,5)运行模型,当我进入model.fit行时,它向我显示此错误:

ValueError:检查输入时出错:预期input_1具有3个维度,但数组的形状为(45,5)

当我将尺寸增加到(45,5,1)时,出现错误:

ValueError:检查输入时出错:预期input_3具有形状(45,5),但数组具有形状(5,1)

我不明白自己要怎么做,这是我的模型(展开后):

history_points = 50 

past_ohlcv = np.array(data[0 : history_points])
past_ohlcv = np.expand_dims(past_ohlcv, -1) #Dimensions (50, 5, 1)

nextday_high = np.array(data[0 : history_points][:,1])
nextday_high = np.expand_dims(nextday_high, -1) #Dimensions (50, 1)


test_split = 0.9
n = int(past_ohlcv.shape[0] * test_split)

ohlcv_train = past_ohlcv[:n] #Dimensions (45, 5, 1)

ohlcv_test = past_ohlcv[n:] #Dimensions (5, 5, 1)

y_train = nextday_high[:n] #Dimensions (45, 1)
y_test = nextday_high[n:] #Dimensions (5, 1)

nextday_high_test = nextday_high[n:] #Dimensions (5, 1)

inputs = Input(shape=(int(history_points * 0.9), 5))
x = LSTM(50)(inputs)
x = Dropout(0.2)(x)
x = Dense(64)(x)
x = Activation('sigmoid')(x)
x = Dense(1)(x)
outputs = Activation('linear')(x)

model = Model(inputs=inputs, outputs=outputs)

adam = optimizers.Adam(lr=0.0005)

model.compile(optimizer=adam, loss='mse')

model.fit(x=ohlcv_train, y=y_train, batch_size=32, epochs=5, shuffle=True, validation_split=0.1)

PS:我知道当第二次出现“值错误”时,输入已从input_1更改为input_3,但是我很确定它仍在引用相同的输入。我不知道为什么输入数字会更改,但是每次我在同一控制台中再次运行代码时,输​​入数字都会增加(该数字由input_11决定)。

0 个答案:

没有答案