Ejemplo n.º 1
0
    def __init__(self,
                 num_classes=2,
                 numDiPerVideos=1,
                 model_name='resnet50',
                 joinType='maxTempPool',
                 freezeConvLayers=True):
        super(ResNet_ROI_Pool, self).__init__()
        self.numDiPerVideos = numDiPerVideos
        self.num_classes = num_classes
        self.joinType = joinType
        self.model_ft = None
        self.model_ft = models.resnet50(pretrained=True)

        self.num_ftrs = self.model_ft.fc.in_features
        self.model_ft.fc = Identity()
        self.bn = nn.BatchNorm2d(2048)

        self.model_ft = nn.Sequential(*list(
            self.model_ft.children())[:-2])  # to tempooling

        self.roi_pool = RoIPool(3, 1)

        # model_ft = None
        self.AdaptiveAvgPool2d = nn.AdaptiveAvgPool2d((1, 1))

        # set_parameter_requires_grad(self.model_ft, feature_extract)
        set_parameter_requires_grad(self.model_ft, freezeConvLayers)
        if self.joinType == constants.TEMP_MAX_POOL:
            self.linear = nn.Linear(2048, self.num_classes)
Ejemplo n.º 2
0
    def __init__(self, num_classes, numDiPerVideos, model_name, joinType,
                 freezeConvLayers):
        super(ResNet, self).__init__()
        self.numDiPerVideos = numDiPerVideos
        self.num_classes = num_classes
        self.joinType = joinType
        self.model_ft = None
        if model_name == 'resnet18':
            self.model_ft = models.resnet18(pretrained=True)
        elif model_name == 'resnet34':
            self.model_ft = models.resnet34(pretrained=True)
        elif model_name == 'resnet50':
            self.model_ft = models.resnet50(pretrained=True)

        self.num_ftrs = self.model_ft.fc.in_features
        self.model_ft.fc = Identity()
        if model_name == 'resnet18' or model_name == 'resnet34':
            self.bn = nn.BatchNorm2d(512)
        elif model_name == 'resnet50':
            self.bn = nn.BatchNorm2d(2048)

        self.convLayers = nn.Sequential(*list(
            self.model_ft.children())[:-2])  # to tempooling
        model_ft = None
        self.AdaptiveAvgPool2d = nn.AdaptiveAvgPool2d((1, 1))

        # set_parameter_requires_grad(self.model_ft, feature_extract)
        set_parameter_requires_grad(self.convLayers, freezeConvLayers)
        if self.joinType == constants.TEMP_MAX_POOL or self.joinType == constants.MULT_TEMP_POOL or self.joinType == constants.TEMP_AVG_POOL or self.joinType == constants.TEMP_STD_POOL:
            if model_name == 'resnet18' or model_name == 'resnet34':
                self.linear = nn.Linear(512, self.num_classes)
            elif model_name == 'resnet50':
                self.linear = nn.Linear(2048, self.num_classes)
Ejemplo n.º 3
0
 def __init__(self, num_classes, numDiPerVideos, joinType, feature_extract):
     super(Densenet, self).__init__()
     self.numDiPerVideos = numDiPerVideos
     self.joinType = joinType
     self.num_classes = num_classes
     self.model = models.densenet121(pretrained=True)
     set_parameter_requires_grad(self.model, feature_extract)
     self.num_ftrs = self.model.classifier.in_features
     self.model.classifier = Identity()
     self.linear = nn.Linear(self.num_ftrs, num_classes)
Ejemplo n.º 4
0
 def __init__(self, num_classes, model_name, feature_extract):
     super(ResNetRGB, self).__init__()
     self.num_classes = num_classes
     if model_name == 'resnet18':
         self.model_ft = models.resnet18(pretrained=True)
     elif model_name == 'resnet34':
         self.model_ft = models.resnet34(pretrained=True)
     elif model_name == 'resnet50':
         self.model_ft = models.resnet50(pretrained=True)
     self.num_ftrs = self.model_ft.fc.in_features
     set_parameter_requires_grad(self.model_ft, feature_extract)
     self.model_ft.fc = nn.Linear(self.num_ftrs, self.num_classes)
Ejemplo n.º 5
0
 def __init__(self, num_classes, numDiPerVideos, joinType, feature_extract):
     super(AlexNet, self).__init__()
     self.numDiPerVideos = numDiPerVideos
     self.joinType = joinType
     self.num_classes = num_classes
     self.model = models.alexnet(pretrained=True)
     set_parameter_requires_grad(self.model, feature_extract)
     self.linear = None
     self.model = nn.Sequential(*list(
         self.model.children())[:-2])  # to tempooling
     self.tmpPooling = nn.MaxPool2d((numDiPerVideos, 1))
     self.linear = nn.Linear(256 * 6 * 6, self.num_classes)
Ejemplo n.º 6
0
 def __init__(self, num_classes, numDiPerVideos, joinType, feature_extract):
     super(Inception, self).__init__()
     self.numDiPerVideos = numDiPerVideos
     self.joinType = joinType
     self.num_classes = num_classes
     self.model = models.inception_v3(pretrained=True)
     set_parameter_requires_grad(self.model, feature_extract)
     # Handle the auxilary net
     num_ftrs = self.model.AuxLogits.fc.in_features
     self.model.AuxLogits.fc = nn.Linear(num_ftrs, num_classes)
     # Handle the primary net
     num_ftrs = self.model.fc.in_features
     self.model.fc = nn.Linear(num_ftrs, num_classes)