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

testing infer_shape: op Softmax

上级 bc365ed0
...@@ -22,6 +22,7 @@ from theano.tensor.nnet import (categorical_crossentropy, ...@@ -22,6 +22,7 @@ from theano.tensor.nnet import (categorical_crossentropy,
softmax_with_bias, softmax_with_bias,
Prepend_scalar_constant_to_each_row, Prepend_scalar_constant_to_each_row,
Prepend_scalar_to_each_row) Prepend_scalar_to_each_row)
from theano.tensor import dmatrix
class T_sigmoid(unittest.TestCase): class T_sigmoid(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -35,9 +36,8 @@ class T_softplus(unittest.TestCase): ...@@ -35,9 +36,8 @@ class T_softplus(unittest.TestCase):
def test_elemwise(self): def test_elemwise(self):
utt.verify_grad(softplus, [numpy.random.rand(3,4)]) utt.verify_grad(softplus, [numpy.random.rand(3,4)])
class T_Softmax(unittest.TestCase): class T_Softmax(utt.InferShapeTester):
def setUp(self):
utt.seed_rng()
def test0(self): def test0(self):
def f(a): def f(a):
return softmax(a)[:,0] return softmax(a)[:,0]
...@@ -56,8 +56,10 @@ class T_Softmax(unittest.TestCase): ...@@ -56,8 +56,10 @@ class T_Softmax(unittest.TestCase):
utt.verify_grad(f, [numpy.random.rand(3,4)]) utt.verify_grad(f, [numpy.random.rand(3,4)])
def test_infer_shape(self): def test_infer_shape(self):
f=theano.function([],softmax(numpy.random.rand(3,4)).shape) admat = dmatrix()
assert all(f()==[3,4]) admat_val = numpy.random.rand(3, 4)
self._compile_and_check([admat], [Softmax()(admat)],
[admat_val], Softmax)
def test_vector(self): def test_vector(self):
x = T.vector() x = T.vector()
...@@ -1091,5 +1093,21 @@ class Test_softmax_opt: ...@@ -1091,5 +1093,21 @@ class Test_softmax_opt:
# REPEAT 3 CASES in presence of log(softmax) with the advanced indexing etc. # REPEAT 3 CASES in presence of log(softmax) with the advanced indexing etc.
#if __name__ == '__main__':
# unittest.main()
if __name__ == '__main__': if __name__ == '__main__':
unittest.main()
t = T_Softmax('setUp')
t.setUp()
t.test_infer_shape()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论