【发布时间】:2022-01-08 19:46:22
【问题描述】:
我是深度学习的新手,我对术语完全感到困惑。
在 TensorFlow 文档中,
对于[RNN层]https://www.tensorflow.org/api_docs/python/tf/keras/layers/RNN#input_shape
N-D tensor with shape [batch_size, timesteps, ...]
对于 [LSTM 层] https://www.tensorflow.org/api_docs/python/tf/keras/layers/LSTM
inputs: A 3D tensor with shape [batch, timesteps, feature].
-
我了解 input_shape,我们不必指定批次/批次大小。 但我仍然想知道批量和批量大小之间的区别。
-
什么是时间步长与特征?
第一个维度总是批次吗?第 2 维 = 时间步长,第 3 维 = 特征?
示例 1
data = array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
data = data.reshape((1, 5, 2))
print(data.shape) --> (1, 5, 2)
print(data)
[[[ 1 2]
[ 3 4]
[ 5 6]
[ 7 8]
[ 9 10]]]
model = Sequential()
model.add(LSTM(32, input_shape=(5, 2)))
示例 2
data1 = array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11])
n_features = 1
data1 = data1.reshape((len(data1), n_features))
print(data1)
# define generator
n_input = 2
generator = TimeseriesGenerator(data1, data1, length=n_input, stride=2, batch_size=10)
# number of batch
print('Batches: %d' % len(generator))
# OUT --> Batches: 1
# print each batch
for i in range(len(generator)):
x, y = generator[i]
print('%s => %s' % (x, y))
x, y = generator[0]
print(x.shape)
[[[ 1]
[ 2]]
[[ 3]
[ 4]]
[[ 5]
[ 6]]
[[ 7]
[ 8]]
[[ 9]
[10]]] => [[ 3]
[ 5]
[ 7]
[ 9]
[11]]
(5, 2, 1)
# define model
model = Sequential()
model.add(LSTM(100, activation='relu', input_shape=(n_input, n_features)))
【问题讨论】:
标签: tensorflow keras lstm