Skip to content

Instantly share code, notes, and snippets.

@csaguiar
Last active February 14, 2020 00:45
Show Gist options
  • Select an option

  • Save csaguiar/1f4b37c2827a0cfd4dd0db8c59541371 to your computer and use it in GitHub Desktop.

Select an option

Save csaguiar/1f4b37c2827a0cfd4dd0db8c59541371 to your computer and use it in GitHub Desktop.
sequence_size = X_train.shape[1]
n_features = 1
n_subsequences = 4
subsequence_size = int(sequence_size / n_subsequences)
# Reshaping to be (samples, subsequences, sequence, feature)
X_train = X_train.reshape(-1, n_subsequences, subsequence_size, n_features)
X_val = X_val.reshape(-1, n_subsequences, subsequence_size, n_features)
cnn_lstm_model = Sequential([
TimeDistributed(
Conv1D(
filters=8,
kernel_size=4,
strides=1,
padding="same",
activation="relu"
),
input_shape=(n_subsequences, subsequence_size, n_features)
),
TimeDistributed(Flatten()),
LSTM(
units=1,
input_shape=(sequence_size, n_features)
),
Dense(
1,
activation="sigmoid",
name="output",
)
])
optimizer = Adam(lr=0.001)
# Compiling the model
cnn_lstm_model.compile(
optimizer=optimizer,
loss="binary_crossentropy",
metrics=["accuracy"]
)
cnn_lstm_model.summary()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment