我对加速的原因感到困惑。训练和预测速度方面的收益都是巨大的,超过50倍。
这是我创建LSTM模型的方式:
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
这就是我创建CNN-LSTM模型的方式:
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
但是,当我查看可训练参数的数量时,CNN-LSTM似乎比经典LSTM拥有更多的参数。有人知道原因吗?谢谢您的帮助,谢谢。
答案 0 :(得分:1)
在cnn中更深入的初学者外观