Last active
January 3, 2019 20:36
-
-
Save DiegoAgher/055c4d8b67db4bc00e5f65de598b5a2f to your computer and use it in GitHub Desktop.
conv + lstm model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def build_Model(num_classes, seq_lenght, input_shape=(28, 252, 1)): | |
inputs = Input(name='x', shape=input_shape, dtype='float32') | |
conv1 = Conv2D(seq_lenght, (3, 3), padding='same', name='conv1', kernel_initializer='he_normal')(inputs) | |
conv1 = Activation('relu')(conv1) | |
conv1 = MaxPooling2D(pool_size=(2, 2), name='max1')(conv1) | |
dims = conv1.get_shape() | |
reshape = Reshape(target_shape=(seq_lenght, int(dims[1]*dims[2])), name='reshape')(conv1) | |
reshape = Dense(128, activation='relu', kernel_initializer='he_normal', name='dense2')(reshape) | |
lstm_1 = LSTM(32, return_sequences=True, kernel_initializer='he_normal', name='lstm1')(reshape) | |
lstm_2 = LSTM(32, return_sequences=True, kernel_initializer='he_normal', name='lstm2')(lstm_1) | |
y_pred = Dense(num_classes, activation='softmax', | |
kernel_initializer='he_normal',name='output')(lstm_2) | |
model = Model(inputs=inputs, outputs=y_pred) | |
model.compile(Adam(lr=0.001), 'categorical_crossentropy', metrics=['accuracy']) | |
return model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment