Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d35d01b1
提交
d35d01b1
authored
7月 05, 2017
作者:
João Victor Tozatti Risso
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reuse testcases in both CPU and GPU tests of CTC
Signed-off-by:
João Victor Tozatti Risso
<
joaovictor.risso@gmail.com
>
上级
b4f54eae
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
77 行增加
和
106 行删除
+77
-106
test_ctc.py
theano/gpuarray/tests/test_ctc.py
+6
-52
test_ctc.py
theano/tensor/nnet/tests/test_ctc.py
+71
-54
没有找到文件。
theano/gpuarray/tests/test_ctc.py
浏览文件 @
d35d01b1
...
...
@@ -9,6 +9,7 @@ from theano.tests import unittest_tools as utt
import
theano.gpuarray
from
theano.gpuarray.ctc
import
(
gpu_ctc
,
GpuConnectionistTemporalClassification
)
from
theano.tensor.nnet.ctc
import
(
ctc
,
ctc_available
,
ConnectionistTemporalClassification
)
from
theano.tensor.nnet.tests.test_ctc
import
(
setup_torch_case
,
setup_ctc_case
,
setup_grad_case
)
from
.config
import
(
mode_with_gpu
,
mode_without_gpu
)
...
...
@@ -118,53 +119,12 @@ class TestCTC(unittest.TestCase):
# Test obtained from Torch tutorial at:
# https://github.com/baidu-research/warp-ctc/blob/master/torch_binding/TUTORIAL.md
def
test_torch_case
(
self
):
# Layout, from slowest to fastest changing dimension, is (time, batchSize, inputLayerSize)
activations
=
np
.
asarray
([[[
0
,
0
,
0
,
0
,
0
],
[
1
,
2
,
3
,
4
,
5
],
[
-
5
,
-
4
,
-
3
,
-
2
,
-
1
]],
[[
0
,
0
,
0
,
0
,
0
],
[
6
,
7
,
8
,
9
,
10
],
[
-
10
,
-
9
,
-
8
,
-
7
,
-
6
]],
[[
0
,
0
,
0
,
0
,
0
],
[
11
,
12
,
13
,
14
,
15
],
[
-
15
,
-
14
,
-
13
,
-
12
,
-
11
]]],
dtype
=
np
.
float32
)
# Duration of each sequence
activation_times
=
np
.
asarray
([
1
,
3
,
3
],
dtype
=
np
.
int32
)
# Labels for each sequence
labels
=
np
.
asarray
([[
1
,
-
1
],
[
3
,
3
],
[
2
,
3
]],
dtype
=
np
.
int32
)
expected_costs
=
np
.
asarray
([
1.609437943
,
7.355742931
,
4.938849926
],
dtype
=
np
.
float32
)
grads
=
[[[
0.2
,
-
0.8
,
0.2
,
0.2
,
0.2
],
[
0.01165623125
,
0.03168492019
,
0.08612854034
,
-
0.7658783197
,
0.636408627
],
[
-
0.02115798369
,
0.03168492019
,
-
0.8810571432
,
0.2341216654
,
0.636408627
]],
[[
0
,
0
,
0
,
0
,
0
],
[
-
0.9883437753
,
0.03168492019
,
0.08612854034
,
0.2341216654
,
0.636408627
],
[
-
0.02115798369
,
0.03168492019
,
-
0.1891518533
,
-
0.4577836394
,
0.636408627
]],
[[
0
,
0
,
0
,
0
,
0
],
[
0.01165623125
,
0.03168492019
,
0.08612854034
,
-
0.7658783197
,
0.636408627
],
[
-
0.02115798369
,
0.03168492019
,
0.08612854034
,
-
0.7330639958
,
0.636408627
]]]
expected_gradients
=
np
.
asarray
(
grads
,
dtype
=
np
.
float32
)
self
.
check_ctc
(
activations
,
labels
,
activation_times
,
expected_costs
,
expected_gradients
)
activations
,
labels
,
activation_times
,
expected_costs
,
expected_grads
=
setup_torch_case
()
self
.
check_ctc
(
activations
,
labels
,
activation_times
,
expected_costs
,
expected_grads
)
def
test_ctc
(
self
):
activations
=
np
.
asarray
([[[
0.1
,
0.6
,
0.1
,
0.1
,
0.1
],
[
0.1
,
0.1
,
0.6
,
0.1
,
0.1
]],
[[
0.6
,
0.1
,
0.1
,
0.1
,
0.1
],
[
0.1
,
0.1
,
0.5
,
0.2
,
0.1
]]],
dtype
=
np
.
float32
)
activation_times
=
np
.
asarray
([
2
,
2
],
dtype
=
np
.
int32
)
labels
=
np
.
asarray
([[
1
,
2
],
[
1
,
2
]],
dtype
=
np
.
int32
)
expected_costs
=
np
.
asarray
([
2.962858438
,
3.053659201
],
dtype
=
np
.
float32
)
grads
=
[[[
0.177031219
,
-
0.7081246376
,
0.177031219
,
0.177031219
,
0.177031219
],
[
0.177031219
,
-
0.8229685426
,
0.291875124
,
0.177031219
,
0.177031219
]],
[[
0.291875124
,
0.177031219
,
-
0.8229685426
,
0.177031219
,
0.177031219
],
[
0.1786672771
,
0.1786672771
,
-
0.7334594727
,
0.1974578798
,
0.1786672771
]]]
expected_gradients
=
np
.
asarray
(
grads
,
dtype
=
np
.
float32
)
self
.
check_ctc
(
activations
,
labels
,
activation_times
,
expected_costs
,
expected_gradients
)
activations
,
labels
,
input_length
,
expected_costs
,
expected_grads
=
setup_ctc_case
()
self
.
check_ctc
(
activations
,
labels
,
input_length
,
expected_costs
,
expected_grads
)
def
test_verify_grad
(
self
):
def
ctc_op_functor
(
labels
,
in_lengths
):
...
...
@@ -175,13 +135,7 @@ class TestCTC(unittest.TestCase):
return
gpu_ctc
(
acts
,
t_labels
,
t_activation_times
)
return
wrapper
activations
=
np
.
asarray
([[[
0.1
,
0.6
,
0.1
,
0.1
,
0.1
],
[
0.1
,
0.1
,
0.6
,
0.1
,
0.1
]],
[[
0.6
,
0.1
,
0.1
,
0.1
,
0.1
],
[
0.1
,
0.1
,
0.5
,
0.2
,
0.1
]]],
dtype
=
np
.
float32
)
activation_times
=
np
.
asarray
([
2
,
2
],
dtype
=
np
.
int32
)
labels
=
np
.
asarray
([[
1
,
2
],
[
1
,
2
]],
dtype
=
np
.
int32
)
activations
,
activation_times
,
labels
=
setup_grad_case
()
ctc_op
=
ctc_op_functor
(
labels
,
activation_times
)
...
...
theano/tensor/nnet/tests/test_ctc.py
浏览文件 @
d35d01b1
...
...
@@ -9,6 +9,72 @@ from theano.tests import unittest_tools as utt
from
theano.tensor.nnet.ctc
import
(
ctc_available
,
ctc
,
ConnectionistTemporalClassification
)
def
setup_torch_case
():
# Test obtained from Torch tutorial at:
# https://github.com/baidu-research/warp-ctc/blob/master/torch_binding/TUTORIAL.md
# Layout, from slowest to fastest changing dimension, is (time, batchSize, inputLayerSize)
activations
=
np
.
asarray
([[[
0
,
0
,
0
,
0
,
0
],
[
1
,
2
,
3
,
4
,
5
],
[
-
5
,
-
4
,
-
3
,
-
2
,
-
1
]],
[[
0
,
0
,
0
,
0
,
0
],
[
6
,
7
,
8
,
9
,
10
],
[
-
10
,
-
9
,
-
8
,
-
7
,
-
6
]],
[[
0
,
0
,
0
,
0
,
0
],
[
11
,
12
,
13
,
14
,
15
],
[
-
15
,
-
14
,
-
13
,
-
12
,
-
11
]]],
dtype
=
np
.
float32
)
# Duration of each sequence
activation_times
=
np
.
asarray
([
1
,
3
,
3
],
dtype
=
np
.
int32
)
# Labels for each sequence
labels
=
np
.
asarray
([[
1
,
-
1
],
[
3
,
3
],
[
2
,
3
]],
dtype
=
np
.
int32
)
expected_costs
=
np
.
asarray
([
1.609437943
,
7.355742931
,
4.938849926
],
dtype
=
np
.
float32
)
grads
=
[[[
0.2
,
-
0.8
,
0.2
,
0.2
,
0.2
],
[
0.01165623125
,
0.03168492019
,
0.08612854034
,
-
0.7658783197
,
0.636408627
],
[
-
0.02115798369
,
0.03168492019
,
-
0.8810571432
,
0.2341216654
,
0.636408627
]],
[[
0
,
0
,
0
,
0
,
0
],
[
-
0.9883437753
,
0.03168492019
,
0.08612854034
,
0.2341216654
,
0.636408627
],
[
-
0.02115798369
,
0.03168492019
,
-
0.1891518533
,
-
0.4577836394
,
0.636408627
]],
[[
0
,
0
,
0
,
0
,
0
],
[
0.01165623125
,
0.03168492019
,
0.08612854034
,
-
0.7658783197
,
0.636408627
],
[
-
0.02115798369
,
0.03168492019
,
0.08612854034
,
-
0.7330639958
,
0.636408627
]]]
expected_gradients
=
np
.
asarray
(
grads
,
dtype
=
np
.
float32
)
return
[
activations
,
labels
,
activation_times
,
expected_costs
,
expected_gradients
]
def
setup_ctc_case
():
activations
=
np
.
asarray
([[[
0.1
,
0.6
,
0.1
,
0.1
,
0.1
],
[
0.1
,
0.1
,
0.6
,
0.1
,
0.1
]],
[[
0.6
,
0.1
,
0.1
,
0.1
,
0.1
],
[
0.1
,
0.1
,
0.5
,
0.2
,
0.1
]]],
dtype
=
np
.
float32
)
activation_times
=
np
.
asarray
([
2
,
2
],
dtype
=
np
.
int32
)
labels
=
np
.
asarray
([[
1
,
2
],
[
1
,
2
]],
dtype
=
np
.
int32
)
expected_costs
=
np
.
asarray
([
2.962858438
,
3.053659201
],
dtype
=
np
.
float32
)
grads
=
[[[
0.177031219
,
-
0.7081246376
,
0.177031219
,
0.177031219
,
0.177031219
],
[
0.177031219
,
-
0.8229685426
,
0.291875124
,
0.177031219
,
0.177031219
]],
[[
0.291875124
,
0.177031219
,
-
0.8229685426
,
0.177031219
,
0.177031219
],
[
0.1786672771
,
0.1786672771
,
-
0.7334594727
,
0.1974578798
,
0.1786672771
]]]
expected_gradients
=
np
.
asarray
(
grads
,
dtype
=
np
.
float32
)
return
[
activations
,
labels
,
activation_times
,
expected_costs
,
expected_gradients
]
def
setup_grad_case
():
activations
=
np
.
asarray
([[[
0.1
,
0.6
,
0.1
,
0.1
,
0.1
],
[
0.1
,
0.1
,
0.6
,
0.1
,
0.1
]],
[[
0.6
,
0.1
,
0.1
,
0.1
,
0.1
],
[
0.1
,
0.1
,
0.5
,
0.2
,
0.1
]]],
dtype
=
np
.
float32
)
activation_times
=
np
.
asarray
([
2
,
2
],
dtype
=
np
.
int32
)
labels
=
np
.
asarray
([[
1
,
2
],
[
1
,
2
]],
dtype
=
np
.
int32
)
return
[
activations
,
labels
,
activation_times
]
class
TestCTC
(
unittest
.
TestCase
):
"""
Test Baidu CTC wrapper implementation.
...
...
@@ -50,56 +116,13 @@ class TestCTC(unittest.TestCase):
if
isinstance
(
node
.
op
,
ConnectionistTemporalClassification
):
assert
(
node
.
op
.
compute_grad
is
False
)
# Test obtained from Torch tutorial at:
# https://github.com/baidu-research/warp-ctc/blob/master/torch_binding/TUTORIAL.md
def
test_torch_case
(
self
):
# Layout, from slowest to fastest changing dimension, is (time, batchSize, inputLayerSize)
activations
=
np
.
asarray
([[[
0
,
0
,
0
,
0
,
0
],
[
1
,
2
,
3
,
4
,
5
],
[
-
5
,
-
4
,
-
3
,
-
2
,
-
1
]],
[[
0
,
0
,
0
,
0
,
0
],
[
6
,
7
,
8
,
9
,
10
],
[
-
10
,
-
9
,
-
8
,
-
7
,
-
6
]],
[[
0
,
0
,
0
,
0
,
0
],
[
11
,
12
,
13
,
14
,
15
],
[
-
15
,
-
14
,
-
13
,
-
12
,
-
11
]]],
dtype
=
np
.
float32
)
# Duration of each sequence
activation_times
=
np
.
asarray
([
1
,
3
,
3
],
dtype
=
np
.
int32
)
# Labels for each sequence
labels
=
np
.
asarray
([[
1
,
-
1
],
[
3
,
3
],
[
2
,
3
]],
dtype
=
np
.
int32
)
expected_costs
=
np
.
asarray
([
1.609437943
,
7.355742931
,
4.938849926
],
dtype
=
np
.
float32
)
grads
=
[[[
0.2
,
-
0.8
,
0.2
,
0.2
,
0.2
],
[
0.01165623125
,
0.03168492019
,
0.08612854034
,
-
0.7658783197
,
0.636408627
],
[
-
0.02115798369
,
0.03168492019
,
-
0.8810571432
,
0.2341216654
,
0.636408627
]],
[[
0
,
0
,
0
,
0
,
0
],
[
-
0.9883437753
,
0.03168492019
,
0.08612854034
,
0.2341216654
,
0.636408627
],
[
-
0.02115798369
,
0.03168492019
,
-
0.1891518533
,
-
0.4577836394
,
0.636408627
]],
[[
0
,
0
,
0
,
0
,
0
],
[
0.01165623125
,
0.03168492019
,
0.08612854034
,
-
0.7658783197
,
0.636408627
],
[
-
0.02115798369
,
0.03168492019
,
0.08612854034
,
-
0.7330639958
,
0.636408627
]]]
expected_gradients
=
np
.
asarray
(
grads
,
dtype
=
np
.
float32
)
self
.
run_ctc
(
activations
,
labels
,
activation_times
,
expected_costs
,
expected_gradients
)
activations
,
labels
,
input_length
,
expected_costs
,
expected_grads
=
setup_torch_case
()
self
.
run_ctc
(
activations
,
labels
,
input_length
,
expected_costs
,
expected_grads
)
def
test_ctc
(
self
):
activations
=
np
.
asarray
([[[
0.1
,
0.6
,
0.1
,
0.1
,
0.1
],
[
0.1
,
0.1
,
0.6
,
0.1
,
0.1
]],
[[
0.6
,
0.1
,
0.1
,
0.1
,
0.1
],
[
0.1
,
0.1
,
0.5
,
0.2
,
0.1
]]],
dtype
=
np
.
float32
)
activation_times
=
np
.
asarray
([
2
,
2
],
dtype
=
np
.
int32
)
labels
=
np
.
asarray
([[
1
,
2
],
[
1
,
2
]],
dtype
=
np
.
int32
)
expected_costs
=
np
.
asarray
([
2.962858438
,
3.053659201
],
dtype
=
np
.
float32
)
grads
=
[[[
0.177031219
,
-
0.7081246376
,
0.177031219
,
0.177031219
,
0.177031219
],
[
0.177031219
,
-
0.8229685426
,
0.291875124
,
0.177031219
,
0.177031219
]],
[[
0.291875124
,
0.177031219
,
-
0.8229685426
,
0.177031219
,
0.177031219
],
[
0.1786672771
,
0.1786672771
,
-
0.7334594727
,
0.1974578798
,
0.1786672771
]]]
expected_gradients
=
np
.
asarray
(
grads
,
dtype
=
np
.
float32
)
self
.
run_ctc
(
activations
,
labels
,
activation_times
,
expected_costs
,
expected_gradients
)
activations
,
labels
,
input_length
,
expected_costs
,
expected_grads
=
setup_ctc_case
()
self
.
run_ctc
(
activations
,
labels
,
input_length
,
expected_costs
,
expected_grads
)
def
test_verify_grad
(
self
):
def
ctc_op_functor
(
labels
,
in_lengths
):
...
...
@@ -110,13 +133,7 @@ class TestCTC(unittest.TestCase):
return
ctc
(
acts
,
t_labels
,
t_activation_times
)
return
wrapper
activations
=
np
.
asarray
([[[
0.1
,
0.6
,
0.1
,
0.1
,
0.1
],
[
0.1
,
0.1
,
0.6
,
0.1
,
0.1
]],
[[
0.6
,
0.1
,
0.1
,
0.1
,
0.1
],
[
0.1
,
0.1
,
0.5
,
0.2
,
0.1
]]],
dtype
=
np
.
float32
)
activation_times
=
np
.
asarray
([
2
,
2
],
dtype
=
np
.
int32
)
labels
=
np
.
asarray
([[
1
,
2
],
[
1
,
2
]],
dtype
=
np
.
int32
)
activations
,
activation_times
,
labels
=
setup_grad_case
()
ctc_op
=
ctc_op_functor
(
labels
,
activation_times
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论