| 28 | |
| 29 | |
| 30 | class CRAFT(nn.Module): |
| 31 | def __init__(self, pretrained=False, freeze=False): |
| 32 | super(CRAFT, self).__init__() |
| 33 | |
| 34 | """ Base network """ |
| 35 | self.basenet = vgg16_bn(pretrained, freeze) |
| 36 | |
| 37 | """ U network """ |
| 38 | self.upconv1 = double_conv(1024, 512, 256) |
| 39 | self.upconv2 = double_conv(512, 256, 128) |
| 40 | self.upconv3 = double_conv(256, 128, 64) |
| 41 | self.upconv4 = double_conv(128, 64, 32) |
| 42 | |
| 43 | num_class = 2 |
| 44 | self.conv_cls = nn.Sequential( |
| 45 | nn.Conv2d(32, 32, kernel_size=3, padding=1), nn.ReLU(inplace=True), |
| 46 | nn.Conv2d(32, 32, kernel_size=3, padding=1), nn.ReLU(inplace=True), |
| 47 | nn.Conv2d(32, 16, kernel_size=3, padding=1), nn.ReLU(inplace=True), |
| 48 | nn.Conv2d(16, 16, kernel_size=1), nn.ReLU(inplace=True), |
| 49 | nn.Conv2d(16, num_class, kernel_size=1), |
| 50 | ) |
| 51 | |
| 52 | init_weights(self.upconv1.modules()) |
| 53 | init_weights(self.upconv2.modules()) |
| 54 | init_weights(self.upconv3.modules()) |
| 55 | init_weights(self.upconv4.modules()) |
| 56 | init_weights(self.conv_cls.modules()) |
| 57 | |
| 58 | def forward(self, x): |
| 59 | """ Base network """ |
| 60 | sources = self.basenet(x) |
| 61 | |
| 62 | """ U network """ |
| 63 | y = torch.cat([sources[0], sources[1]], dim=1) |
| 64 | y = self.upconv1(y) |
| 65 | |
| 66 | y = F.interpolate(y, size=sources[2].size()[2:], mode='bilinear', align_corners=False) |
| 67 | y = torch.cat([y, sources[2]], dim=1) |
| 68 | y = self.upconv2(y) |
| 69 | |
| 70 | y = F.interpolate(y, size=sources[3].size()[2:], mode='bilinear', align_corners=False) |
| 71 | y = torch.cat([y, sources[3]], dim=1) |
| 72 | y = self.upconv3(y) |
| 73 | |
| 74 | y = F.interpolate(y, size=sources[4].size()[2:], mode='bilinear', align_corners=False) |
| 75 | y = torch.cat([y, sources[4]], dim=1) |
| 76 | feature = self.upconv4(y) |
| 77 | |
| 78 | y = self.conv_cls(feature) |
| 79 | |
| 80 | return y.permute(0,2,3,1), feature |
no outgoing calls
no test coverage detected
searching dependent graphs…