本文整理匯總了Python中blocks.bricks.conv.MaxPooling.get_dim方法的典型用法代碼示例。如果您正苦於以下問題:Python MaxPooling.get_dim方法的具體用法?Python MaxPooling.get_dim怎麽用?Python MaxPooling.get_dim使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類blocks.bricks.conv.MaxPooling
的用法示例。
在下文中一共展示了MaxPooling.get_dim方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_max_pooling
# 需要導入模塊: from blocks.bricks.conv import MaxPooling [as 別名]
# 或者: from blocks.bricks.conv.MaxPooling import get_dim [as 別名]
def test_max_pooling():
x = tensor.tensor4("x")
num_channels = 4
batch_size = 5
x_size = 17
y_size = 13
pool_size = 3
pool = MaxPooling((pool_size, pool_size))
y = pool.apply(x)
func = function([x], y)
x_val = numpy.ones((batch_size, num_channels, x_size, y_size), dtype=theano.config.floatX)
assert_allclose(func(x_val), numpy.ones((batch_size, num_channels, x_size / pool_size, y_size / pool_size)))
pool.input_dim = (x_size, y_size)
pool.get_dim("output") == (num_channels, x_size / pool_size + 1, y_size / pool_size + 1)
示例2: pool_layer
# 需要導入模塊: from blocks.bricks.conv import MaxPooling [as 別名]
# 或者: from blocks.bricks.conv.MaxPooling import get_dim [as 別名]
def pool_layer(self, name, method, pool, pad, stride, image_size):
"""Creates a MaxPooling brick with the given name, pooling size, stride,
and image size. If a string other than 'max' is passed in the 'method'
parameter, the function throws an exception. The 'pad' argument
are ignored. It is instead handled in the conversion through a Padding
brick (see below)."""
# FIX: ignore padding [0 1 0 1]
if method == 'max':
layer = MaxPooling(name=name, pooling_size=pool, step=stride, input_dim=image_size)
else:
raise Exception("Unsupported pooling method: %s" % method)
return (layer, layer.get_dim("output"))
示例3: ConvolutionalLayer
# 需要導入模塊: from blocks.bricks.conv import MaxPooling [as 別名]
# 或者: from blocks.bricks.conv.MaxPooling import get_dim [as 別名]
class ConvolutionalLayer(Sequence, Initializable):
"""A complete convolutional layer: Convolution, nonlinearity, pooling.
.. todo::
Mean pooling.
Parameters
----------
activation : :class:`.BoundApplication`
The application method to apply in the detector stage (i.e. the
nonlinearity before pooling. Needed for ``__init__``.
See Also
--------
:class:`Convolutional` and :class:`MaxPooling` for the other
parameters.
Notes
-----
Uses max pooling.
"""
@lazy(allocation=['filter_size', 'num_filters', 'num_channels'])
def __init__(self, activation, filter_size, num_filters, pooling_size,
num_channels, conv_step=(1, 1), pooling_step=None,
batch_size=None, image_size=None, border_mode='valid',
**kwargs):
self.convolution = ConvolutionalActivation(activation, filter_size, num_filters, num_channels)
self.pooling = MaxPooling()
super(ConvolutionalLayer, self).__init__(
application_methods=[self.convolution.apply,
self.pooling.apply], **kwargs)
self.convolution.name = self.name + '_convolution'
self.pooling.name = self.name + '_pooling'
self.filter_size = filter_size
self.num_filters = num_filters
self.num_channels = num_channels
self.pooling_size = pooling_size
self.conv_step = conv_step
self.pooling_step = pooling_step
self.batch_size = batch_size
self.border_mode = border_mode
self.image_size = image_size
def _push_allocation_config(self):
for attr in ['filter_size', 'num_filters', 'num_channels',
'batch_size', 'border_mode', 'image_size']:
setattr(self.convolution, attr, getattr(self, attr))
self.convolution.step = self.conv_step
self.convolution._push_allocation_config()
if self.image_size is not None:
pooling_input_dim = self.convolution.get_dim('output')
else:
pooling_input_dim = None
self.pooling.input_dim = pooling_input_dim
self.pooling.pooling_size = self.pooling_size
self.pooling.step = self.pooling_step
self.pooling.batch_size = self.batch_size
def get_dim(self, name):
if name == 'input_':
return self.convolution.get_dim('input_')
if name == 'output':
return self.pooling.get_dim('output')
return super(ConvolutionalLayer, self).get_dim(name)
@property
def num_output_channels(self):
return self.num_filters