-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Request Mobilenet fpn #1999
Comments
Hi, There are two issues with your implementation:
Here is a working version class FPNMobileNet(nn.Module):
def __init__(self, pretrained=True):
super().__init__()
net = MobileNetV2(pretrained)
features = net.features
self.layer1= nn.Sequential(*features[0:4])
self.layer2 = nn.Sequential(*features[4:7])
self.layer3 = nn.Sequential(*features[7:11])
self.layer4 = nn.Sequential(*features[11:19])
for param in features.parameters():
param.requires_grad = False
def forward(self, x):
# Bottom-up pathway, from ResNet
enc0 = self.layer1(x) # 24
enc1 = self.layer2(enc0) # 32
enc2 = self.layer3(enc1) # 64
enc3 = self.layer4(enc2) # 1280
return enc3
def mobilenet_fpn_backbone(pretrained):
backbone = FPNMobileNet(pretrained)
# freeze layers
for name, parameter in backbone.named_parameters():
if 'layer2' not in name and 'layer3' not in name and 'layer4' not in name:
parameter.requires_grad_(False)
return_layers = {'layer1': 0, 'layer2': 1, 'layer3': 2, 'layer4': 3}
in_channels_list = [
24, 32, 64, 1280
]
out_channels = 256
return BackboneWithFPN(backbone, return_layers, in_channels_list, out_channels) |
It works, many thanks! |
@fmassa Hi, I want ask if I want extract certain layers usign for example: in mobilenetv2, take the 4th layer, should be |
|
🚀 Feature
Hi I want to write mobilenet fpn.
Motivation
Improve MaskRCNN speed and accuracy.
Pitch
Alternatives
Additional context
Code:
/torchvision/models/detection/backbone_utils.py
/torchvision/models/detection/mobilenet_fpn.py
demo.py
Bug:
"RuntimeError: Given groups=1, weight of size 32 3 3 3, expected input[1, 1280, 4, 4] to have 3 channels, but got 1280 channels instead"
The text was updated successfully, but these errors were encountered: