Пример #1
0
    def __init__(self, num_classes, context_path):
        super().__init__()
        # build spatial path
        self.saptial_path = Spatial_path()

        # build context path
        self.context_path = build_contextpath(name=context_path)

        # build attention refinement module  for resnet 101
        if context_path == 'resnet101':
            self.attention_refinement_module1 = AttentionRefinementModule(1024, 1024)
            self.attention_refinement_module2 = AttentionRefinementModule(2048, 2048)
            # supervision block
            self.supervision1 = nn.Conv2d(in_channels=1024, out_channels=num_classes, kernel_size=1)
            self.supervision2 = nn.Conv2d(in_channels=2048, out_channels=num_classes, kernel_size=1)
            # build feature fusion module
            self.feature_fusion_module = FeatureFusionModule(num_classes, 3328)

        elif context_path == 'resnet18':
            # build attention refinement module  for resnet 18
            self.attention_refinement_module1 = AttentionRefinementModule(256, 256)
            self.attention_refinement_module2 = AttentionRefinementModule(512, 512)
            # supervision block
            self.supervision1 = nn.Conv2d(in_channels=256, out_channels=num_classes, kernel_size=1)
            self.supervision2 = nn.Conv2d(in_channels=512, out_channels=num_classes, kernel_size=1)
            # build feature fusion module
            self.feature_fusion_module = FeatureFusionModule(num_classes, 1024)
        else: 
            print('Error: unspport context_path network \n')

        # build final convolution
        self.conv = nn.Conv2d(in_channels=num_classes, out_channels=num_classes, kernel_size=1)
Пример #2
0
    def __init__(self, num_classes, num_char, context_path):
        super().__init__()
        # build spatial path
        self.saptial_path = Spatial_path()

        # build context path
        self.context_path = build_contextpath(name=context_path)

        # build attention refinement module
        if context_path == 'resnet101':
            self.attention_refinement_module1 = AttentionRefinementModule(
                1024, 1024)
            self.attention_refinement_module2 = AttentionRefinementModule(
                2048, 2048)
            self.feature_fusion_module1 = FeatureFusionModule(
                num_classes, 3328)
            self.feature_fusion_module2 = FeatureFusionModule(num_char, 3328)
        else:
            self.attention_refinement_module1 = AttentionRefinementModule(
                256, 256)
            self.attention_refinement_module2 = AttentionRefinementModule(
                512, 512)
            self.feature_fusion_module1 = FeatureFusionModule(
                num_classes, 1024)
            self.feature_fusion_module2 = FeatureFusionModule(num_char, 1024)
        # build final convolution
        self.conv_seg = nn.Conv2d(in_channels=num_classes,
                                  out_channels=num_classes,
                                  kernel_size=1)
        self.conv_pos = nn.Conv2d(in_channels=num_char,
                                  out_channels=num_char,
                                  kernel_size=1)
Пример #3
0
    def __init__(self, num_classes, context_path):
        super().__init__()
        # build spatial path
        self.saptial_path = Spatial_path()

        # build context path
        self.context_path = build_contextpath(name=context_path)

        # build attention refinement module
        self.attention_refinement_module1 = AttentionRefinementModule(1024, 1024)
        self.attention_refinement_module2 = AttentionRefinementModule(2048, 2048)

        # build feature fusion module
        self.feature_fusion_module = FeatureFusionModule(num_classes)

        # build final convolution
        self.conv = nn.Conv2d(in_channels=num_classes, out_channels=num_classes, kernel_size=1)

        # supervision block
        self.supervision1 = nn.Conv2d(in_channels=1024, out_channels=num_classes, kernel_size=1)
        self.supervision2 = nn.Conv2d(in_channels=2048, out_channels=num_classes, kernel_size=1)
Пример #4
0
    def __init__(self, num_classes, context_path, in_channel=3):
        super().__init__()
        # build context path
        self.context_path = build_contextpath(name=context_path, in_channel=in_channel)

        # build attention refinement module
        if context_path in ['resnet18', 'resnet34']:
            self.attention_refinement_module0 = AttentionRefinementModule(128, 128)
            self.attention_refinement_module1 = AttentionRefinementModule(256, 256)
            self.attention_refinement_module2 = AttentionRefinementModule(512, 512)
            n_ch = 512
        elif context_path in ['xception']:
            self.attention_refinement_module0 = AttentionRefinementModule(256, 256)
            self.attention_refinement_module1 = AttentionRefinementModule(728, 728)
            self.attention_refinement_module2 = AttentionRefinementModule(1024, 1024)
            n_ch = 1024
        else:
            self.attention_refinement_module0 = AttentionRefinementModule(512, 512)
            self.attention_refinement_module1 = AttentionRefinementModule(1024, 1024)
            self.attention_refinement_module2 = AttentionRefinementModule(2048, 2048)
            n_ch = 2048

        # build feature fusion module
        self.feature_fusion_module = FeatureFusionModule(num_classes, context_path)

        # build final convolution
        self.conv = nn.Conv2d(in_channels=num_classes, out_channels=num_classes, kernel_size=1)
        self.cls = nn.Linear(in_features=n_ch, out_features=num_classes-1)

        # supervision block
        if context_path in ['resnet18', 'resnet34']:
            self.supervision1 = nn.Conv2d(in_channels=256, out_channels=num_classes, kernel_size=1)
            self.supervision2 = nn.Conv2d(in_channels=512, out_channels=num_classes, kernel_size=1)
        elif context_path in ['xception']:
            self.supervision1 = nn.Conv2d(in_channels=728, out_channels=num_classes, kernel_size=1)
            self.supervision2 = nn.Conv2d(in_channels=1024, out_channels=num_classes, kernel_size=1)
        else:
            self.supervision1 = nn.Conv2d(in_channels=1024, out_channels=num_classes, kernel_size=1)
            self.supervision2 = nn.Conv2d(in_channels=2048, out_channels=num_classes, kernel_size=1)
Пример #5
0
    def __init__(self, num_classes, num_char, context_path):
        super().__init__()
        # build spatial path
        self.saptial_path = Spatial_path()

        # build context path
        self.context_path = build_contextpath(name=context_path)

        # build attention refinement module
        if context_path == 'resnet101':
            self.attention_refinement_module1 = AttentionRefinementModule(
                1024, 1024)
            self.attention_refinement_module2 = AttentionRefinementModule(
                2048, 2048)
            self.feature_fusion_module1 = FeatureFusionModule(
                num_classes, 3328)
            self.feature_fusion_module2 = FeatureFusionModule(num_char, 3328)
        else:
            self.attention_refinement_module1 = AttentionRefinementModule(
                256, 256)
            self.attention_refinement_module2 = AttentionRefinementModule(
                512, 512)
            self.feature_fusion_module1 = FeatureFusionModule(
                num_classes, 1024)
            self.feature_fusion_module2 = FeatureFusionModule(num_char, 1024)
        # build final convolution
        self.conv_seg = nn.Conv2d(in_channels=num_classes,
                                  out_channels=num_classes,
                                  kernel_size=1)
        self.conv_pos = nn.Conv2d(in_channels=num_char,
                                  out_channels=num_char,
                                  kernel_size=1)

        self.convblock = nn.Sequential(
            ConvBlock(in_channels=num_classes - 1,
                      out_channels=1000,
                      kernel_size=5,
                      stride=4,
                      padding=2),
            nn.AdaptiveAvgPool2d((1, 1)),
        )
        # self.convblock1 = nn.Sequential(
        #     ConvBlock(in_channels=num_classes-1, out_channels=256, kernel_size=5, stride=4, padding=2),
        #     ConvBlock(in_channels=256, out_channels=1000, kernel_size=5, stride=4, padding=2),
        #     nn.AdaptiveAvgPool2d((1, 1)),
        #     )
        # self.convblock2 = nn.Sequential(
        #     ConvBlock(in_channels=num_classes-42, out_channels=1000, kernel_size=5, stride=4, padding=2),
        #     nn.AdaptiveAvgPool2d((1, 1)),
        #     )
        # self.convblock3 = nn.Sequential(
        #     ConvBlock(in_channels=num_classes-32, out_channels=1000, kernel_size=5, stride=4, padding=2),
        #     nn.AdaptiveAvgPool2d((1, 1)),
        #     )

        self.classifier1 = nn.Linear(1000, provNum)
        self.classifier2 = nn.Linear(1000, alphaNum)
        self.classifier3 = nn.Linear(1000, adNum)
        self.classifier4 = nn.Linear(1000, adNum)
        self.classifier5 = nn.Linear(1000, adNum)
        self.classifier6 = nn.Linear(1000, adNum)
        self.classifier7 = nn.Linear(1000, adNum)