| 6 | |
| 7 | |
| 8 | class slam(nn.Module): |
| 9 | def __init__(self, spatial_dim): |
| 10 | super(slam,self).__init__() |
| 11 | self.spatial_dim = spatial_dim |
| 12 | self.linear = nn.Sequential( |
| 13 | nn.Linear(spatial_dim**2,512), |
| 14 | nn.ReLU(), |
| 15 | nn.Linear(512,1), |
| 16 | nn.Sigmoid() |
| 17 | ) |
| 18 | |
| 19 | def forward(self, feature): |
| 20 | n,c,h,w = feature.shape |
| 21 | if (h != self.spatial_dim): |
| 22 | x = F.interpolate(feature,size=(self.spatial_dim,self.spatial_dim),mode= "bilinear", align_corners=True) |
| 23 | else: |
| 24 | x = feature |
| 25 | |
| 26 | |
| 27 | x = x.view(n,c,-1) |
| 28 | x = self.linear(x) |
| 29 | x = x.unsqueeze(dim =3) |
| 30 | out = x.expand_as(feature)*feature |
| 31 | |
| 32 | return out |
| 33 | |
| 34 | |
| 35 | class to_map(nn.Module): |