I tried to change the first maxpool layer to avg_pool layer in resnet34, I did this but only got a maxpool missed model, could you tell me why doesn’t it work, how to do that?
class resnet30_avg(nn.Module):
def init(self, original_model):
super(resnet30_avg, self).init()
self.S1 = nn.Sequential(*list(original_model.children())[:3])
self.S2 = nn.Sequential(*list(original_model.children())[4:])
def forward(self, x):
x = F.avg_pool2d(self.S1(x), 3, stride=2, padding=1)
x = self.S2(x)
return x
arch=resnet30_avg(models.resnet34(pretrained=True))
arch:
resnet30_avg(
(S1): Sequential(
(0): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
(1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU(inplace)
)
(S2): Sequential(
(0): Sequential(
(0): BasicBlock(
(conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
(bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(relu): ReLU(inplace)
(conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
(bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
…