当前位置: 首页>>代码示例>>Python>>正文


Python pool.pool_2d方法代码示例

本文整理汇总了Python中theano.tensor.signal.pool.pool_2d方法的典型用法代码示例。如果您正苦于以下问题:Python pool.pool_2d方法的具体用法?Python pool.pool_2d怎么用?Python pool.pool_2d使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在theano.tensor.signal.pool的用法示例。


在下文中一共展示了pool.pool_2d方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: apply

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
def apply(self, input_):
        """Apply the pooling (subsampling) transformation.

        Parameters
        ----------
        input_ : :class:`~tensor.TensorVariable`
            An tensor with dimension greater or equal to 2. The last two
            dimensions will be downsampled. For example, with images this
            means that the last two dimensions should represent the height
            and width of your image.

        Returns
        -------
        output : :class:`~tensor.TensorVariable`
            A tensor with the same number of dimensions as `input_`, but
            with the last two dimensions downsampled.

        """
        output = pool_2d(input_, self.pooling_size, st=self.step,
                         mode=self.mode, padding=self.padding,
                         ignore_border=self.ignore_border)
        return output 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:24,代码来源:conv.py

示例2: set_output

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
def set_output(self):
        pooled_out = pool.pool_2d(
            input=self._prev_layer.output,
            ds=self._pool_size,
            ignore_border=True,
            padding=self._padding)
        self._output = pooled_out 
开发者ID:chrischoy,项目名称:3D-R2N2,代码行数:9,代码来源:layers.py

示例3: pool2d

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
def pool2d(x, pool_size, strides=(1, 1), border_mode='valid',
           dim_ordering='th', pool_mode='max'):
    if border_mode == 'same':
        w_pad = pool_size[0] - 2 if pool_size[0] % 2 == 1 else pool_size[0] - 1
        h_pad = pool_size[1] - 2 if pool_size[1] % 2 == 1 else pool_size[1] - 1
        padding = (w_pad, h_pad)
    elif border_mode == 'valid':
        padding = (0, 0)
    else:
        raise Exception('Invalid border mode: ' + str(border_mode))

    if dim_ordering not in {'th', 'tf'}:
        raise Exception('Unknown dim_ordering ' + str(dim_ordering))

    if dim_ordering == 'tf':
        x = x.dimshuffle((0, 3, 1, 2))

    if pool_mode == 'max':
        pool_out = pool.pool_2d(x, ds=pool_size, st=strides,
                                ignore_border=True,
                                padding=padding,
                                mode='max')
    elif pool_mode == 'avg':
        pool_out = pool.pool_2d(x, ds=pool_size, st=strides,
                                ignore_border=True,
                                padding=padding,
                                mode='average_exc_pad')
    else:
        raise Exception('Invalid pooling mode: ' + str(pool_mode))

    if border_mode == 'same':
        expected_width = (x.shape[2] + strides[0] - 1) // strides[0]
        expected_height = (x.shape[3] + strides[1] - 1) // strides[1]

        pool_out = pool_out[:, :,
                            : expected_width,
                            : expected_height]

    if dim_ordering == 'tf':
        pool_out = pool_out.dimshuffle((0, 2, 3, 1))
    return pool_out 
开发者ID:mathDR,项目名称:reading-text-in-the-wild,代码行数:43,代码来源:theano_backend.py

示例4: test_pooling_opt

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
def test_pooling_opt():
    if not cuda.dnn.dnn_available():
        raise SkipTest(cuda.dnn.dnn_available.msg)

    x = T.fmatrix()

    f = theano.function(
        [x],
        pool_2d(x, ds=(2, 2), mode='average_inc_pad', ignore_border=True),
        mode=mode_with_gpu)

    assert any([isinstance(n.op, cuda.dnn.GpuDnnPool)
                for n in f.maker.fgraph.toposort()])

    f(numpy.zeros((10, 10), dtype='float32'))

    f = theano.function(
        [x],
        T.grad(pool_2d(x, ds=(2, 2), mode='average_inc_pad',
                       ignore_border=True).sum(), x),
        mode=mode_with_gpu.including("cudnn"))

    assert any([isinstance(n.op, cuda.dnn.GpuDnnPoolGrad)
                for n in f.maker.fgraph.toposort()])

    f(numpy.zeros((10, 10), dtype='float32')) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:28,代码来源:test_dnn.py

示例5: test_dnn_tag

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
def test_dnn_tag():
    """
    Test that if cudnn isn't avail we crash and that if it is avail, we use it.
    """
    x = T.ftensor4()
    old = theano.config.on_opt_error
    theano.config.on_opt_error = "raise"

    sio = StringIO()
    handler = logging.StreamHandler(sio)
    logging.getLogger('theano.compile.tests.test_dnn').addHandler(handler)
    # Silence original handler when intentionnally generating warning messages
    logging.getLogger('theano').removeHandler(theano.logging_default_handler)
    raised = False
    try:
        f = theano.function(
            [x],
            pool_2d(x, ds=(2, 2), ignore_border=True),
            mode=mode_with_gpu.including("cudnn"))
    except (AssertionError, RuntimeError):
        assert not cuda.dnn.dnn_available()
        raised = True
    finally:
        theano.config.on_opt_error = old
        logging.getLogger(
            'theano.compile.tests.test_dnn').removeHandler(handler)
        logging.getLogger('theano').addHandler(theano.logging_default_handler)

    if not raised:
        assert cuda.dnn.dnn_available()
        assert any([isinstance(n.op, cuda.dnn.GpuDnnPool)
                    for n in f.maker.fgraph.toposort()]) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:34,代码来源:test_dnn.py

示例6: test_pooling_opt

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
def test_pooling_opt():
    if not dnn.dnn_available(test_ctx_name):
        raise SkipTest(dnn.dnn_available.msg)

    x = T.fmatrix()

    f = theano.function(
        [x],
        pool_2d(x, ds=(2, 2), mode='average_inc_pad',
                ignore_border=True),
        mode=mode_with_gpu)

    assert any([isinstance(n.op, dnn.GpuDnnPool)
                for n in f.maker.fgraph.toposort()])

    f(numpy.zeros((10, 10), dtype='float32'))

    f = theano.function(
        [x],
        T.grad(pool_2d(x, ds=(2, 2), mode='average_inc_pad',
                       ignore_border=True).sum(),
               x),
        mode=mode_with_gpu.including("cudnn"))

    assert any([isinstance(n.op, dnn.GpuDnnPoolGrad)
                for n in f.maker.fgraph.toposort()])

    f(numpy.zeros((10, 10), dtype='float32')) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:30,代码来源:test_dnn.py

示例7: test_dnn_tag

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
def test_dnn_tag():
    """
    Test that if cudnn isn't avail we crash and that if it is avail, we use it.
    """
    x = T.ftensor4()
    old = theano.config.on_opt_error
    theano.config.on_opt_error = "raise"

    sio = StringIO()
    handler = logging.StreamHandler(sio)
    logging.getLogger('theano.compile.tests.test_dnn').addHandler(handler)
    # Silence original handler when intentionnally generating warning messages
    logging.getLogger('theano').removeHandler(theano.logging_default_handler)
    raised = False
    try:
        f = theano.function(
            [x],
            pool_2d(x, ds=(2, 2), ignore_border=True),
            mode=mode_with_gpu.including("cudnn"))
    except (AssertionError, RuntimeError):
        assert not dnn.dnn_available(test_ctx_name)
        raised = True
    finally:
        theano.config.on_opt_error = old
        logging.getLogger(
            'theano.compile.tests.test_dnn').removeHandler(handler)
        logging.getLogger('theano').addHandler(theano.logging_default_handler)

    if not raised:
        assert dnn.dnn_available(test_ctx_name)
        assert any([isinstance(n.op, dnn.GpuDnnPool)
                    for n in f.maker.fgraph.toposort()]) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:34,代码来源:test_dnn.py

示例8: encoder

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
def encoder(tparams, layer0_input, filter_shape, pool_size,
                      prefix='cnn_encoder'):
    
    """ filter_shape: (number of filters, num input feature maps, filter height,
                        filter width)
        image_shape: (batch_size, num input feature maps, image height, image width)
    """
    
    conv_out = conv.conv2d(input=layer0_input, filters=tparams[_p(prefix,'W')], 
                            filter_shape=filter_shape)
    
    conv_out_tanh = tensor.tanh(conv_out + tparams[_p(prefix,'b')].dimshuffle('x', 0, 'x', 'x'))
    output = pool.pool_2d(input=conv_out_tanh, ds=pool_size, ignore_border=True)

    return output.flatten(2) 
开发者ID:zhegan27,项目名称:sentence_classification,代码行数:17,代码来源:cnn_layers.py

示例9: pool2d

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
def pool2d(x, pool_size, strides=(1, 1), padding='valid',
           data_format=None, pool_mode='max'):
    data_format = normalize_data_format(data_format)

    assert pool_size[0] >= 1 and pool_size[1] >= 1

    if padding == 'same':
        w_pad = pool_size[0] - 2 if pool_size[0] > 2 and pool_size[0] % 2 == 1 else pool_size[0] - 1
        h_pad = pool_size[1] - 2 if pool_size[1] > 2 and pool_size[1] % 2 == 1 else pool_size[1] - 1
        pad = (w_pad, h_pad)
    elif padding == 'valid':
        pad = (0, 0)
    else:
        raise ValueError('Invalid border mode:', padding)

    if data_format == 'channels_last':
        x = x.dimshuffle((0, 3, 1, 2))

    if pool_mode == 'max':
        pool_out = pool.pool_2d(x, ws=pool_size, stride=strides,
                                ignore_border=True,
                                pad=pad,
                                mode='max')
    elif pool_mode == 'avg':
        pool_out = pool.pool_2d(x, ws=pool_size, stride=strides,
                                ignore_border=True,
                                pad=pad,
                                mode='average_exc_pad')
    else:
        raise ValueError('Invalid pooling mode:', pool_mode)
    if padding == 'same':
        expected_width = (x.shape[2] + strides[0] - 1) // strides[0]
        expected_height = (x.shape[3] + strides[1] - 1) // strides[1]
        pool_out = pool_out[:, :,
                            : expected_width,
                            : expected_height]

    if data_format == 'channels_last':
        pool_out = pool_out.dimshuffle((0, 2, 3, 1))
    return pool_out 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:42,代码来源:theano_backend.py

示例10: pool_2d

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
def pool_2d(x, mode="average", ws=(2, 2), stride=(2, 2)):
    import theano.sandbox.cuda as cuda
    assert cuda.dnn.dnn_available()
    return cuda.dnn.dnn_pool(x, ws=ws, stride=stride, mode=mode) 
开发者ID:CuriousAI,项目名称:ladder,代码行数:6,代码来源:nn.py

示例11: maxpool_2d

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
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:CuriousAI,项目名称:ladder,代码行数:6,代码来源:nn.py

示例12: _train_fprop

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
def _train_fprop(self, state_below):
        return pool_2d(state_below, ds=self.poolsize, st=self.stride,
                       padding=self.padding, ignore_border=self.ignore_border,
                       mode=self.mode) 
开发者ID:hycis,项目名称:Mozi,代码行数:6,代码来源:convolution.py

示例13: get_output_for

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
def get_output_for(self, input, **kwargs):
        if self.pad == 'strictsamex':
            assert(self.stride[0] == 1)
            kk = self.pool_size[0]
            ll = int(np.ceil(kk/2.))
            # rr = kk-ll
            # pad = (ll, 0)
            pad = [(ll, 0)]

            length = input.shape[2]

            self.ignore_border = True
            input = padding.pad(input, pad, batch_ndim=2)
            pad = (0, 0)
        else:
            pad = self.pad

        pooled = pool.pool_2d(input,
                              ds=self.pool_size,
                              st=self.stride,
                              ignore_border=self.ignore_border,
                              padding=pad,
                              mode=self.mode,
                              )

        if self.pad == 'strictsamex':
            pooled = pooled[:, :, :length or None, :]

        return pooled


# add 'strictsamex' method for pad 
开发者ID:ciaua,项目名称:clip2frame,代码行数:34,代码来源:layers.py

示例14: compute_tensor

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
def compute_tensor(self, x):
        if self.reshape_input:
            img_width = T.cast(T.sqrt(x.shape[1]), "int32")
            x = x.reshape((x.shape[0], 1, img_width, img_width), ndim=4)

        conv_out = conv.conv2d(
            input=x,
            filters=self.W_conv,
            filter_shape=self.filter_shape,
            image_shape=None,
            border_mode=self.border_mode
        )

        pooled_out = pool.pool_2d(
            input=conv_out,
            ws=self.pool_size,
            ignore_border=True
        )

        if self.disable_pooling:
            pooled_out = conv_out

        output = self._activation_func(pooled_out + self.B_conv.dimshuffle('x', 0, 'x', 'x'))

        if self.flatten_output:
            output = output.flatten(2)
        return output 
开发者ID:zomux,项目名称:deepy,代码行数:29,代码来源:conv.py

示例15: max_pool

# 需要导入模块: from theano.tensor.signal import pool [as 别名]
# 或者: from theano.tensor.signal.pool import pool_2d [as 别名]
def max_pool( x, size, ignore_border=False ):
    return pool_2d( x, size, ignore_border=ignore_border ) 
开发者ID:anitan0925,项目名称:vaegan,代码行数:4,代码来源:functions.py


注:本文中的theano.tensor.signal.pool.pool_2d方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。