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