torch.nn.functional.
adaptive_avg_pool2d
(input, output_size)
意思就是不管之前的特征图尺寸为多少,只要设置为(1,1),那么最终特征图大小都为(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
https://pytorch.org/docs/stable/nn.html#torch.nn.functional.adaptive_avg_pool2d