def __init__(self,nInputChannels=3, n_classes=7, os=16,input_channels=256,hidden_layers=128,out_channels=256): super(deeplab_xception_transfer_basemodel_synBN_savememory, self).__init__(nInputChannels=nInputChannels, n_classes=n_classes, os=os, ) ### source graph # self.source_featuremap_2_graph = gcn.Featuremaps_to_Graph(input_channels=input_channels, hidden_layers=hidden_layers, # nodes=n_classes) # self.source_graph_conv1 = gcn.GraphConvolution(hidden_layers, hidden_layers) # self.source_graph_conv2 = gcn.GraphConvolution(hidden_layers, hidden_layers) # self.source_graph_conv3 = gcn.GraphConvolution(hidden_layers, hidden_layers) # # self.source_graph_2_fea = gcn.Graph_to_Featuremaps(input_channels=input_channels, output_channels=out_channels, # hidden_layers=hidden_layers, nodes=n_classes # ) # self.source_skip_conv = nn.Sequential(*[nn.Conv2d(input_channels, input_channels, kernel_size=1), # nn.ReLU(True)]) ### target graph self.target_featuremap_2_graph = gcn.Featuremaps_to_Graph(input_channels=input_channels, hidden_layers=hidden_layers, nodes=n_classes) self.target_graph_conv1 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.target_graph_conv2 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.target_graph_conv3 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.target_graph_2_fea = gcn.Graph_to_Featuremaps_savemem(input_channels=input_channels, output_channels=out_channels, hidden_layers=hidden_layers, nodes=n_classes ) self.target_skip_conv = nn.Sequential(*[nn.Conv2d(input_channels, input_channels, kernel_size=1), nn.BatchNorm2d(input_channels), nn.ReLU(True)])
def __init__( self, nInputChannels=3, n_classes=7, os=16, input_channels=256, hidden_layers=128, out_channels=256, transfer_graph=None, source_classes=20, ): super(deeplab_xception_transfer_projection_savemem, self).__init__( nInputChannels=nInputChannels, n_classes=n_classes, os=os, input_channels=input_channels, hidden_layers=hidden_layers, out_channels=out_channels, ) self.source_featuremap_2_graph = gcn.Featuremaps_to_Graph( input_channels=input_channels, hidden_layers=hidden_layers, nodes=source_classes, ) self.source_graph_conv1 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.source_graph_conv2 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.source_graph_conv3 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.transpose_graph = gcn.Graph_trans( in_features=hidden_layers, out_features=hidden_layers, adj=transfer_graph, begin_nodes=source_classes, end_nodes=n_classes, ) self.fc_graph = gcn.GraphConvolution(hidden_layers * 3, hidden_layers)
def __init__(self, n_classes, hidden_layers, gcn_mode=2, device='cpu'): super(DeepLabv3_plus_gcn_skipconnection_3d_subnet2, self).__init__() self.device = device self.gcn_mode = gcn_mode self.feature_projection_conv2 = nn.Conv3d(32, 64, 1, bias=False) self.feature_projection_bn2 = nn.BatchNorm3d(64) self.relu = nn.ReLU() if self.gcn_mode == 0: self.featuremap_2_graph = gcn.Featuremaps_to_Graph( input_channels=128, hidden_layers=hidden_layers, nodes=n_classes) self.graph_conv1 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.graph_conv2 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.graph_conv3 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.graph_2_fea = gcn.Graph_to_Featuremaps_savemem( input_channels=128, output_channels=128, hidden_layers=hidden_layers, nodes=n_classes) elif self.gcn_mode == 1: self.global_reasoning_unit = GloRe_Unit_3D(num_in=128, num_s=128, num_n=64) elif self.gcn_mode == 2: self.featuremap_2_graph = gcn.My_Featuremaps_to_Graph( input_channels=128, hidden_layers=hidden_layers, nodes=n_classes) self.graph_conv1 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.graph_conv2 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.graph_conv3 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.graph_2_fea = gcn.My_Graph_to_Featuremaps( hidden_layers=hidden_layers, output_channels=128) self.skip_conv = nn.Sequential( *[nn.Conv3d(128, 128, kernel_size=1), nn.ReLU(True)])
def __init__(self, nInputChannels=3, n_classes=21, os=16, pretrained=False, _print=True, final_sigmoid=False, hidden_layers=128, gcn_mode=0, device=None): if _print: print("Constructing DeepLabv3+ model...") print("Number of classes: {}".format(n_classes)) print("Output stride: {}".format(os)) print("Number of Input Channels: {}".format(nInputChannels)) super(DeepLabv3_plus_gcn_skipconnection_2d, self).__init__() self.in_channels = nInputChannels self.gcn_mode = gcn_mode self.device = device # Atrous Conv self.xception_features = Xception(nInputChannels, os, pretrained) # ASPP if os == 16: rates = [1, 6, 12, 18] elif os == 8: rates = [1, 12, 24, 36] raise NotImplementedError else: raise NotImplementedError self.aspp1 = ASPP_module_rate0(1024, 128, rate=rates[0]) self.aspp2 = ASPP_module(1024, 128, rate=rates[1]) self.aspp3 = ASPP_module(1024, 128, rate=rates[2]) self.aspp4 = ASPP_module(1024, 128, rate=rates[3]) self.relu = nn.ReLU() self.global_avg_pool = nn.Sequential( nn.AdaptiveAvgPool2d((1, 1)), nn.Conv2d(1024, 128, 1, stride=1, bias=False), nn.BatchNorm2d(128), nn.ReLU()) self.concat_projection_conv1 = nn.Conv2d(640, 128, 1, bias=False) self.concat_projection_bn1 = nn.BatchNorm2d(128) # adopt [1x1, 48] for channel reduction. self.feature_projection_conv1 = nn.Conv2d(128, 24, 1, bias=False) self.feature_projection_bn1 = nn.BatchNorm2d(24) self.feature_projection_conv2 = nn.Conv2d(32, 64, 1, bias=False) self.feature_projection_bn2 = nn.BatchNorm2d(64) self.decoder1 = nn.Sequential(Decoder_module(152, 128), Decoder_module(128, 128)) self.decoder2 = nn.Sequential(Decoder_module(192, 256), Decoder_module(256, 256)) if self.gcn_mode == 0: self.featuremap_2_graph = gcn.Featuremaps_to_Graph( input_channels=128, hidden_layers=hidden_layers, nodes=n_classes) self.graph_conv1 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.graph_conv2 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.graph_conv3 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.graph_2_fea = gcn.Graph_to_Featuremaps_savemem( input_channels=128, output_channels=128, hidden_layers=hidden_layers, nodes=n_classes) elif self.gcn_mode == 1: self.global_reasoning_unit = GloRe_Unit_2D(num_in=128, num_s=128, num_n=64) elif self.gcn_mode == 2: self.featuremap_2_graph = gcn.My_Featuremaps_to_Graph( input_channels=128, hidden_layers=hidden_layers, nodes=n_classes) self.graph_conv1 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.graph_conv2 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.graph_conv3 = gcn.GraphConvolution(hidden_layers, hidden_layers) self.graph_2_fea = gcn.My_Graph_to_Featuremaps( hidden_layers=hidden_layers, output_channels=128, dimension=2) self.skip_conv = nn.Sequential( *[nn.Conv2d(128, 128, kernel_size=1), nn.ReLU(True)]) self.semantic = nn.Conv2d(256, n_classes, kernel_size=1, stride=1) if final_sigmoid: self.final_activation = nn.Sigmoid() else: self.final_activation = nn.Softmax(dim=1)