提交 9c66685f authored 作者: Eric Larsen's avatar Eric Larsen 提交者: Frederic

testing infer_shape: op CrossentropyCategorical1HotGrad

上级 76ef9ebc
...@@ -1034,9 +1034,11 @@ class CrossentropyCategorical1HotGrad(gof.Op): ...@@ -1034,9 +1034,11 @@ class CrossentropyCategorical1HotGrad(gof.Op):
for i in xrange(len(g_y)): for i in xrange(len(g_y)):
g_coding[i, true_one_of_n[i]] = -g_y[i] / coding_dist[i, g_coding[i, true_one_of_n[i]] = -g_y[i] / coding_dist[i,
true_one_of_n[i]] true_one_of_n[i]]
g_coding_strg[0] = g_coding g_coding_strg[0] = g_coding
def infer_shape(self, node, in_shapes):
return [in_shapes[1]]
crossentropy_categorical_1hot_grad = CrossentropyCategorical1HotGrad() crossentropy_categorical_1hot_grad = CrossentropyCategorical1HotGrad()
......
...@@ -20,6 +20,7 @@ from theano.tensor.nnet import (categorical_crossentropy, ...@@ -20,6 +20,7 @@ from theano.tensor.nnet import (categorical_crossentropy,
CrossentropySoftmax1HotWithBiasDx, CrossentropySoftmax1HotWithBiasDx,
CrossentropySoftmaxArgmax1HotWithBias, CrossentropySoftmaxArgmax1HotWithBias,
CrossentropyCategorical1Hot, CrossentropyCategorical1Hot,
CrossentropyCategorical1HotGrad,
sigmoid, softplus, sigmoid, softplus,
Softmax, softmax, SoftmaxWithBias, softmax_grad, Softmax, softmax, SoftmaxWithBias, softmax_grad,
softmax_with_bias, SoftmaxGrad, softmax_with_bias, SoftmaxGrad,
...@@ -283,6 +284,21 @@ class T_prepend(utt.InferShapeTester): ...@@ -283,6 +284,21 @@ class T_prepend(utt.InferShapeTester):
Prepend_scalar_to_each_row) Prepend_scalar_to_each_row)
class T_CrossentropyCategorical1HotGrad(utt.InferShapeTester):
def test_infer_shape(self):
advec = dvector()
admat = dmatrix()
alvec = lvector()
rng = numpy.random.RandomState(utt.fetch_seed())
advec_val = rng.rand(3)
admat_val = rng.rand(3, 2)
alvec_val = [0, 1, 0]
self._compile_and_check([advec, admat, alvec],
[CrossentropyCategorical1HotGrad()(advec, admat, alvec)],
[advec_val, admat_val, alvec_val],
CrossentropyCategorical1HotGrad)
class T_CrossentropyCategorical1Hot(utt.InferShapeTester): class T_CrossentropyCategorical1Hot(utt.InferShapeTester):
def test_grad(self): def test_grad(self):
x = tensor.matrix('x') x = tensor.matrix('x')
...@@ -1159,7 +1175,7 @@ class Test_softmax_opt: ...@@ -1159,7 +1175,7 @@ class Test_softmax_opt:
if __name__ == '__main__': if __name__ == '__main__':
t = T_CrossentropyCategorical1Hot('setUp') t = T_CrossentropyCategorical1HotGrad('setUp')
t.setUp() t.setUp()
t.test_infer_shape() t.test_infer_shape()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论