提交 ca677d9c authored 作者: Xavier Bouthillier's avatar Xavier Bouthillier

Fix stack interface use

上级 dfdcd682
...@@ -411,8 +411,8 @@ def convolve(kerns, kshp, nkern, images, imgshp, step=(1, 1), bias=None, ...@@ -411,8 +411,8 @@ def convolve(kerns, kshp, nkern, images, imgshp, step=(1, 1), bias=None,
patches = (sparse.structured_dot(csc, images.T)).T patches = (sparse.structured_dot(csc, images.T)).T
# compute output of linear classifier # compute output of linear classifier
pshape = tensor.stack(images.shape[0] * tensor.as_tensor(N.prod(outshp)),\ pshape = tensor.stack([images.shape[0] * tensor.as_tensor(N.prod(outshp)),\
tensor.as_tensor(imgshp[0] * kern_size)) tensor.as_tensor(imgshp[0] * kern_size)])
patch_stack = tensor.reshape(patches, pshape, ndim=2) patch_stack = tensor.reshape(patches, pshape, ndim=2)
# kern is of shape: nkern x ksize*number_of_input_features # kern is of shape: nkern x ksize*number_of_input_features
...@@ -425,9 +425,9 @@ def convolve(kerns, kshp, nkern, images, imgshp, step=(1, 1), bias=None, ...@@ -425,9 +425,9 @@ def convolve(kerns, kshp, nkern, images, imgshp, step=(1, 1), bias=None,
# now to have feature maps in raster order ... # now to have feature maps in raster order ...
# go from bsize*outshp x nkern to bsize x nkern*outshp # go from bsize*outshp x nkern to bsize x nkern*outshp
newshp = tensor.stack(images.shape[0],\ newshp = tensor.stack([images.shape[0],\
tensor.as_tensor(N.prod(outshp)),\ tensor.as_tensor(N.prod(outshp)),\
tensor.as_tensor(nkern)) tensor.as_tensor(nkern)])
tensout = tensor.reshape(output, newshp, ndim=3) tensout = tensor.reshape(output, newshp, ndim=3)
output = tensor.DimShuffle((False,) * tensout.ndim, (0, 2, 1))(tensout) output = tensor.DimShuffle((False,) * tensout.ndim, (0, 2, 1))(tensout)
if flatten: if flatten:
...@@ -477,17 +477,17 @@ def max_pool(images, imgshp, maxpoolshp): ...@@ -477,17 +477,17 @@ def max_pool(images, imgshp, maxpoolshp):
indptr, spmat_shape) indptr, spmat_shape)
patches = sparse.structured_dot(csc, images.T).T patches = sparse.structured_dot(csc, images.T).T
pshape = tensor.stack(images.shape[0] *\ pshape = tensor.stack([images.shape[0] *\
tensor.as_tensor(N.prod(outshp)), tensor.as_tensor(N.prod(outshp)),
tensor.as_tensor(imgshp[0]), tensor.as_tensor(imgshp[0]),
tensor.as_tensor(poolsize)) tensor.as_tensor(poolsize)])
patch_stack = tensor.reshape(patches, pshape, ndim=3) patch_stack = tensor.reshape(patches, pshape, ndim=3)
out1 = tensor.max(patch_stack, axis=2) out1 = tensor.max(patch_stack, axis=2)
pshape = tensor.stack(images.shape[0], pshape = tensor.stack([images.shape[0],
tensor.as_tensor(N.prod(outshp)), tensor.as_tensor(N.prod(outshp)),
tensor.as_tensor(imgshp[0])) tensor.as_tensor(imgshp[0])])
out2 = tensor.reshape(out1, pshape, ndim=3) out2 = tensor.reshape(out1, pshape, ndim=3)
out3 = tensor.DimShuffle(out2.broadcastable, (0, 2, 1))(out2) out3 = tensor.DimShuffle(out2.broadcastable, (0, 2, 1))(out2)
......
...@@ -569,8 +569,8 @@ def neibs2images(neibs, neib_shape, original_shape, mode='valid'): ...@@ -569,8 +569,8 @@ def neibs2images(neibs, neib_shape, original_shape, mode='valid'):
neib_shape = T.as_tensor_variable(neib_shape) neib_shape = T.as_tensor_variable(neib_shape)
original_shape = T.as_tensor_variable(original_shape) original_shape = T.as_tensor_variable(original_shape)
new_neib_shape = T.stack(original_shape[-1] // neib_shape[1], new_neib_shape = T.stack([original_shape[-1] // neib_shape[1],
neib_shape[1]) neib_shape[1]])
output_2d = images2neibs(neibs.dimshuffle('x', 'x', 0, 1), output_2d = images2neibs(neibs.dimshuffle('x', 'x', 0, 1),
new_neib_shape, mode=mode) new_neib_shape, mode=mode)
......
...@@ -80,10 +80,10 @@ def conv2d(input, filters, image_shape=None, filter_shape=None, ...@@ -80,10 +80,10 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
else: else:
sym_nkern = 1 sym_nkern = 1
new_input_shape = tensor.join(0, tensor.stack(sym_bsize, 1), input.shape[-2:]) new_input_shape = tensor.join(0, tensor.stack([sym_bsize, 1]), input.shape[-2:])
input4D = tensor.reshape(input, new_input_shape, ndim=4) input4D = tensor.reshape(input, new_input_shape, ndim=4)
new_filter_shape = tensor.join(0, tensor.stack(sym_nkern, 1), filters.shape[-2:]) new_filter_shape = tensor.join(0, tensor.stack([sym_nkern, 1]), filters.shape[-2:])
filters4D = tensor.reshape(filters, new_filter_shape, ndim=4) filters4D = tensor.reshape(filters, new_filter_shape, ndim=4)
### perform actual convolution ### ### perform actual convolution ###
......
...@@ -5118,7 +5118,7 @@ class T_local_reduce(unittest.TestCase): ...@@ -5118,7 +5118,7 @@ class T_local_reduce(unittest.TestCase):
# on 32 bit systems # on 32 bit systems
A = theano.shared(numpy.array([1, 2, 3, 4, 5], dtype='int64')) A = theano.shared(numpy.array([1, 2, 3, 4, 5], dtype='int64'))
f = theano.function([], T.sum(T.stack(A, A), axis=0), mode=self.mode) f = theano.function([], T.sum(T.stack([A, A]), axis=0), mode=self.mode)
assert numpy.allclose(f(), [2, 4, 6, 8, 10]) assert numpy.allclose(f(), [2, 4, 6, 8, 10])
topo = f.maker.fgraph.toposort() topo = f.maker.fgraph.toposort()
assert isinstance(topo[-1].op, T.Elemwise) assert isinstance(topo[-1].op, T.Elemwise)
...@@ -5127,7 +5127,7 @@ class T_local_reduce(unittest.TestCase): ...@@ -5127,7 +5127,7 @@ class T_local_reduce(unittest.TestCase):
try: try:
old = theano.config.warn.reduce_join old = theano.config.warn.reduce_join
theano.config.warn.reduce_join = False theano.config.warn.reduce_join = False
f = theano.function([], T.sum(T.stack(A, A), axis=1), f = theano.function([], T.sum(T.stack([A, A]), axis=1),
mode=self.mode) mode=self.mode)
finally: finally:
theano.config.warn.reduce_join = old theano.config.warn.reduce_join = old
...@@ -5454,7 +5454,7 @@ class TestMakeVector(utt.InferShapeTester): ...@@ -5454,7 +5454,7 @@ class TestMakeVector(utt.InferShapeTester):
def test_local_join_1(): def test_local_join_1():
# test for vector # test for vector
a = tensor.vector('a') a = tensor.vector('a')
s = tensor.stack(a) s = tensor.stack([a])
f = function([a], s, mode=mode_opt) f = function([a], s, mode=mode_opt)
val = f([1]) val = f([1])
assert numpy.all(val == [1]) assert numpy.all(val == [1])
...@@ -5520,7 +5520,7 @@ def test_local_join_empty(): ...@@ -5520,7 +5520,7 @@ def test_local_join_empty():
# test for vector, vector, empty to matrix # test for vector, vector, empty to matrix
# We can't optimize this case. # We can't optimize this case.
s = tensor.stack(a, a, empty_vec) s = tensor.stack([a, a, empty_vec])
f = function([a], s, mode=mode_opt) f = function([a], s, mode=mode_opt)
val = f([]) val = f([])
assert numpy.all(val == [1]) assert numpy.all(val == [1])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论