NIN-pytorch
numpy
实现NIN模型,利用cifar-10
、cifar-100
和mnist
数据集进行MLPConv
和GAP
的测试
完整实现:zjZSTU/PyNet
GAP实现
参考Global Average Pooling in Pytorch,使用torch.nn.AvgPool2d
class torch.nn.AvgPool2d(kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True)
输入数据体大小为\(N\times C\times H_{in}\times W_{in}\),输出大小为\(N\times C\times H_{out}\times W_{out}\),则
\[ H_{out} = \left \lfloor \frac {H_{in}+2\times padding[0] - kernelsize[0]} {stride[0]} \right \rfloor + 1 \]
\[ W_{out} = \left \lfloor \frac {W_{in}+2\times padding[1] - kernelsize[1]} {stride[1]} \right \rfloor + 1 \]
设核空间尺寸为输入数据体大小,即为全局平均池化层
测试代码如下:
1 | >>> gap = nn.AvgPool2d(3) |
NIN定义
参考:pytorch-nin-cifar10/original.py
1 | class NIN(nn.Module): |
测试
1 | def train(): |