-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewmodel.py
More file actions
23 lines (18 loc) · 908 Bytes
/
Copy pathnewmodel.py
File metadata and controls
23 lines (18 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import torchvision
from torchvision.models.detection.faster_rcnn import FastRCNNPredictor
from torchvision.models.detection.mask_rcnn import MaskRCNNPredictor
from fsanet import FrequencySelfAttention
import torch
def get_fsanet_model(num_classes=2):
model = torchvision.models.detection.maskrcnn_resnet50_fpn(weights="DEFAULT")
backbone_final_layer = model.backbone.body.layer4
model.backbone.body.layer4 = torch.nn.Sequential(
backbone_final_layer,
FrequencySelfAttention(in_channels=2048, k=16)
)
in_features = model.roi_heads.box_predictor.cls_score.in_features
model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)
in_features_mask = model.roi_heads.mask_predictor.conv5_mask.in_channels
hidden_layer = 256
model.roi_heads.mask_predictor = MaskRCNNPredictor(in_features_mask, hidden_layer, num_classes)
return model