LSTM 参数修改
LSTM Arguments modifications
我正在研究 LSTM 代码并努力使我的模型准确。我一直在尝试更改参数 * 以及时期数和批量大小,但没有成功。可能,我做错了!
有什么帮助吗?请与我分享任何可能有用的教程或指南。谢谢
*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 博客。
您还可以看到这个 article 总结了 RNN 的概念。
keras 博客中的这个 tutorial 可能对实现 RNN 有用。
最后,要理解 LSTM 层,请将它们视为简单的密集层,层的大小为 units
。
这些层的特别之处在于它们的工作方式,这是其他争论的来源。这里只说我用过的。
units: Size of the layer
Activation: Activation function to apply on the output of the layer
use_bias: Boolean, decides if to use a vector for bias or not
return_sequences: Boolean, if you have Many to One RNN set it to False, If Many to Many RNN set it to 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()
希望对您有所帮助。
我正在研究 LSTM 代码并努力使我的模型准确。我一直在尝试更改参数 * 以及时期数和批量大小,但没有成功。可能,我做错了! 有什么帮助吗?请与我分享任何可能有用的教程或指南。谢谢
*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 博客。
您还可以看到这个 article 总结了 RNN 的概念。
keras 博客中的这个 tutorial 可能对实现 RNN 有用。
最后,要理解 LSTM 层,请将它们视为简单的密集层,层的大小为 units
。
这些层的特别之处在于它们的工作方式,这是其他争论的来源。这里只说我用过的。
units: Size of the layer
Activation: Activation function to apply on the output of the layer
use_bias: Boolean, decides if to use a vector for bias or not
return_sequences: Boolean, if you have Many to One RNN set it to False, If Many to Many RNN set it to 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()
希望对您有所帮助。