我正在处理LSTM代码,试图提高模型的准确性。我尝试更改参数*、epochs数量和batch大小,但都没有效果。可能是我做错了!有什么建议吗?请分享任何有帮助的教程或指南。谢谢
*LSTM参数
tf.keras.layers.LSTM( units, activation='tanh', recurrent_activation='sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0, implementation=2, return_sequences=False, return_state=False, go_backwards=False, stateful=False, time_major=False, unroll=False, **kwargs)
回答:
每个人在理解和使用循环神经网络时可能都会遇到困难。然而,它们实际上并不像看起来那么难。
要从头开始理解循环神经网络和LSTM,我认为最好的博客是Colah博客。
你还可以查看这篇文章,它总结了RNN的概念。
Keras博客中的这个教程可能对实现RNN有帮助。
最后,要理解LSTM层,可以将其视为一个简单的Dense层,其中units
是层的大小。
这些层的特别之处在于它们的工作方式,这就是其他参数的作用所在。这里我只列出我用过的参数。
units: 层的大小Activation: 应用于层输出的激活函数use_bias: 布尔值,决定是否使用偏置向量return_sequences: 布尔值,如果你有Many to One RNN,设为False;如果是Many to Many RNN,设为True
编辑:这是我为图像分类构建的一个宪法循环神经网络的代码。希望这是你要找的。
model = Sequential() model.add(Input(shape=(IMG_HEIGHT, IMG_WIDTH, 3))) model.add(Reshape(target_shape=(IMG_HEIGHT, IMG_WIDTH * 3))) model.add(Conv1D(filters=64, kernel_size=3, padding="same", activation='relu', input_shape=(IMG_HEIGHT, IMG_WIDTH * 3), data_format='channels_last')) model.add(Conv1D(filters=64, kernel_size=3, padding="same", activation='relu')) model.add(MaxPooling1D(pool_size=3)) model.add(Conv1D(filters=128, kernel_size=3, padding="same", activation='relu')) model.add(Conv1D(filters=128, kernel_size=3, padding="same", activation='relu')) model.add(LSTM(64, activation='relu')) model.add(BatchNormalization()) model.add(Flatten()) model.add(Dense(4, activation='softmax')) model.build(input_shape=(batch_size, IMG_HEIGHT, IMG_WIDTH, 3)) model.summary()
希望这对你有帮助。