Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5213ba52
提交
5213ba52
authored
6月 13, 2017
作者:
João Victor Tozatti Risso
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add check to verify that GPU values are equal to CPU values in CTC tests
Signed-off-by:
João Victor Tozatti Risso
<
joaovictor.risso@gmail.com
>
上级
ef01d10d
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
24 行增加
和
8 行删除
+24
-8
test_ctc.py
theano/gpuarray/tests/test_ctc.py
+24
-8
没有找到文件。
theano/gpuarray/tests/test_ctc.py
浏览文件 @
5213ba52
...
...
@@ -8,6 +8,8 @@ import theano.tensor as T
from
theano.tests
import
unittest_tools
as
utt
import
theano.gpuarray
from
theano.gpuarray.ctc
import
(
ctc_enabled
,
gpu_ctc
)
from
theano.tensor.nnet.ctc
import
ctc
from
.config
import
(
mode_with_gpu
,
mode_without_gpu
)
class
TestCTC
(
unittest
.
TestCase
):
...
...
@@ -21,21 +23,35 @@ class TestCTC(unittest.TestCase):
t_activation_times
=
theano
.
shared
(
input_length
,
name
=
"activation_times"
)
t_labels
=
theano
.
shared
(
labels
,
name
=
"labels"
)
t_cost
=
gpu_ctc
(
t_activations
,
t_labels
,
t_activation_times
)
# Compute CTC costs and gradients on the CPU to compare with GPU
cpu_ctc_cost
=
ctc
(
t_activations
,
t_labels
,
t_activation_times
)
# Symbolic gradient of CTC cost
t_grad
=
T
.
grad
(
T
.
mean
(
t_cost
),
t_activations
)
cpu_ctc_grad
=
T
.
grad
(
T
.
mean
(
t_cost
),
t_activations
)
# Compile CPU function without optimization
cpu_train
=
theano
.
function
([],
[
cpu_ctc_cost
,
cpu_ctc_grad
],
mode
=
mode_without_gpu
)
cpu_cost
,
cpu_grad
=
cpu_train
()
gpu_ctc_cost
=
gpu_ctc
(
t_activations
,
t_labels
,
t_activation_times
)
# Symbolic gradient of CTC cost
gpu_ctc_grad
=
T
.
grad
(
T
.
mean
(
t_cost
),
t_activations
)
# Compile symbolic functions
train
=
theano
.
function
([],
[
t_cost
,
t
_grad
])
gpu_train
=
theano
.
function
([],
[
gpu_ctc_cost
,
gpu_ctc
_grad
])
cost
,
grad
=
train
()
gpu_cost
,
gpu_grad
=
gpu_
train
()
# Transfer costs from GPU memory to host
c
pu_cost
=
np
.
asarray
(
cost
)
c
ost_from_gpu
=
np
.
asarray
(
gpu_
cost
)
# Transfer gradients from GPU memory to host
cpu_grad
=
np
.
asarray
(
grad
)
grad_from_gpu
=
np
.
asarray
(
gpu_grad
)
# Check that results are in conformance with expected values
utt
.
assert_allclose
(
expected_grads
/
gpu_ctc_cost
.
shape
[
0
],
grad_from_gpu
)
utt
.
assert_allclose
(
expected_costs
,
cost_from_gpu
)
utt
.
assert_allclose
(
expected_grads
/
cost
.
shape
[
0
],
cpu_grad
)
utt
.
assert_allclose
(
expected_costs
,
cpu_cost
)
# Compare values obtained from CPU and GPU implementations
utt
.
assert_allclose
(
cpu_cost
,
cost_from_gpu
)
utt
.
assert_allclose
(
cpu_grad
,
grad_from_gpu
)
# Test obtained from Torch tutorial at:
# https://github.com/baidu-research/warp-ctc/blob/master/torch_binding/TUTORIAL.md
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论