-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_conv_ctc.py
30 lines (26 loc) · 1.13 KB
/
utils_conv_ctc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def conv_output_length(input_length, filter_size, padding, stride,
dilation=1):
''' Compute the length of the output sequence after 1D convolution along
time.
Params:
input_length (int): Length of the input sequence.
filter_size (int): Width of the convolution kernel.
padding (str): Only support `SAME` or `VALID`.
stride (int): Stride size used in 1D convolution.
dilation (int)
'''
if input_length is None:
return None
assert padding in {'SAME', 'VALID'}
dilated_filter_size = filter_size + (filter_size - 1) * (dilation - 1)
if padding == 'SAME':
output_length = input_length
elif padding == 'VALID':
output_length = input_length - dilated_filter_size + 1
return (output_length + stride - 1) // stride
# Convolution Layer
#layer_1 = tf.contrib.layers.convolution2d(inputs=inputs, num_outputs=num_hidden,
#kernel_size=[5], stride=1, padding='VALID',
#normalizer_fn=tf.contrib.layers.batch_norm,
#normalizer_params={'is_training': True})
#output_lengths = conv_output_length(seq_len, 5, 'VALID', 1)