MCPcopy Create free account
hub / github.com/SLDGroup/MERIT / __init__

Method __init__

lib/networks.py:633–676  ·  view source on GitHub ↗
(self, n_class=1, img_size_s1=(256,256), img_size_s2=(224,224), decoder_aggregation='additive', interpolation='bilinear')

Source from the content-addressed store, hash-verified

631
632class MERIT_Parallel_Small(nn.Module):
633 def __init__(self, n_class=1, img_size_s1=(256,256), img_size_s2=(224,224), decoder_aggregation='additive', interpolation='bilinear'):
634 super(MERIT_Parallel_Small, self).__init__()
635
636 self.interpolation = interpolation
637 self.img_size_s1 = img_size_s1
638 self.img_size_s2 = img_size_s2
639
640 # conv block to convert single channel to 3 channels
641 self.conv = nn.Sequential(
642 nn.Conv2d(1, 3, kernel_size=1),
643 nn.BatchNorm2d(3),
644 nn.ReLU(inplace=True)
645 )
646
647 # backbone network initialization with pretrained weight
648 #self.backbone = maxvit_tiny_rw_224_4out() # [64, 128, 320, 512]
649 self.backbone1 = maxxvit_rmlp_small_rw_256_4out() # [64, 128, 320, 512]
650 self.backbone2 = maxvit_rmlp_small_rw_224_4out() # [64, 128, 320, 512]
651
652 print('Loading:', './pretrained_pth/maxvit/maxxvit_rmlp_small_rw_256_sw-37e217ff.pth')
653 state_dict1 = torch.load('./pretrained_pth/maxvit/maxxvit_rmlp_small_rw_256_sw-37e217ff.pth')
654 self.backbone1.load_state_dict(state_dict1, strict=False)
655
656 print('Loading:', './pretrained_pth/maxvit/maxvit_rmlp_small_rw_224_sw-6ef0ae4f.pth')
657 state_dict2 = torch.load('./pretrained_pth/maxvit/maxvit_rmlp_small_rw_224_sw-6ef0ae4f.pth')
658 self.backbone2.load_state_dict(state_dict2, strict=False)
659
660 print('Pretrain weights loaded.')
661
662 #channels=[512, 256, 128, 64]
663 channels = [768, 384, 192, 96]
664 # decoder initialization
665 if(decoder_aggregation=='additive'):
666 self.decoder = CASCADE_Add(channels=channels)
667 elif(self.decoder_aggregation=='concatenation'):
668 self.decoder = CASCADE_Cat(channels=self.channels)
669 else:
670 sys.exit("'"+self.decoder_aggregation+"' is not a valid decoder aggregation! Currently supported aggregations are 'additive' and 'concatenation'.")
671
672 # Prediction heads initialization
673 self.out_head1 = nn.Conv2d(channels[0], n_class, 1)
674 self.out_head2 = nn.Conv2d(channels[1], n_class, 1)
675 self.out_head3 = nn.Conv2d(channels[2], n_class, 1)
676 self.out_head4 = nn.Conv2d(channels[3], n_class, 1)
677
678 def forward(self, x, im1_size=(256,256), im2_size=(224,224)):
679

Callers

nothing calls this directly

Calls 3

CASCADE_AddClass · 0.90
CASCADE_CatClass · 0.90
__init__Method · 0.45

Tested by

no test coverage detected