Add transfer from GPU to host of CTC costs, to check results in GPU CTC test

上级 cb2dad40
...@@ -8,6 +8,7 @@ import theano.tensor as T ...@@ -8,6 +8,7 @@ import theano.tensor as T
from theano import config from theano import config
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
import theano.gpuarray import theano.gpuarray
from theano.gpuarray.basic_ops import infer_context_name
from theano.gpuarray.ctc import (ctc_enabled, ctc) from theano.gpuarray.ctc import (ctc_enabled, ctc)
class TestCTC(unittest.TestCase): class TestCTC(unittest.TestCase):
...@@ -28,14 +29,20 @@ class TestCTC(unittest.TestCase): ...@@ -28,14 +29,20 @@ class TestCTC(unittest.TestCase):
# Symbolic gradient of CTC cost # Symbolic gradient of CTC cost
t_grad = T.grad(T.mean(t_cost), t_activations) t_grad = T.grad(T.mean(t_cost), t_activations)
# Compile symbolic functions # Compile symbolic functions
train = theano.function([], [t_cost, t_grad]) #train = theano.function([], [t_cost, t_grad])
test = theano.function([], [t_cost]) test = theano.function([], [t_cost])
cost, grad = train() #cost, grad = train()
test_cost, = test() cost, = test()
cpu_cost = np.empty(shape=cost.shape, dtype=np.float32)
cost.read(cpu_cost)
#cpu_grad = np.empty(shape=grad.shape, dtype=np.float32)
#grad.read(cpu_grad)
#utt.assert_allclose(expected_grads, grad) #utt.assert_allclose(expected_grads, grad)
#utt.assert_allclose(expected_costs, cost) utt.assert_allclose(expected_costs, cpu_cost)
def simple_test(self): def simple_test(self):
activations = np.asarray([[[0.1, 0.6, 0.1, 0.1, 0.1], [0.1, 0.1, 0.6, 0.1, 0.1]], activations = np.asarray([[[0.1, 0.6, 0.1, 0.1, 0.1], [0.1, 0.1, 0.6, 0.1, 0.1]],
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论