Skip to content

Instantly share code, notes, and snippets.

@Jsevillamol
Created October 28, 2018 13:46
Show Gist options
  • Save Jsevillamol/d0c5018bee158de4f514c6f6edd21978 to your computer and use it in GitHub Desktop.
Save Jsevillamol/d0c5018bee158de4f514c6f6edd21978 to your computer and use it in GitHub Desktop.
CNN RNN model with masking in Keras
# Create model
model = Sequential()
input_shape = (n_tel, img_w, img_h, n_channels)
# mask the inputs that correspond to padding
model.add(Masking(mask_value=0., input_shape=input_shape))
# Add CNN feature extractor
model.add(TimeDistributed(
Conv2D(
filters=16,
kernel_size=(3,3),
padding='same',
activation='relu'
)))
model.add(TimeDistributed(
Conv2D(
filters=32,
kernel_size=(3,3),
padding='same',
activation='relu'
)
))
model.add(TimeDistributed(MaxPooling2D(pool_size=(2,2), strides=None)))
model.add(Flatten())
# Add LSTM feature combinator
model.add(LSTM(units=100))
# Add FCN classifier
model.add(Dense(units=100, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment