简体   繁体   English

ValueError:检查输入时出错:预期lstm_1_input具有形状(973,215),但数组的形状为(61,215)

[英]ValueError: Error when checking input: expected lstm_1_input to have shape (973, 215) but got array with shape (61, 215)

I have received multiple diffrent ValueErrors when trying to solve following by changing many parameters. 尝试通过更改许多参数来解决以下问题时,我收到多个不同的ValueErrors

It is a time series problem , I have data from 60 shops, 215 items, 1034 days. 这是一个time series problem ,我有60个商店,215个项目,1034天的数据。 I have splitted 973 days for train and 61 for test.: 我将973天的火车时间和61天的测试时间分开:

train_x = train_x.reshape((60, 973, 215))
test_x = test_x.reshape((60, 61, 215))
train_y = train_y.reshape((60, 973, 215))
test_y = test_y.reshape((60, 61, 215))

My model : 我的模特

model = Sequential()
model.add(LSTM(100, input_shape=(train_x.shape[1], train_x.shape[2]), 
return_sequences='true'))
model.add(Dense(215))
model.compile(loss='mean_squared_error', optimizer='adam', metrics= 
['accuracy'])
history = model.fit(train_x, train_y, epochs=10,
                validation_data=(test_x, test_y), verbose=2, shuffle=False)

ValueError: Error when checking input: expected lstm_1_input to have shape (973, 215) but got array with shape (61, 215) ValueError:检查输入时出错:预期lstm_1_input具有形状(973,215),但数组的形状为(61,215)

You've split your data with respect to timesteps as opposed to the samples. 您已按照时间步长(而不是样本)拆分了数据。 You need to decide on what are your samples in the first instance. 您首先需要确定样本是什么。 For the sake of the answer I will assume these are along the first axis (assuming the data has been framed as a supervised time-series problem). 为了回答这个问题,我将假设它们沿着第一个轴(假设数据已被构造为有监督的时间序列问题)。

The input_size in LSTM expects the shape of (timesteps, data_dim) as explained here , and these dimensions must remain the same for each batch. 所述input_size在LSTM期望的形状(timesteps, data_dim)作为解释这里 ,这些尺寸必须保持相同每批。 In your example, samples from training and testing have different dimensions. 在您的示例中,来自训练和测试的样本具有不同的维度。 The batch size can differ (unless specified with batch_size parameter). 批处理大小可以不同(除非使用batch_size参数指定)。

Your data should be split between training and testing along the first axis. 您的数据应沿第一个轴在训练和测试之间划分。 Here is an analogous example from Keras tutorials: 这是Keras教程中的一个类似示例:

from keras.models import Sequential
from keras.layers import LSTM, Dense
import numpy as np

data_dim = 16
timesteps = 8
num_classes = 10

# expected input data shape: (batch_size, timesteps, data_dim)
model = Sequential()
model.add(LSTM(32, return_sequences=True,
               input_shape=(timesteps, data_dim)))  # returns a sequence of vectors of dimension 32
model.add(LSTM(32, return_sequences=True))  # returns a sequence of vectors of dimension 32
model.add(LSTM(32))  # return a single vector of dimension 32
model.add(Dense(10, activation='softmax'))

model.compile(loss='categorical_crossentropy',
              optimizer='rmsprop',
              metrics=['accuracy'])

# Generate dummy training data
x_train = np.random.random((1000, timesteps, data_dim))
y_train = np.random.random((1000, num_classes))

# Generate dummy validation data
x_val = np.random.random((100, timesteps, data_dim))
y_val = np.random.random((100, num_classes))

model.fit(x_train, y_train,
          batch_size=64, epochs=5,
          validation_data=(x_val, y_val))

You will notice that timesteps is the same for training and testing data and x_train.shape[1] == x_val.shape[1] . 您会注意到,对于训练和测试数据和x_train.shape[1] == x_val.shape[1]timesteps是相同的。 It is the number of samples that differs along the first axis x_train.shape[0] is 1000 and x_val.shape[0] is 100 . 它是沿第一轴不同的样本数x_train.shape[0]1000x_val.shape[0]100

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:检查输入时出错:预期lstm_1_input具有3个维,但数组的形状为(393613,50) - ValueError: Error when checking input: expected lstm_1_input to have 3 dimensions, but got array with shape (393613, 50) ValueError:检查输入时出错:预期lstm_1_input具有3个维,但数组的形状为(10,1) - ValueError: Error when checking input: expected lstm_1_input to have 3 dimensions, but got array with shape (10, 1) 检查输入时出错:预期 lstm_1_input 有 3 个维度,但得到形状为 (5, 3) 的数组 - Error when checking input: expected lstm_1_input to have 3 dimensions, but got array with shape (5, 3) 检查模型输入时发生错误:预期lstm_1_input具有3维,但数组的形状为(339732,29) - Error when checking model input: expected lstm_1_input to have 3 dimensions, but got array with shape (339732, 29) 检查输入时出错:预期 lstm_1_input 的形状为 (71, 768) 但得到的数组形状为 (72, 768) - Error when checking input: expected lstm_1_input to have shape (71, 768) but got array with shape (72, 768) 检查输入时出错:预期 lstm_1_input 具有 3 个维度,但仅在 epoch>1 和特定数据集拆分时获得形状为 (0, 1) 的数组 - Error when checking input: expected lstm_1_input to have 3 dimensions, but got array with shape (0, 1) only on epoch>1 and at a specific dataset split ValueError:检查输入时出错:预期 lstm_11_input 具有形状 (1, 1) 但得到形状为 (1, 3841) 的数组 - ValueError: Error when checking input: expected lstm_11_input to have shape (1, 1) but got array with shape (1, 3841) ValueError:检查输入时出错:预期 lstm_6_input 具有形状 (87482, 1) 但得到的数组具有形状 (87482, 3) - ValueError: Error when checking input: expected lstm_6_input to have shape (87482, 1) but got array with shape (87482, 3) ValueError:检查输入时出错:预期 lstm_12_input 具有形状 (5793993, 7) 但得到形状为 (7, 1) 的数组 - ValueError: Error when checking input: expected lstm_12_input to have shape (5793993, 7) but got array with shape (7, 1) 预期 lstm_1_input 有 3 个维度,但得到了形状为 (0, 1) 的数组 - expected lstm_1_input to have 3 dimensions, but got array with shape (0, 1)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM