假设我们有一个包含整数的 Numpy 数组 .
arr = [1, 2, 3]
我们有一个Keras模型 .
model.add(LSTM(128, input_shape=(arr)))
如何正确指定输入形状?
LSTM层的输入数据需要是三维的,形状为 (num_samples, timesteps, num_features) .
(num_samples, timesteps, num_features)
您为LSTM图层指定的 input_shape 的形状为 (timesteps, num_features) . input_shape 并不关心样本数量,只关心每个样本的形状 .
input_shape
(timesteps, num_features)
如果我们假设 timesteps=1 ,你会想要做这样的事情 .
timesteps=1
arr = np.array([1, 2, 3]) arr.shape # (3,) arr = arr.reshape(arr.shape[0], 1, 1) arr.shape # (3, 1, 1) model.add(LSTM(128, input_shape=(arr.shape[1], arr.shape[2])))
将LSTM与 timesteps=1 一起使用并没有多大意义,但希望你能得到这个想法 .
1 回答
LSTM层的输入数据需要是三维的,形状为
(num_samples, timesteps, num_features)
.您为LSTM图层指定的
input_shape
的形状为(timesteps, num_features)
.input_shape
并不关心样本数量,只关心每个样本的形状 .如果我们假设
timesteps=1
,你会想要做这样的事情 .将LSTM与
timesteps=1
一起使用并没有多大意义,但希望你能得到这个想法 .