Created
January 10, 2022 17:17
-
-
Save starovoitovs/c47336a526c619fd13d54df5776d4ede to your computer and use it in GitHub Desktop.
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
import numpy as np | |
from sklearn.model_selection import train_test_split | |
from keras import Model | |
from keras.layers import Input, LSTM, Conv1D, Conv2D, Reshape, Dense, BatchNormalization, Dropout, concatenate | |
from keras.callbacks import ModelCheckpoint | |
from sklearn.preprocessing import OneHotEncoder | |
from sklearn.metrics import accuracy_score, precision_recall_fscore_support | |
def build_model(window_size, n_features, depth): | |
input_layer1 = Input(shape=(window_size, depth * 4, 1)) | |
input_layer2 = Input(shape=(window_size, n_features)) | |
x = Conv2D(16, kernel_size=(1, 2), strides=(1, 2), activation='relu')(input_layer1) | |
x = Conv2D(16, kernel_size=(4, 1), activation='relu', padding='same')(x) | |
x = Conv2D(16, kernel_size=(4, 1), activation='relu', padding='same')(x) | |
x = Conv2D(16, kernel_size=(1, 2), strides=(1, 2), activation='relu')(x) | |
x = Conv2D(16, kernel_size=(4, 1), activation='relu', padding='same')(x) | |
x = Conv2D(16, kernel_size=(4, 1), activation='relu', padding='same')(x) | |
x = Conv2D(16, kernel_size=(1, depth), activation='relu')(x) | |
x = Conv2D(16, kernel_size=(4, 1), activation='relu', padding='same')(x) | |
x = Conv2D(16, kernel_size=(4, 1), activation='relu', padding='same')(x) | |
x = Reshape((window_size, 16))(x) | |
x = concatenate([x, input_layer2]) | |
lstm_layer = LSTM(64)(x) | |
bn_layer = BatchNormalization()(lstm_layer) | |
dropout_layer = Dropout(0.8)(bn_layer) | |
output_layer = Dense(3, activation='softmax')(dropout_layer) | |
model = Model([input_layer1, input_layer2], output_layer) | |
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy']) | |
return model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment