def __init__(self,
              block=Bottleneck,
              layers=[3, 4, 6, 3],
              nb_classes=40,
              channel=3):
     self.inplanes = 64
     super(ResNet, self).__init__()
     self.conv1_custom = nn.Conv2d(channel,
                                   64,
                                   kernel_size=7,
                                   stride=2,
                                   padding=3,
                                   bias=False)
     self.bn1 = nn.BatchNorm2d(64)
     self.relu = nn.ReLU(inplace=True)
     self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
     self.layer1 = self._make_layer(block, 64, layers[0])
     self.layer2 = self._make_layer(block, 128, layers[1], stride=2)
     self.layer3 = self._make_layer(block, 256, layers[2], stride=2)
     self.layer4 = self._make_layer(block, 512, layers[3], stride=2)
     self.avgpool = nn.AvgPool2d(2)
     #self.maxpool = nn.MaxPool2d(kernel_size=7,stride=2)
     #self.channelpool = nn.AvgPool1d(1)
     #self.bn_global = nn.BatchNorm1d(2048)
     #self.fc_custom = nn.Linear(512 * block.expansion, nb_classes)
     #self.fc_pool = nn.Conv1d(50,1,kernel_size=1,stride=1)
     #self.fc_s = nn.Linear(2048,nb_classes)
     self.extractor = SingleRoIExtractor(dict(type='RoIAlign',
                                              out_size=7,
                                              sample_num=1),
                                         out_channels=512,
                                         featmap_strides=[
                                             4,
                                         ])
     self.attention = MultiHeadAttention(1, 2048, 512, 512)
     self.fc_roi = nn.Linear(2048 * 16, 40)
     self.bn2 = nn.BatchNorm2d(2048)
     #self.fc_global = nn.Linear(2048*7*7,2048)
     #self.fc_s2 = nn.Linear(1024,nb_classes)
     #self.conv_end = nn.Conv2d(1,1,kernel_size=(16,1),stride=1)
     for m in self.modules():
         if isinstance(m, nn.Conv2d):
             n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
             m.weight.data.normal_(0, math.sqrt(2. / n))
         elif isinstance(m, nn.BatchNorm2d):
             m.weight.data.fill_(1)
             m.bias.data.zero_()
 def __init__(self, block, layers, num_classes=40):
     self.inplanes = 64
     super(ResNet, self).__init__()
     self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3,
                            bias=False)
     self.bn1 = nn.BatchNorm2d(64)
     self.relu = nn.ReLU(inplace=True)
     self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
     self.layer1 = self._make_layer(block, 64, layers[0])
     self.layer2 = self._make_layer(block, 128, layers[1], stride=2)
     self.layer3 = self._make_layer(block, 256, layers[2], stride=2)
     self.layer4 = self._make_layer(block, 512, layers[3], stride=2)
     self.conv1g = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3,
                            bias=False)
     self.bn1g = nn.BatchNorm2d(64)
     self.relug = nn.ReLU(inplace=True)
     self.maxpoolg = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
     self.layer1g = self.layer1
     self.layer2g = self.layer2
     self.layer3g = self.layer3
     self.layer4g = self.layer4
     self.avgpooll = nn.AvgPool2d(2)
     self.avgpoolg = nn.AvgPool2d(7)
     #self.fcadd = nn.Linear(2048,2048)
     #self.atn_s1 = MultiHeadAttention(56*56,256,64,64)
     #self.atn_s2 = MultiHeadAttention(28*28,512,128,128)
     self.atn_s4 = MultiHeadAttention(1,2048*2*2,512,512)
     #self.atn_s3 = MultiHeadAttention(14*14,1024,256,256)
     # self.fc_aux = nn.Linear(512 * block.expansion, 101)
     self.dp = nn.Dropout(p=0.8)
     self.fc_g = nn.Linear(512 * block.expansion, num_classes)
     self.fc_l = nn.Linear(512 * block.expansion, num_classes)
     # self.bn_final = nn.BatchNorm1d(num_classes)
     # self.fc2 = nn.Linear(num_classes, num_classes)
     # self.fc_final = nn.Linear(num_classes, 101)
     self.extractor = SingleRoIExtractor(dict(type='RoIAlign', out_size=2, sample_num=1),out_channels=2048,
                                        featmap_strides=[32, ]
                                        )
     for m in self.modules():
         if isinstance(m, nn.Conv2d):
             n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
             m.weight.data.normal_(0, math.sqrt(2. / n))
         elif isinstance(m, nn.BatchNorm2d):
             m.weight.data.fill_(1)
             m.bias.data.zero_()
 def __init__(self):
     super(proposalModel, self).__init__()
     self.backbone = ResNet(101, 4, out_indices=(
         1,
         3,
     ))  # int obj不可迭代,加个 ,
     self.roiextract = SingleRoIExtractor(roi_layer=dict(type='RoIAlign',
                                                         out_size=7,
                                                         sample_num=2),
                                          out_channels=512,
                                          featmap_strides=[
                                              8,
                                          ])  # 没有FPN 所以只有一个步长
     self.fc = nn.Linear(2048 + 2048, 40)
     self.backbone.init_weights(
         pretrained='/home/share/LabServer/GLnet/MODELZOO/resnet50.pth')
     self.conv1 = nn.Conv2d(512, 1024, 3, 1)
     self.conv2 = nn.Conv2d(1024, 2048, 3, 1)
Ejemplo n.º 4
0
 def __init__(self,
              roi_out_size=7,
              roi_sample_num=2,
              channels=256,
              strides=[4, 8, 16, 32],
              featmap_num=5):
     super(RPN_Modulator, self).__init__()
     self.roi_extractor = SingleRoIExtractor(roi_layer={
         'type': 'RoIAlign',
         'out_size': roi_out_size,
         'sample_num': roi_sample_num
     },
                                             out_channels=channels,
                                             featmap_strides=strides)
     self.proj_modulator = nn.ModuleList([
         nn.Conv2d(channels, channels, roi_out_size, padding=0)
         for _ in range(featmap_num)
     ])
     self.proj_out = nn.ModuleList([
         nn.Conv2d(channels, channels, 1, padding=0)
         for _ in range(featmap_num)
     ])
 def __init__(self):
     super(proposalModel_scene, self).__init__()
     self.HIGHSCENE = [
         3, 4, 6, 7, 9, 10, 13, 12, 11, 16, 24, 25, 26, 32, 39
     ]
     self.backbone = ResNet(50, 4, out_indices=(
         1,
         3,
     ))  # int obj不可迭代,加个 ,
     self.roiextract = SingleRoIExtractor(roi_layer=dict(type='RoIAlign',
                                                         out_size=7,
                                                         sample_num=2),
                                          out_channels=512,
                                          featmap_strides=[
                                              8,
                                          ])  # 没有FPN 所以只有一个步长
     self.fc_high = nn.Linear(2048 + 1024, 40)
     self.fc_low = nn.Linear(1024 + 1024, 40)
     self.conv1 = nn.Conv2d(512, 1024, 3, 1, 0)
     self.conv2 = nn.Conv2d(1024, 2048, 3, 1, 0)
     self.backbone.init_weights(
         pretrained='/home/share/LabServer/GLnet/MODELZOO/resnet50.pth')
 def __init__(self,
              block=Bottleneck,
              layers=[3, 4, 6, 3],
              nb_classes=40,
              channel=3):
     self.inplanes = 64
     super(ResNet, self).__init__()
     self.conv1_custom = nn.Conv2d(channel,
                                   64,
                                   kernel_size=7,
                                   stride=2,
                                   padding=3,
                                   bias=False)
     self.bn1 = nn.BatchNorm2d(64)
     self.relu = nn.ReLU(inplace=True)
     self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
     self.layer1 = self._make_layer(block, 64, layers[0])
     self.layer2 = self._make_layer(block, 128, layers[1], stride=2)
     self.layer3 = self._make_layer(block, 256, layers[2], stride=2)
     self.layer4 = self._make_layer(block, 512, layers[3], stride=2)
     self.avgpool = nn.AvgPool2d(7)
     self.maxpool = nn.MaxPool2d(kernel_size=7, stride=2)
     self.channelpool = nn.AvgPool1d(100)
     #self.fc_custom = nn.Linear(512 * block.expansion, nb_classes)
     #self.fc_at1 = nn.Linear(1024,nb_classes)
     #self.fc_at2 = nn.Linear(2048,nb_classes)
     """
     self.conv_lower = nn.Sequential(OrderedDict([
         ('con1',nn.Conv2d(1024,521,kernel_size=3,stride=2,padding=1)),
         ('bn1',nn.BatchNorm2d(521)),
         ('relu1',nn.ReLU()),
                                     ('conv2',(nn.Conv2d(521,256,kernel_size=3,stride=1,padding=1))),
         ('bn2',nn.BatchNorm2d(256)),
         ('relu2',nn.ReLU()),
                                     ('conv3',(nn.Conv2d(256,10,kernel_size=1,stride=1,padding=0))),
         ('bn3',nn.BatchNorm2d(10)),
         ('relu3',nn.ReLU()),
                                     ('conv4',(nn.Conv2d(10,1,kernel_size=1,stride=1))),
         ('relu4',nn.ReLU()),
                                     ]))
     """
     #self.conv_atten = self.layer4
     #self.layer3_main = self.layer3
     #self.layer4_main = self.layer4
     self.fc_custom = nn.Linear(2048 * 2, nb_classes)
     self.extractor = SingleRoIExtractor(dict(type='RoIAlign',
                                              out_size=3,
                                              sample_num=2),
                                         out_channels=1024,
                                         featmap_strides=[
                                             16,
                                         ])
     self.attention_op = MultiHeadAttention(1, 2048, 2048, 2048)
     self.convx = nn.Conv2d(1024, 2048, kernel_size=3, stride=2)
     for m in self.modules():
         if isinstance(m, nn.Conv2d):
             n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
             m.weight.data.normal_(0, math.sqrt(2. / n))
         elif isinstance(m, nn.BatchNorm2d):
             m.weight.data.fill_(1)
             m.bias.data.zero_()