Created
January 6, 2021 09:33
-
-
Save suhaskv/69b928f044aa215309709abb201c629a to your computer and use it in GitHub Desktop.
VSB Power Line Blog - DNN implementation
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 model_lstm(input_shape, feat_shape): | |
""" | |
Builds the Neural Network Architecture. | |
Following is the architecture that is built: | |
* Layer 1 | |
* LSTM | |
* Bidirectional LSTM - 128 neurons | |
* Bidirectional LSTM - 64 neurons | |
* Attention layer | |
* Layer 2 | |
* Dense - 64, activation: relu | |
* Layer 3 | |
* Output: Dense - 1, activation: sigmoid | |
* Loss - binary cross-entropy | |
* Optimizer - adam | |
* Metric - matthews correlation coefficient | |
""" | |
inp = Input(shape=(input_shape[1], input_shape[2],)) | |
feat = Input(shape=(feat_shape[1],)) | |
bi_lstm_1 = Bidirectional(LSTM(128, return_sequences=True), merge_mode='concat')(inp) | |
bi_lstm_2 = Bidirectional(GRU(64, return_sequences=True), merge_mode='concat')(bi_lstm_1) | |
attention = Attention()(bi_lstm_2) | |
x = concatenate([attention, feat], axis=1) | |
x = Dense(64, activation='relu')(x) | |
x = Dense(1, activation='sigmoid')(x) | |
model = Model(inputs=[inp, feat], outputs=x) | |
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=[matthews_correlation]) | |
return model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment