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

testing infer_shape: op CrossentropySoftmaxArgmax1HotWithBias

上级 5b7ab732
...@@ -18,6 +18,7 @@ from theano.tensor.nnet import (categorical_crossentropy, ...@@ -18,6 +18,7 @@ from theano.tensor.nnet import (categorical_crossentropy,
crossentropy_softmax_1hot_with_bias_dx, crossentropy_softmax_1hot_with_bias_dx,
crossentropy_softmax_argmax_1hot_with_bias, crossentropy_softmax_argmax_1hot_with_bias,
CrossentropySoftmax1HotWithBiasDx, CrossentropySoftmax1HotWithBiasDx,
CrossentropySoftmaxArgmax1HotWithBias,
sigmoid, softplus, sigmoid, softplus,
Softmax, softmax, SoftmaxWithBias, softmax_grad, Softmax, softmax, SoftmaxWithBias, softmax_grad,
softmax_with_bias, SoftmaxGrad, softmax_with_bias, SoftmaxGrad,
...@@ -201,9 +202,9 @@ class T_CrossentropySoftmax1HotWithBiasDx(utt.InferShapeTester): ...@@ -201,9 +202,9 @@ class T_CrossentropySoftmax1HotWithBiasDx(utt.InferShapeTester):
CrossentropySoftmax1HotWithBiasDx) CrossentropySoftmax1HotWithBiasDx)
class T_CrossentropySoftmaxArgmax1HotWithBias(unittest.TestCase): class T_CrossentropySoftmaxArgmax1HotWithBias(utt.InferShapeTester):
def setUp(self): def setUp(self):
utt.seed_rng() super(T_CrossentropySoftmaxArgmax1HotWithBias, self).setUp()
self.op = theano.tensor.nnet.crossentropy_softmax_argmax_1hot_with_bias self.op = theano.tensor.nnet.crossentropy_softmax_argmax_1hot_with_bias
def test0(self): def test0(self):
n_classes = 5 n_classes = 5
...@@ -223,11 +224,18 @@ class T_CrossentropySoftmaxArgmax1HotWithBias(unittest.TestCase): ...@@ -223,11 +224,18 @@ class T_CrossentropySoftmaxArgmax1HotWithBias(unittest.TestCase):
numpy.random.rand(n_classes)]) numpy.random.rand(n_classes)])
def test_infer_shape(self): def test_infer_shape(self):
var = self.op(numpy.random.rand(3,5),numpy.random.rand(5), y_idx=numpy.random.randint( admat = dmatrix()
low=0, high=5, size=3)) advec = dvector()
assert theano.function([],var[0].shape)() == [3] alvec = lvector()
assert all(theano.function([],var[1].shape)() == [3,5]) rng = numpy.random.RandomState(utt.fetch_seed())
assert theano.function([],var[2].shape)() == [3] admat_val = rng.rand(3, 5)
advec_val = rng.rand(5)
alvec_val = rng.randint(low=0, high=5, size=3)
self._compile_and_check([admat, advec, alvec],
CrossentropySoftmaxArgmax1HotWithBias()(admat, advec, alvec),
[admat_val, advec_val, alvec_val],
CrossentropySoftmaxArgmax1HotWithBias)
class T_prepend(unittest.TestCase): class T_prepend(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -1123,7 +1131,7 @@ class Test_softmax_opt: ...@@ -1123,7 +1131,7 @@ class Test_softmax_opt:
if __name__ == '__main__': if __name__ == '__main__':
t = T_CrossentropySoftmax1HotWithBiasDx('setUp') t = T_CrossentropySoftmaxArgmax1HotWithBias('setUp')
t.setUp() t.setUp()
t.test_infer_shape() t.test_infer_shape()
...@@ -1131,7 +1139,3 @@ if __name__ == '__main__': ...@@ -1131,7 +1139,3 @@ if __name__ == '__main__':
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论