Example #1
0
 def __init__(self, num_classes, loss={'softmax'}, aligned=False, **kwargs):
     super(ResNet50, self).__init__()
     self.loss = loss
     resnet50 = torchvision.models.resnet50(pretrained=True)
     self.base = nn.Sequential(*list(resnet50.children())[:-2])
     self.classifier = nn.Linear(2048, num_classes)
     self.s_classifier = AngleLinear(2048, num_classes)
     self.feat_dim = 2048  # feature dimension
     self.aligned = aligned
     if self.aligned:
         self.bn = nn.BatchNorm2d(2048)
         self.relu = nn.ReLU(inplace=True)
         self.horizon_pool = HorizontalMaxPool2d()
         self.conv1 = nn.Conv2d(2048, 128, kernel_size=1, stride=1, padding=0, bias=True)
Example #2
0
    def __init__(self,
                 num_classes,
                 loss={'softmax'},
                 num_groups=3,
                 aligned=False,
                 **kwargs):
        super(ShuffleNet, self).__init__()
        self.loss = loss

        self.conv1 = nn.Sequential(
            nn.Conv2d(3, 24, 3, stride=2, padding=1, bias=False),
            nn.BatchNorm2d(24),
            nn.ReLU(),
            nn.MaxPool2d(3, stride=2, padding=1),
        )

        self.stage2 = nn.Sequential(
            Bottleneck(24, cfg[num_groups][0], 2, num_groups),
            Bottleneck(cfg[num_groups][0], cfg[num_groups][0], 1, num_groups),
            Bottleneck(cfg[num_groups][0], cfg[num_groups][0], 1, num_groups),
            Bottleneck(cfg[num_groups][0], cfg[num_groups][0], 1, num_groups),
        )

        self.stage3 = nn.Sequential(
            Bottleneck(cfg[num_groups][0], cfg[num_groups][1], 2, num_groups),
            Bottleneck(cfg[num_groups][1], cfg[num_groups][1], 1, num_groups),
            Bottleneck(cfg[num_groups][1], cfg[num_groups][1], 1, num_groups),
            Bottleneck(cfg[num_groups][1], cfg[num_groups][1], 1, num_groups),
            Bottleneck(cfg[num_groups][1], cfg[num_groups][1], 1, num_groups),
            Bottleneck(cfg[num_groups][1], cfg[num_groups][1], 1, num_groups),
            Bottleneck(cfg[num_groups][1], cfg[num_groups][1], 1, num_groups),
            Bottleneck(cfg[num_groups][1], cfg[num_groups][1], 1, num_groups),
        )

        self.stage4 = nn.Sequential(
            Bottleneck(cfg[num_groups][1], cfg[num_groups][2], 2, num_groups),
            Bottleneck(cfg[num_groups][2], cfg[num_groups][2], 1, num_groups),
            Bottleneck(cfg[num_groups][2], cfg[num_groups][2], 1, num_groups),
            Bottleneck(cfg[num_groups][2], cfg[num_groups][2], 1, num_groups),
        )

        self.classifier = nn.Linear(cfg[num_groups][2], num_classes)
        self.feat_dim = cfg[num_groups][2]
        self.aligned = aligned
        self.horizon_pool = HorizontalMaxPool2d()
 def __init__(self, num_classes, loss={'softmax'}, aligned=False, **kwargs):
     super(DenseNet121, self).__init__()
     self.loss = loss
     densenet121 = torchvision.models.densenet121(pretrained=True)
     self.base = densenet121.features
     self.classifier = nn.Linear(1024, num_classes)
     self.feat_dim = 1024  # feature dimension
     self.aligned = aligned
     self.horizon_pool = HorizontalMaxPool2d()
     if self.aligned:
         self.bn = nn.BatchNorm2d(1024)
         self.relu = nn.ReLU(inplace=True)
         self.conv1 = nn.Conv2d(1024,
                                128,
                                kernel_size=1,
                                stride=1,
                                padding=0,
                                bias=True)
Example #4
0
 def __init__(self, num_classes, loss={'softmax'}, aligned=False, **kwargs):
     super(InceptionV4ReID, self).__init__()
     self.loss = loss
     base = inceptionv4()
     self.features = base.features
     self.classifier = nn.Linear(1536, num_classes)
     self.feat_dim = 1536  # feature dimension
     self.aligned = aligned
     self.horizon_pool = HorizontalMaxPool2d()
     if self.aligned:
         self.bn = nn.BatchNorm2d(1536)
         self.relu = nn.ReLU(inplace=True)
         self.conv1 = nn.Conv2d(1536,
                                128,
                                kernel_size=1,
                                stride=1,
                                padding=0,
                                bias=True)