Python torch.nn 模块,FractionalMaxPool2d() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用torch.nn.FractionalMaxPool2d()

项目:covfefe    作者:deepnn    | 项目源码 | 文件源码
def pool(kernel_size, power=2, output_size=None, 
            out_ratio=None, stride=None, padding=0, 
            dilation=1, return_indices=False, ceil_mode=False, 
            mode='max', count_include_pad=True, _random_samples=None, dim=2):

    in_dim = dim
    if mode == 'max':
        if in_dim == 1:
            return nn.MaxPool1d(kernel_size=kernel_size, stride=stride, 
                        padding=padding, dilation=dilation, 
                        return_indices=return_indices, 
                        ceil_mode=ceil_mode)

        elif in_dim == 2:
            return nn.MaxPool2d(kernel_size=kernel_size, stride=stride, 
                        padding=padding, dilation=dilation, 
                        return_indices=return_indices, 
                        ceil_mode=ceil_mode)

        elif in_dim == 3:
            return nn.MaxPool3d(kernel_size=kernel_size, stride=stride, 
                        padding=padding, dilation=dilation, 
                        return_indices=return_indices, 
                        ceil_mode=ceil_mode)

    elif mode=='ave':
        if in_dim == 1:
            return nn.AvgPool1d(kernel_size=kernel_size, stride=stride, 
                        padding=padding, ceil_mode=ceil_mode, 
                        count_include_pad=count_include_pad)

        elif in_dim == 2:
            return nn.AvgPool2d(kernel_size=kernel_size, stride=stride, 
                        padding=padding, ceil_mode=ceil_mode, 
                        count_include_pad=count_include_pad)

        elif in_dim == 3:
            return nn.AvgPool3d(kernel_size=kernel_size, stride=stride)

    elif mode=='fractional_max':
        return nn.FractionalMaxPool2d(kernel_size=kernel_size, 
                        output_size=out_size, 
                        output_ratio=out_ratio, 
                        return_indices=return_indices, 
                        _random_samples=_random_samples)

    elif mode=='power':
        return nn.LPPool2d(norm_type=power, kernel_size=kernel_size, 
                        stride=stride, ceil_mode=ceil_mode)

# normalization