(self, x)
| 463 | self.out_head4 = nn.Conv2d(self.channels[3], self.n_class, 1) |
| 464 | |
| 465 | def forward(self, x): |
| 466 | |
| 467 | # if grayscale input, convert to 3 channels |
| 468 | if x.size()[1] == 1: |
| 469 | x = self.conv(x) |
| 470 | |
| 471 | # transformer backbone as encoder |
| 472 | f1 = self.backbone1(F.interpolate(x, size=self.img_size_s1, mode=self.interpolation)) |
| 473 | #print([f1[3].shape,f1[2].shape,f1[1].shape,f1[0].shape]) |
| 474 | |
| 475 | f2 = self.backbone2(F.interpolate(x, size=self.img_size_s2, mode=self.interpolation)) |
| 476 | #print([f2[3].shape,f2[2].shape,f2[1].shape,f2[0].shape]) |
| 477 | |
| 478 | # decoder |
| 479 | x11_o, x12_o, x13_o, x14_o = self.decoder(f1[3], [f1[2], f1[1], f1[0]]) |
| 480 | |
| 481 | x21_o, x22_o, x23_o, x24_o = self.decoder(f2[3], [f2[2], f2[1], f2[0]]) |
| 482 | |
| 483 | # prediction heads |
| 484 | p11 = self.out_head1(x11_o) |
| 485 | p12 = self.out_head2(x12_o) |
| 486 | p13 = self.out_head3(x13_o) |
| 487 | p14 = self.out_head4(x14_o) |
| 488 | #print([p11.shape,p12.shape,p13.shape,p14.shape]) |
| 489 | |
| 490 | p21 = self.out_head1(x21_o) |
| 491 | p22 = self.out_head2(x22_o) |
| 492 | p23 = self.out_head3(x23_o) |
| 493 | p24 = self.out_head4(x24_o) |
| 494 | #print([p21.shape,p22.shape,p23.shape,p24.shape]) |
| 495 | |
| 496 | p11 = F.interpolate(p11, scale_factor=32, mode=self.interpolation) |
| 497 | p12 = F.interpolate(p12, scale_factor=16, mode=self.interpolation) |
| 498 | p13 = F.interpolate(p13, scale_factor=8, mode=self.interpolation) |
| 499 | p14 = F.interpolate(p14, scale_factor=4, mode=self.interpolation) |
| 500 | |
| 501 | p21 = F.interpolate(p21, size=(p11.shape[-2:]), mode=self.interpolation) |
| 502 | p22 = F.interpolate(p22, size=(p12.shape[-2:]), mode=self.interpolation) |
| 503 | p23 = F.interpolate(p23, size=(p13.shape[-2:]), mode=self.interpolation) |
| 504 | p24 = F.interpolate(p24, size=(p14.shape[-2:]), mode=self.interpolation) |
| 505 | |
| 506 | p1 = p11 + p21 |
| 507 | p2 = p12 + p22 |
| 508 | p3 = p13 + p23 |
| 509 | p4 = p14 + p24 |
| 510 | #print([p1.shape,p2.shape,p3.shape,p4.shape]) |
| 511 | |
| 512 | return p1, p2, p3, p4 |
| 513 | |
| 514 | class MERIT_Cascaded(nn.Module): |
| 515 | def __init__(self, n_class=1, img_size_s1=(256,256), img_size_s2=(224,224), model_scale='small', decoder_aggregation='additive', interpolation='bilinear'): |
nothing calls this directly
no outgoing calls
no test coverage detected