AdaptiveAvgPool2d

AdaptiveAvgPool2d_第1张图片

In [1]: import torch

In [2]: a = torch.rand([4,3,4,4])

In [3]: a.size()
Out[3]: torch.Size([4, 3, 4, 4])

In [4]: b = torch.nn.functional.adaptive_avg_pool2d(a, (1,1))  # 自适应池化,指定池化输出尺寸为 1 * 1

In [5]: b.size()
Out[5]: torch.Size([4, 3, 1, 1])

def _make_test_model():
        import torch.nn as nn
        from inferno.extensions.layers.reshape import AsMatrix
 
        toy_net = nn.Sequential(nn.Conv2d(3, 128, 3, 1, 1),
                                nn.ELU(),
                                nn.MaxPool2d(2),
                                nn.Conv2d(128, 128, 3, 1, 1),
                                nn.ELU(),
                                nn.MaxPool2d(2),
                                nn.Conv2d(128, 256, 3, 1, 1),
                                nn.ELU(),
                                nn.AdaptiveAvgPool2d((1, 1)),
                                AsMatrix(),
                                nn.Linear(256, 10),
                                nn.Softmax())
        return toy_net 

你可能感兴趣的:(目标检测,pytorch)