Created
May 29, 2020 07:53
-
-
Save AdroitAnandAI/fc45306aeb9349a85df6c780d054f8f2 to your computer and use it in GitHub Desktop.
deepRnnCnn.py
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 final_model(input_dim, filters, kernel_size, conv_stride, | |
conv_border_mode, units, recur_layers, output_dim=29): | |
""" Build a deep network for speech | |
""" | |
# Main acoustic input | |
input_data = Input(name='the_input', shape=(None, input_dim)) | |
# TODO: Specify the layers in your network | |
# Add convolutional layer | |
conv_1d = Conv1D(filters, kernel_size, | |
strides=conv_stride, | |
padding=conv_border_mode, | |
activation='relu', | |
name='conv1d')(input_data) | |
pooled_1d = MaxPooling1D(pool_size=2, strides=1)(conv_1d) | |
# Add batch normalization | |
bn_cnn = BatchNormalization(name='bn_conv_1d')(pooled_1d) | |
prev_layer = bn_cnn | |
for layer in range(recur_layers): | |
prev_layer = Bidirectional(GRU(units, activation='relu', | |
return_sequences=True, implementation=2, name=f'gru_{layer+1}'))(prev_layer) | |
# TODO: Add batch normalization | |
prev_layer = BatchNormalization()(prev_layer) | |
# TODO: Add a TimeDistributed(Dense(output_dim)) layer | |
time_dense = TimeDistributed(Dense(output_dim))(prev_layer) | |
# TODO: Add softmax activation layer | |
y_pred = Activation('softmax', name='softmax')(time_dense) | |
# Specify the model | |
model = Model(inputs=input_data, outputs=y_pred) | |
# TODO: Specify model.output_length | |
model.output_length = lambda x: cnn_output_length( | |
x, kernel_size, conv_border_mode, conv_stride)/2 | |
print(model.summary()) | |
return model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment