Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing tf.Keras (Keras v2.x) #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

import ctc
import logging
import keras.backend as K
from tensorflow.python import keras
import tensorflow.python.keras.backend as K

from keras.layers import (BatchNormalization, Convolution1D, Dense,
from tensorflow.python.keras.layers import (BatchNormalization, Conv1D, Dense,
Input, GRU, TimeDistributed)
from keras.models import Model
from tensorflow.python.keras.models import Model
# from keras.optimizers import SGD
import lasagne

Expand Down Expand Up @@ -103,29 +104,31 @@ def compile_gru_model(input_dim=161, output_dim=29, recur_layers=3, nodes=1024,
acoustic_input = Input(shape=(None, input_dim), name='acoustic_input')

# Setup the network
conv_1d = Convolution1D(nodes, conv_context, name='conv1d',
border_mode=conv_border_mode,
subsample_length=conv_stride, init=initialization,
activation='relu')(acoustic_input)
conv_1d = Conv1D(filters=nodes, kernel_size=conv_context, name='conv1d',
padding=conv_border_mode,
strides=conv_stride,
kerne_initializer=initialization,
activation='relu')(acoustic_input)
if batch_norm:
output = BatchNormalization(name='bn_conv_1d', mode=2)(conv_1d)
output = BatchNormalization(name='bn_conv_1d')(conv_1d)
else:
output = conv_1d

for r in range(recur_layers):
output = GRU(nodes, activation='relu',
name='rnn_{}'.format(r + 1), init=initialization,
return_sequences=True)(output)
output = GRU(units=nodes, activation='relu',
name='rnn_{}'.format(r + 1),
kernel_initializer=initialization,
return_sequences=True)(output)
if batch_norm:
bn_layer = BatchNormalization(name='bn_rnn_{}'.format(r + 1),
mode=2)
bn_layer = BatchNormalization(name='bn_rnn_{}'.format(r + 1))
output = bn_layer(output)

# We don't softmax here because CTC does that
network_output = TimeDistributed(Dense(
output_dim, name='dense', activation='linear', init=initialization,
units=output_dim, name='dense', activation='linear',
kernel_initializer=initialization,
))(output)
model = Model(input=acoustic_input, output=network_output)
model = Model(inputs=acoustic_input, outputs=network_output)
model.conv_output_length = lambda x: conv_output_length(
x, conv_context, conv_border_mode, conv_stride)
return model