[英]Why CNN-LSTM is faster than LSTM?
I was confused about the reason for speed up.我对加速的原因感到困惑。 The gain in both training and prediction speed is huge, more than 50 times.
训练和预测速度的提升是巨大的,超过 50 倍。
This is how I create my LSTM model:这就是我创建 LSTM model 的方式:
def create_model(learning_rate, num_LSTM_layers,
num_LSTM_nodes, dropout_rate):
#CREATE THE LSTM NEURAL NETWORK
model = Sequential()
if num_LSTM_layers > 1:
model.add(LSTM(num_LSTM_nodes, return_sequences=True ))
if num_LSTM_layers == 1:
model.add(LSTM(num_LSTM_nodes, return_sequences=False))
model.add(Activation('relu'))
model.add(Dropout(dropout_rate))
if num_LSTM_layers > 1:
for i in range(num_LSTM_layers-1):
if i+1 == num_LSTM_layers-1:
model.add(layers.LSTM(num_LSTM_nodes, return_sequences=False))
else:
model.add(layers.LSTM(num_LSTM_nodes, return_sequences=True))
model.add(Activation('relu'))
model.add(Dropout(dropout_rate))
model.add(Dense(1))
model.add(Activation('linear'))
# Use the Adam method for training the network.
# We want to find the best learning-rate for the Adam method.
optimizer = Adam(lr=learning_rate)
# In Keras we need to compile the model so it can be trained.
model.compile(loss='mean_squared_error', optimizer=optimizer)
return model
and this is how I create my CNN-LSTM model:这就是我创建 CNN-LSTM model 的方式:
def create_model_TD(learning_rate, num_conv_layers, num_LSTM_layers,
num_LSTM_nodes, dropout_rate, filter_size, kernel_height, pool_size):
#CREATE THE LSTM NEURAL NETWORK
model = Sequential()
model.add(TimeDistributed(Conv1D(input_shape=(None, X_train.shape[2], X_train.shape[3]) ,
filters= int(filter_size), kernel_size= int(kernel_height), activation='relu', padding='causal')))
if num_conv_layers == 2:
model.add(TimeDistributed(Conv1D(filters=int(filter_size), kernel_size= int(kernel_height), activation='relu', padding='causal')))
model.add(TimeDistributed(MaxPooling1D(pool_size=int(pool_size))))
model.add(TimeDistributed(Flatten()))
if num_LSTM_layers > 1:
model.add(LSTM(num_LSTM_nodes, return_sequences=True))
if num_LSTM_layers == 1:
model.add(LSTM(num_LSTM_nodes, return_sequences=False))
model.add(Activation('relu'))
model.add(Dropout(dropout_rate))
if num_LSTM_layers > 1:
for i in range(num_LSTM_layers-1):
if i+1 == num_LSTM_layers-1:
model.add(LSTM(num_LSTM_nodes, return_sequences=False))
else:
model.add(LSTM(num_LSTM_nodes, return_sequences=True))
model.add(Activation('relu'))
model.add(Dropout(dropout_rate))
model.add(Dense(1))
model.add(Activation('linear'))
# Use the Adam method for training the network.
# We want to find the best learning-rate for the Adam method.
optimizer = Adam(lr=learning_rate)
# In Keras we need to compile the model so it can be trained.
model.compile(loss='mean_squared_error', optimizer=optimizer)
return model
But when I look at the number of trainable parameters, CNN-LSTM seems to have even more parameters than classic LSTM.但是当我查看可训练参数的数量时,CNN-LSTM 的参数似乎比经典 LSTM 还要多。 Anyone knows the reason?
有人知道原因吗? I would appreciate your help, thanks.
我会很感激你的帮助,谢谢。
CNN leads to a variety of different complexity reductions by concentrating on the key features. CNN 通过专注于关键特征来降低各种不同的复杂性。 The use of convolution layers leads to a reduction in the size of tensors.
卷积层的使用导致张量的大小减小。 Also the use of pooling leads to a further reduction.
此外,池化的使用导致进一步减少。 And last but not least the ReLu layer reduces the complexity.
最后但并非最不重要的一点是,ReLu 层降低了复杂性。 Because of the training time decrease
因为训练时间减少
Deeper beginner look in cnn在 cnn 中更深入的初学者看
https://www.semanticscholar.org/paper/Introduction-to-Convolutional-Neural-Networks-Wu/450ca19932fcef1ca6d0442cbf52fec38fb9d1e5 https://www.semanticscholar.org/paper/Introduction-to-Convolutional-Neural-Networks-Wu/450ca19932fcef1ca6d0442cbf52fec38fb9d1e5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.