tensorflow - LSTM 参数修改
问题描述
我正在研究 LSTM 代码并试图使我的模型准确。我一直在尝试更改参数*以及 epoch 数和批量大小,但都是徒劳的。可能,我做错了!有什么帮助吗?请与我分享任何可能有用的教程或指南。谢谢
*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: 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()
我希望这有帮助。
推荐阅读
- python - 使用并发和 boost::python 回调
- python - 将数据从 25hz 下采样到 10hz
- sql - Netezza 代码转换以减号结尾的数据,而不是以减号开头
- javascript - 将 HTML 编码为有效的 JSON
- python - Celery - 我应该为 Windows 繁重的 cpu 进程和 redis 后端使用什么池来进行状态跟踪?
- linux - 在 Linux 中静默安装 PowerShell 模块 /quiet
- python - Seaborn 如何在 catplot 或 pointplot 中使用关键字参数
- python-3.x - 无法访问 API
- javascript - 如何为创建的每个随机生成的对象创建随机 X 和 Y 旋转(三个 JS)
- python - 在两个 numpy 数组中乘以“交叉”