Our model is a simple sequential model, defined using Keras layers:
model = tf.keras.Sequential([
tf.keras.layers.Masking(mask_value=0.),
tf.keras.layers.LSTM(512, dropout=0.5, recurrent_dropout=0.5),
tf.keras.layers.Dense(256, activation='relu'),
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(len(LABELS), activation='softmax')
])
We apply a dropout, a concept introduced in Chapter 3, Modern Neural Networks. The dropout parameter of the LSTM controls how much dropout is applied to the input weight matrix. The recurrent_dropout parameter controls how much dropout is applied to the previous state. Similar to a mask, recurrent_dropout randomly ignores part of the previous state activations in order to avoid overfitting.
The very first layer of our model is a Masking layer. As we padded our image sequences with empty frames in order to batch them, our LSTM cell would needlessly iterate over those added frames. Adding the Masking layer...