本文整理汇总了Python中theano.tensor.signal.pool.Pool类的典型用法代码示例。如果您正苦于以下问题:Python Pool类的具体用法?Python Pool怎么用?Python Pool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pool类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_DownsampleFactorMax
def test_DownsampleFactorMax(self):
rng = numpy.random.RandomState(utt.fetch_seed())
# generate random images
maxpoolshps = ((1, 1), (2, 2), (3, 3), (2, 3))
imval = rng.rand(4, 2, 16, 16)
images = tensor.dtensor4()
for maxpoolshp, ignore_border, mode in product(
maxpoolshps, [True, False], ["max", "sum", "average_inc_pad", "average_exc_pad"]
):
# print 'maxpoolshp =', maxpoolshp
# print 'ignore_border =', ignore_border
# Pure Numpy computation
numpy_output_val = self.numpy_max_pool_2d(imval, maxpoolshp, ignore_border, mode=mode)
output = pool_2d(images, maxpoolshp, ignore_border, mode=mode)
f = function([images], [output])
output_val = f(imval)
utt.assert_allclose(output_val, numpy_output_val)
# Pool op
maxpool_op = Pool(maxpoolshp, ignore_border=ignore_border, mode=mode)(images)
output_shape = Pool.out_shape(imval.shape, maxpoolshp, ignore_border=ignore_border)
utt.assert_allclose(numpy.asarray(output_shape), numpy_output_val.shape)
f = function([images], maxpool_op)
output_val = f(imval)
utt.assert_allclose(output_val, numpy_output_val)
开发者ID:Tintin-C,项目名称:Theano,代码行数:27,代码来源:test_pool.py
示例2: get_dim
def get_dim(self, name):
if name == 'input_':
return self.input_dim
if name == 'output':
return tuple(Pool.out_shape(
self.input_dim, self.pooling_size, st=self.step,
ignore_border=self.ignore_border, padding=self.padding))
开发者ID:dery-hit,项目名称:blocks,代码行数:7,代码来源:conv.py
示例3: test_DownsampleFactorMaxPaddingStride_grad_grad
def test_DownsampleFactorMaxPaddingStride_grad_grad(self):
rng = numpy.random.RandomState(utt.fetch_seed())
imgsizes = ((10, 10), (10, 5), (5, 5))
maxpoolsizes = ((5, 3), (3, 5), (3, 3))
stridesizes = ((3, 2), (2, 3), (3, 3))
paddingsizes = ((2, 2), (2, 1), (2, 2))
for i in range(len(imgsizes)):
imgsize = imgsizes[i]
imval = rng.rand(1, 1, imgsize[0], imgsize[1]) * 10.0
maxpoolsize = maxpoolsizes[i]
stridesize = stridesizes[i]
paddingsize = paddingsizes[i]
grad_shape = Pool.out_shape(imval.shape,
maxpoolsize, st=stridesize,
ignore_border=True,
padding=paddingsize)
grad_val = rng.rand(*grad_shape) * 10.0
def mp(input, grad):
out = Pool(
maxpoolsize, ignore_border=True,
st=stridesize,
padding=paddingsize,
)(input)
grad_op = MaxPoolGrad(maxpoolsize, ignore_border=True,
st=stridesize, padding=paddingsize)
return grad_op(input, out, grad)
utt.verify_grad(mp, [imval, grad_val], rng=rng)
开发者ID:12190143,项目名称:Theano,代码行数:30,代码来源:test_pool.py
示例4: test_AveragePoolGrad_grad_st_extra
def test_AveragePoolGrad_grad_st_extra(self):
"""checks the gradient of the gradient for the case that
stride is used for extra examples"""
rng = numpy.random.RandomState(utt.fetch_seed())
avgpoolshps = ((5, 3), (5, 3), (5, 3), (5, 5), (3, 2), (7, 7), (9, 9))
stridesizes = ((3, 2), (7, 5), (10, 6), (1, 1),
(2, 3), (10, 10), (1, 1))
imvsizs = ((16, 16), (16, 16), (16, 16), (8, 5),
(8, 5), (8, 5), (8, 5))
for indx in numpy.arange(len(avgpoolshps)):
imvsize = imvsizs[indx]
imval = rng.rand(1, 2, imvsize[0], imvsize[1])
stride = stridesizes[indx]
avgpoolshp = avgpoolshps[indx]
for ignore_border in [True, False]:
for mode in ['sum', 'average_inc_pad', 'average_exc_pad']:
grad_shape = Pool.out_shape(
imval.shape, avgpoolshp,
ignore_border=ignore_border, st=stride)
grad_val = rng.rand(*grad_shape)
def mp(input, grad):
grad_op = AveragePoolGrad(
avgpoolshp, ignore_border=ignore_border,
st=stride, mode=mode)
return grad_op(input, grad)
# skip the grad verification when the output is empty
if numpy.prod(grad_shape) == 0:
continue
utt.verify_grad(mp, [imval, grad_val], rng=rng)
开发者ID:12190143,项目名称:Theano,代码行数:32,代码来源:test_pool.py
示例5: test_DownsampleFactorMaxGrad_grad_st_extra
def test_DownsampleFactorMaxGrad_grad_st_extra(self):
"""checks the gradient of the gradient for the case that
stride is used for extra examples"""
rng = numpy.random.RandomState(utt.fetch_seed())
maxpoolshps = ((5, 3), (5, 3), (5, 3), (5, 5), (3, 2), (7, 7), (9, 9))
stridesizes = ((3, 2), (7, 5), (10, 6), (1, 1),
(2, 3), (10, 10), (1, 1))
imvsizs = ((16, 16), (16, 16), (16, 16), (8, 5),
(8, 5), (8, 5), (8, 5))
for indx in numpy.arange(len(maxpoolshps)):
imvsize = imvsizs[indx]
imval = rng.rand(1, 2, imvsize[0], imvsize[1])
stride = stridesizes[indx]
maxpoolshp = maxpoolshps[indx]
for ignore_border in [True, False]:
grad_shape = Pool.out_shape(
imval.shape, maxpoolshp,
ignore_border=ignore_border, st=stride)
grad_val = rng.rand(*grad_shape)
def mp(input, grad):
out = Pool(ignore_border=ignore_border)(input, maxpoolshp,
stride)
grad_op = MaxPoolGrad(ignore_border=ignore_border)
return grad_op(input, out, grad, maxpoolshp, stride)
# skip the grad verification when the output is empty
if numpy.prod(grad_shape) == 0:
continue
utt.verify_grad(mp, [imval, grad_val], rng=rng)
开发者ID:maniacs-ops,项目名称:Theano,代码行数:31,代码来源:test_pool.py
示例6: test_AveragePoolPaddingStride_grad_grad
def test_AveragePoolPaddingStride_grad_grad(self):
rng = numpy.random.RandomState(utt.fetch_seed())
# avgpool, stride, padding, input sizes
examples = (
((3,), (2,), (2,), (10,)),
((3,), (2,), (2,), (2, 10,)),
((3,), (2,), (2,), (2, 1, 10,)),
((5, 3), (3, 2), (2, 2), (1, 1, 10, 10)),
((5, 3), (3, 2), (2, 2), (1, 1, 10, 10)),
((3, 5), (2, 3), (2, 1), (1, 1, 10, 5)),
((3, 3), (3, 3), (2, 2), (1, 1, 5, 5)),
((5, 3, 3), (3, 2, 2), (2, 2, 2), (1, 1, 10, 5, 5)),
((3, 5, 3), (2, 3, 2), (2, 1, 2), (1, 1, 5, 10, 5)),
((3, 3, 5), (2, 2, 3), (2, 2, 1), (1, 1, 5, 5, 10)),
)
for (avgpoolshp, stridesize, paddingsize, inputsize) in examples:
imval = rng.rand(*inputsize) * 10.0
# 'average_exc_pad' with non-zero padding is not implemented
for mode in ['sum', 'average_inc_pad']:
grad_shape = Pool.out_shape(imval.shape,
avgpoolshp,
ndim=len(avgpoolshp),
st=stridesize,
ignore_border=True,
padding=paddingsize)
grad_val = rng.rand(*grad_shape) * 10.0
def mp(input, grad):
grad_op = AveragePoolGrad(ndim=len(avgpoolshp),
ignore_border=True,
mode=mode)
return grad_op(input, grad, avgpoolshp, stridesize, paddingsize)
utt.verify_grad(mp, [imval, grad_val], rng=rng)
开发者ID:wgapl,项目名称:Theano,代码行数:35,代码来源:test_pool.py
示例7: test_AveragePoolPaddingStride_grad_grad
def test_AveragePoolPaddingStride_grad_grad(self):
rng = numpy.random.RandomState(utt.fetch_seed())
imgsizes = ((10, 10), (10, 5), (5, 5))
avgpoolsizes = ((5, 3), (3, 5), (3, 3))
stridesizes = ((3, 2), (2, 3), (3, 3))
paddingsizes = ((2, 2), (2, 1), (2, 2))
for i in range(len(imgsizes)):
imgsize = imgsizes[i]
imval = rng.rand(1, 1, imgsize[0], imgsize[1]) * 10.0
avgpoolsize = avgpoolsizes[i]
stridesize = stridesizes[i]
paddingsize = paddingsizes[i]
# 'average_exc_pad' with non-zero padding is not implemented
for mode in ['sum', 'average_inc_pad']:
grad_shape = Pool.out_shape(imval.shape,
avgpoolsize, st=stridesize,
ignore_border=True, padding=paddingsize)
grad_val = rng.rand(*grad_shape) * 10.0
def mp(input, grad):
grad_op = AveragePoolGrad(avgpoolsize, ignore_border=True,
st=stridesize, padding=paddingsize,
mode=mode)
return grad_op(input, grad)
utt.verify_grad(mp, [imval, grad_val], rng=rng)
开发者ID:12190143,项目名称:Theano,代码行数:27,代码来源:test_pool.py
示例8: test_DownsampleFactorMaxGrad_grad_st
def test_DownsampleFactorMaxGrad_grad_st(self):
"""checks the gradient of the gradient for
the case that stride is used"""
rng = numpy.random.RandomState(utt.fetch_seed())
maxpoolshps = ((1, 1), (3, 3), (5, 3))
stridesizes = ((1, 1), (3, 3), (5, 7))
imval = rng.rand(1, 2, 16, 16)
for maxpoolshp in maxpoolshps:
for ignore_border in [True, False]:
for stride in stridesizes:
grad_shape = Pool.out_shape(
imval.shape, maxpoolshp,
ignore_border=ignore_border, st=stride)
grad_val = rng.rand(*grad_shape)
def mp(input, grad):
out = Pool(
maxpoolshp, ignore_border=ignore_border,
st=stride)(input)
grad_op = MaxPoolGrad(
maxpoolshp, ignore_border=ignore_border,
st=stride)
return grad_op(input, out, grad)
utt.verify_grad(mp, [imval, grad_val], rng=rng)
开发者ID:12190143,项目名称:Theano,代码行数:26,代码来源:test_pool.py
示例9: test_DownsampleFactorMax
def test_DownsampleFactorMax(self):
rng = numpy.random.RandomState(utt.fetch_seed())
# maxpool, input size
examples = (
((2,), (16,)),
((2,), (4, 16,)),
((2,), (4, 2, 16,)),
((1, 1), (4, 2, 16, 16)),
((2, 2), (4, 2, 16, 16)),
((3, 3), (4, 2, 16, 16)),
((3, 2), (4, 2, 16, 16)),
((3, 2, 2), (3, 2, 16, 16, 16)),
((2, 3, 2), (3, 2, 16, 16, 16)),
((2, 2, 3), (3, 2, 16, 16, 16)),
((2, 2, 3, 2), (3, 2, 6, 6, 6, 5)),
)
for example, ignore_border, mode in product(examples,
[True, False],
['max',
'sum',
'average_inc_pad',
'average_exc_pad']):
(maxpoolshp, inputsize) = example
imval = rng.rand(*inputsize)
images = theano.shared(imval)
# Pure Numpy computation
numpy_output_val = self.numpy_max_pool_nd(imval, maxpoolshp,
ignore_border,
mode=mode)
# The pool_2d or pool_3d helper methods
if len(maxpoolshp) == 2:
output = pool_2d(images, maxpoolshp, ignore_border,
mode=mode)
f = function([], [output, ])
output_val = f()
utt.assert_allclose(output_val, numpy_output_val)
elif len(maxpoolshp) == 3:
output = pool_3d(images, maxpoolshp, ignore_border,
mode=mode)
f = function([], [output, ])
output_val = f()
utt.assert_allclose(output_val, numpy_output_val)
# Pool op
maxpool_op = Pool(ndim=len(maxpoolshp),
ignore_border=ignore_border,
mode=mode)(images, maxpoolshp)
output_shape = Pool.out_shape(imval.shape, maxpoolshp,
ndim=len(maxpoolshp),
ignore_border=ignore_border)
utt.assert_allclose(numpy.asarray(output_shape), numpy_output_val.shape)
f = function([], maxpool_op)
output_val = f()
utt.assert_allclose(output_val, numpy_output_val)
开发者ID:wgapl,项目名称:Theano,代码行数:58,代码来源:test_pool.py
示例10: test_AveragePoolGrad_grad_st
def test_AveragePoolGrad_grad_st(self):
"""checks the gradient of the gradient for
the case that stride is used"""
rng = numpy.random.RandomState(utt.fetch_seed())
avgpoolshps = ((1, 1), (3, 3), (5, 3))
stridesizes = ((1, 1), (3, 3), (5, 7))
imval = rng.rand(1, 2, 16, 16)
for avgpoolshp in avgpoolshps:
for ignore_border in [True, False]:
for mode in ["sum", "average_inc_pad", "average_exc_pad"]:
for stride in stridesizes:
grad_shape = Pool.out_shape(imval.shape, avgpoolshp, ignore_border=ignore_border, st=stride)
grad_val = rng.rand(*grad_shape)
def mp(input, grad):
grad_op = AveragePoolGrad(avgpoolshp, ignore_border=ignore_border, st=stride, mode=mode)
return grad_op(input, grad)
utt.verify_grad(mp, [imval, grad_val], rng=rng)
开发者ID:Tintin-C,项目名称:Theano,代码行数:20,代码来源:test_pool.py
示例11: test_AveragePoolGrad_grad
def test_AveragePoolGrad_grad(self):
rng = numpy.random.RandomState(utt.fetch_seed())
avgpoolshps = ((1, 1), (3, 2), (2, 3))
imval = rng.rand(2, 3, 3, 4) * 10.0
# more variance means numeric gradient will be more accurate
for avgpoolshp in avgpoolshps:
for ignore_border in [True, False]:
for mode in ["sum", "average_inc_pad", "average_exc_pad"]:
# print 'maxpoolshp =', maxpoolshp
# print 'ignore_border =', ignore_border
# The shape of the gradient will be the shape of the output
grad_shape = Pool.out_shape(imval.shape, avgpoolshp, ignore_border=ignore_border)
grad_val = rng.rand(*grad_shape) * 10.0
def mp(input, grad):
grad_op = AveragePoolGrad(avgpoolshp, ignore_border=ignore_border, mode=mode)
return grad_op(input, grad)
utt.verify_grad(mp, [imval, grad_val], rng=rng)
开发者ID:Tintin-C,项目名称:Theano,代码行数:20,代码来源:test_pool.py
示例12: test_DownsampleFactorMaxGrad_grad
def test_DownsampleFactorMaxGrad_grad(self):
rng = numpy.random.RandomState(utt.fetch_seed())
maxpoolshps = ((1, 1), (3, 2), (2, 3))
imval = rng.rand(2, 3, 3, 4) * 10.0
# more variance means numeric gradient will be more accurate
for maxpoolshp in maxpoolshps:
for ignore_border in [True, False]:
# print 'maxpoolshp =', maxpoolshp
# print 'ignore_border =', ignore_border
# The shape of the gradient will be the shape of the output
grad_shape = Pool.out_shape(imval.shape, maxpoolshp, ignore_border=ignore_border)
grad_val = rng.rand(*grad_shape) * 10.0
def mp(input, grad):
out = Pool(maxpoolshp, ignore_border=ignore_border)(input)
grad_op = MaxPoolGrad(maxpoolshp, ignore_border=ignore_border)
return grad_op(input, out, grad)
utt.verify_grad(mp, [imval, grad_val], rng=rng)
开发者ID:Tintin-C,项目名称:Theano,代码行数:20,代码来源:test_pool.py
示例13: test_AveragePoolGrad_grad_st
def test_AveragePoolGrad_grad_st(self, example, ignore_border, mode):
# checks the gradient of the gradient for
# the case that stride is used
rng = numpy.random.RandomState(utt.fetch_seed())
(avgpoolshp, stride, inputsize) = example
imval = rng.rand(*inputsize)
grad_shape = Pool.out_shape(
imval.shape, avgpoolshp,
ndim=len(avgpoolshp),
ignore_border=ignore_border, st=stride)
# skip the grad verification when the output is empty
if numpy.prod(grad_shape) != 0:
grad_val = rng.rand(*grad_shape)
def mp(input, grad):
grad_op = AveragePoolGrad(
ndim=len(avgpoolshp),
ignore_border=ignore_border,
mode=mode)
return grad_op(input, grad, avgpoolshp, stride)
utt.verify_grad(mp, [imval, grad_val], rng=rng)
开发者ID:wgapl,项目名称:Theano,代码行数:23,代码来源:test_pool.py
示例14: test_DownsampleFactorMaxGrad_grad
def test_DownsampleFactorMaxGrad_grad(self):
rng = numpy.random.RandomState(utt.fetch_seed())
# maxpool, input sizes
examples = (
((2,), (2,)),
((2,), (2, 3)),
((1, 1), (2, 3, 3, 4)),
((3, 2), (2, 3, 3, 4)),
((2, 3), (2, 3, 3, 4)),
((1, 1, 1), (2, 3, 3, 4)),
((3, 2, 2), (2, 3, 3, 4)),
((2, 3, 2), (2, 3, 3, 4)),
((2, 2, 3), (2, 3, 3, 4)),
((2, 2, 3), (2, 1, 3, 3, 4)),
)
for (maxpoolshp, inputsize) in examples:
imval = rng.rand(*inputsize) * 10.0
# more variance means numeric gradient will be more accurate
for ignore_border in [True, False]:
# print 'maxpoolshp =', maxpoolshp
# print 'ignore_border =', ignore_border
# The shape of the gradient will be the shape of the output
grad_shape = Pool.out_shape(
imval.shape, maxpoolshp, ndim=len(maxpoolshp), ignore_border=ignore_border)
grad_val = rng.rand(*grad_shape) * 10.0
def mp(input, grad):
out = Pool(
ndim=len(maxpoolshp),
ignore_border=ignore_border)(input, maxpoolshp)
grad_op = MaxPoolGrad(
ndim=len(maxpoolshp),
ignore_border=ignore_border)
return grad_op(input, out, grad, maxpoolshp)
utt.verify_grad(mp, [imval, grad_val], rng=rng)
开发者ID:wgapl,项目名称:Theano,代码行数:37,代码来源:test_pool.py
示例15: test_DownsampleFactorMaxPaddingStride_grad_grad
def test_DownsampleFactorMaxPaddingStride_grad_grad(self):
rng = numpy.random.RandomState(utt.fetch_seed())
# maxpool, stride, padding, input sizes
examples = (
((3,), (2,), (2,), (10,)),
((3,), (2,), (2,), (2, 10,)),
((3,), (2,), (2,), (2, 1, 10,)),
((5, 3), (3, 2), (2, 2), (1, 1, 10, 10)),
((5, 3), (3, 2), (2, 2), (1, 1, 10, 10)),
((3, 5), (2, 3), (2, 1), (1, 1, 10, 5)),
((3, 3), (3, 3), (2, 2), (1, 1, 5, 5)),
((5, 3, 3), (3, 2, 2), (2, 2, 2), (1, 1, 10, 5, 5)),
((3, 5, 3), (2, 3, 2), (2, 1, 2), (1, 1, 5, 10, 5)),
((3, 3, 5), (2, 2, 3), (2, 2, 1), (1, 1, 5, 5, 10)),
)
for (maxpoolshp, stridesize, paddingsize, inputsize) in examples:
imval = rng.rand(*inputsize) * 10.0
grad_shape = Pool.out_shape(imval.shape,
maxpoolshp,
ndim=len(maxpoolshp),
st=stridesize,
ignore_border=True,
padding=paddingsize)
grad_val = rng.rand(*grad_shape) * 10.0
def mp(input, grad):
out = Pool(
ndim=len(maxpoolshp),
ignore_border=True,
)(input, maxpoolshp, stridesize, paddingsize)
grad_op = MaxPoolGrad(ndim=len(maxpoolshp),
ignore_border=True)
return grad_op(input, out, grad, maxpoolshp, stridesize, paddingsize)
utt.verify_grad(mp, [imval, grad_val], rng=rng)
开发者ID:wgapl,项目名称:Theano,代码行数:36,代码来源:test_pool.py
示例16: test_AveragePoolGrad_grad
def test_AveragePoolGrad_grad(self):
rng = numpy.random.RandomState(utt.fetch_seed())
# avgpool, input sizes
examples = (
((2,), (2,)),
((2,), (2, 3)),
((1, 1), (2, 3, 3, 4)),
((3, 2), (2, 3, 3, 4)),
((2, 3), (2, 3, 3, 4)),
((1, 1, 1), (2, 3, 3, 4)),
((3, 2, 2), (2, 3, 3, 4)),
((2, 3, 2), (2, 3, 3, 4)),
((2, 2, 3), (2, 3, 3, 4)),
((2, 2, 3), (2, 1, 3, 3, 4)),
)
for (avgpoolshp, inputsize) in examples:
imval = rng.rand(*inputsize) * 10.0
# more variance means numeric gradient will be more accurate
for ignore_border in [True, False]:
for mode in ['sum', 'average_inc_pad', 'average_exc_pad']:
# print 'maxpoolshp =', maxpoolshp
# print 'ignore_border =', ignore_border
# The shape of the gradient will be the shape of the output
grad_shape = Pool.out_shape(
imval.shape, avgpoolshp, ndim=len(avgpoolshp),
ignore_border=ignore_border)
grad_val = rng.rand(*grad_shape) * 10.0
def mp(input, grad):
grad_op = AveragePoolGrad(
ndim=len(avgpoolshp),
ignore_border=ignore_border, mode=mode)
return grad_op(input, grad, avgpoolshp)
utt.verify_grad(mp, [imval, grad_val], rng=rng)
开发者ID:wgapl,项目名称:Theano,代码行数:36,代码来源:test_pool.py
示例17: test_out_shape
def test_out_shape(self):
assert Pool.out_shape((9, 8, 6), (2, 2)) == [9, 4, 3]
assert Pool.out_shape((8, 6), (2, 2)) == [4, 3]
开发者ID:wgapl,项目名称:Theano,代码行数:3,代码来源:test_pool.py
示例18: infer_shape
def infer_shape(self, node, in_shapes):
ws, stride, pad = [node.inputs[1], node.inputs[2], node.inputs[3]]
shp = Pool.out_shape(in_shapes[0], ws, self.ignore_border, stride,
pad, self.ndim)
return [shp]
开发者ID:JesseLivezey,项目名称:Theano,代码行数:5,代码来源:pool.py
示例19: maxpool_2d
def maxpool_2d(z, in_dim, poolsize, poolstride):
z = pool_2d(z, ds=poolsize, st=poolstride)
output_size = tuple(Pool.out_shape(in_dim, poolsize, st=poolstride))
return z, output_size
开发者ID:VikingMew,项目名称:ladder,代码行数:4,代码来源:nn.py
注:本文中的theano.tensor.signal.pool.Pool类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论