text
stringlengths 0
4.99k
|
---|
# Expand the dimension to use 2D CNN.
|
x = layers.Reshape((-1, input_dim, 1), name=\"expand_dim\")(input_spectrogram)
|
# Convolution layer 1
|
x = layers.Conv2D(
|
filters=32,
|
kernel_size=[11, 41],
|
strides=[2, 2],
|
padding=\"same\",
|
use_bias=False,
|
name=\"conv_1\",
|
)(x)
|
x = layers.BatchNormalization(name=\"conv_1_bn\")(x)
|
x = layers.ReLU(name=\"conv_1_relu\")(x)
|
# Convolution layer 2
|
x = layers.Conv2D(
|
filters=32,
|
kernel_size=[11, 21],
|
strides=[1, 2],
|
padding=\"same\",
|
use_bias=False,
|
name=\"conv_2\",
|
)(x)
|
x = layers.BatchNormalization(name=\"conv_2_bn\")(x)
|
x = layers.ReLU(name=\"conv_2_relu\")(x)
|
# Reshape the resulted volume to feed the RNNs layers
|
x = layers.Reshape((-1, x.shape[-2] * x.shape[-1]))(x)
|
# RNN layers
|
for i in range(1, rnn_layers + 1):
|
recurrent = layers.GRU(
|
units=rnn_units,
|
activation=\"tanh\",
|
recurrent_activation=\"sigmoid\",
|
use_bias=True,
|
return_sequences=True,
|
reset_after=True,
|
name=f\"gru_{i}\",
|
)
|
x = layers.Bidirectional(
|
recurrent, name=f\"bidirectional_{i}\", merge_mode=\"concat\"
|
)(x)
|
if i < rnn_layers:
|
x = layers.Dropout(rate=0.5)(x)
|
# Dense layer
|
x = layers.Dense(units=rnn_units * 2, name=\"dense_1\")(x)
|
x = layers.ReLU(name=\"dense_1_relu\")(x)
|
x = layers.Dropout(rate=0.5)(x)
|
# Classification layer
|
output = layers.Dense(units=output_dim + 1, activation=\"softmax\")(x)
|
# Model
|
model = keras.Model(input_spectrogram, output, name=\"DeepSpeech_2\")
|
# Optimizer
|
opt = keras.optimizers.Adam(learning_rate=1e-4)
|
# Compile the model and return
|
model.compile(optimizer=opt, loss=CTCLoss)
|
return model
|
# Get the model
|
model = build_model(
|
input_dim=fft_length // 2 + 1,
|
output_dim=char_to_num.vocabulary_size(),
|
rnn_units=512,
|
)
|
model.summary(line_length=110)
|
Model: \"DeepSpeech_2\"
|
______________________________________________________________________________________________________________
|
Layer (type) Output Shape Param #
|
==============================================================================================================
|
input (InputLayer) [(None, None, 193)] 0
|
______________________________________________________________________________________________________________
|
expand_dim (Reshape) (None, None, 193, 1) 0
|
______________________________________________________________________________________________________________
|
conv_1 (Conv2D) (None, None, 97, 32) 14432
|
______________________________________________________________________________________________________________
|
conv_1_bn (BatchNormalization) (None, None, 97, 32) 128
|
______________________________________________________________________________________________________________
|
conv_1_relu (ReLU) (None, None, 97, 32) 0
|
______________________________________________________________________________________________________________
|
conv_2 (Conv2D) (None, None, 49, 32) 236544
|
______________________________________________________________________________________________________________
|
conv_2_bn (BatchNormalization) (None, None, 49, 32) 128
|
______________________________________________________________________________________________________________
|
conv_2_relu (ReLU) (None, None, 49, 32) 0
|
______________________________________________________________________________________________________________
|
reshape (Reshape) (None, None, 1568) 0
|
______________________________________________________________________________________________________________
|
bidirectional_1 (Bidirectional) (None, None, 1024) 6395904
|
______________________________________________________________________________________________________________
|
dropout (Dropout) (None, None, 1024) 0
|
______________________________________________________________________________________________________________
|
bidirectional_2 (Bidirectional) (None, None, 1024) 4724736
|
______________________________________________________________________________________________________________
|
dropout_1 (Dropout) (None, None, 1024) 0
|
______________________________________________________________________________________________________________
|
bidirectional_3 (Bidirectional) (None, None, 1024) 4724736
|
______________________________________________________________________________________________________________
|
dropout_2 (Dropout) (None, None, 1024) 0
|
______________________________________________________________________________________________________________
|
bidirectional_4 (Bidirectional) (None, None, 1024) 4724736
|
______________________________________________________________________________________________________________
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.