Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加的位置一般是在最后一个卷积层之后是吗?这样不影响预训练权重? #87

Open
lmqhello opened this issue Oct 5, 2022 · 0 comments

Comments

@lmqhello
Copy link

lmqhello commented Oct 5, 2022

举个例子:

def` __init__(self, num_classes=-1):
       super(AlexNet, self).__init__()
       self.num_classes = num_classes
       self.features = nn.Sequential(
           nn.Conv2d(3, 64, kernel_size=11, stride=4, padding=2),
           nn.ReLU(inplace=True),
           nn.MaxPool2d(kernel_size=3, stride=2),
           nn.Conv2d(64, 192, kernel_size=5, padding=2),
           nn.ReLU(inplace=True),
           nn.MaxPool2d(kernel_size=3, stride=2),
           nn.Conv2d(192, 384, kernel_size=3, padding=1),
           nn.ReLU(inplace=True),
           nn.Conv2d(384, 256, kernel_size=3, padding=1),
           nn.ReLU(inplace=True),
           nn.Conv2d(256, 256, kernel_size=3, padding=1),
           nn.ReLU(inplace=True),
           nn.MaxPool2d(kernel_size=3, stride=2),
       )
    
     self.se = SEAttention(channel=256,reduction=64)

       if self.num_classes > 0:
           self.classifier = nn.Sequential( 
               nn.Dropout(),
               nn.Linear(256 * 6 * 6, 4096),
               nn.ReLU(inplace=True),
               nn.Dropout(),
               nn.Linear(4096, 4096),
               nn.ReLU(inplace=True),
               nn.Linear(4096, num_classes),
           )
       
       
   def forward(self, x):
       x = self.features(x)
       x=self.se(x)
       if self.num_classes > 0:
           x = x.view(x.size(0), 256 * 6 * 6)
           x = self.classifier(x)

       return (x, )
```

这样添加是没有问题的对吗?按照意思实际上SE模块添加在最后一个卷积层池化之后的位置是吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant