예제 #1
0
def build_backbone(cfg):
    backbone_name = cfg.MODEL.BACKBONE.NAME
    print(backbone_name)
    if backbone_name == "basic":
        model = BasicModel(cfg)
        return model
    if backbone_name == "inception":
        model = InceptionV3(cfg)
        return model
    if backbone_name == "resnet34":
        model = Resnet34(cfg)
        return model
    if backbone_name == "resnet50":
        model = Resnet50(cfg)
        return model
    if backbone_name == "resnet34":
        model = Resnet34(cfg)
        return model
    if backbone_name == "vgg":
        model = VGG(cfg)
        if cfg.MODEL.BACKBONE.PRETRAINED:
            state_dict = load_state_dict_from_url(
                "https://s3.amazonaws.com/amdegroot-models/vgg16_reducedfc.pth"
            )
            model.init_from_pretrain(state_dict)
        return model
예제 #2
0
def build_backbone(cfg):
    backbone_name = cfg.MODEL.BACKBONE.NAME
    if backbone_name == "basic":
        model = BasicModel(cfg)
        return model
    # Added model used in 4c
    if backbone_name == "improved":
        model = ImprovedModel(cfg)
        return model
    if backbone_name == "vgg":
        model = VGG(cfg)
        if cfg.MODEL.BACKBONE.PRETRAINED:
            state_dict = load_state_dict_from_url(
                "https://s3.amazonaws.com/amdegroot-models/vgg16_reducedfc.pth"
            )
            model.init_from_pretrain(state_dict)
        return model
예제 #3
0
def build_backbone(cfg):
    backbone_name = cfg.MODEL.BACKBONE.NAME
    print(backbone_name)
    if backbone_name == "basic":
        model = BasicModel(cfg)
        return model
    if backbone_name == "vgg":
        model = VGG(cfg)
        if cfg.MODEL.BACKBONE.PRETRAINED:
            state_dict = load_state_dict_from_url(
                "https://s3.amazonaws.com/amdegroot-models/vgg16_reducedfc.pth"
            )
            model.init_from_pretrain(state_dict)
        return model
    if backbone_name == "googlenet":
        model = GoogleNet(cfg)
        return model
    if backbone_name == "densenet":
        model = DenseNet(cfg)
        return model
    if backbone_name == "resnext":
        model = ResNext(cfg)
        return model
예제 #4
0
def build_backbone(cfg):
    backbone_name = cfg.MODEL.BACKBONE.NAME
    
    print(backbone_name)
    if backbone_name == "basic":
        model = BasicModel(cfg)
        return model
    if backbone_name == "vgg":
        model = VGG(cfg)
        if cfg.MODEL.BACKBONE.PRETRAINED:
            state_dict = load_state_dict_from_url(
                "https://s3.amazonaws.com/amdegroot-models/vgg16_reducedfc.pth")
            model.init_from_pretrain(state_dict)
    if backbone_name == "resnet":
        depth = cfg.MODEL.BACKBONE.DEPTH
        model_urls = {
            'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth',
            'resnet34': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth',
            'resnet50': 'https://download.pytorch.org/models/resnet50-19c8e357.pth',
            'resnet101': 'https://download.pytorch.org/models/resnet101-5d3b4d8f.pth',
            'resnet152': 'https://download.pytorch.org/models/resnet152-b121ed2d.pth',}
        name_dict = {18: 'resnet18', 34: 'resnet34', 50: 'resnet50', 101: 'resnet101', 152: 'resnet152'}
        layers_dict = {18: [2, 2, 2, 2], 34: [3, 4, 6, 3], 50: [3, 4, 6, 3], 
                       101: [3, 4, 23, 3], 152: [3, 8, 36, 3]}
        block_dict = {18: BasicBlock, 34: BasicBlock, 50: Bottleneck, 101: Bottleneck, 152: Bottleneck}
        model = ResNet(cfg, block_dict[depth], layers_dict[depth])
        if cfg.MODEL.BACKBONE.PRETRAINED:
            pretrained_dict = model_zoo.load_url(model_urls[name_dict[depth]])
            model_dict = model.state_dict()
            pretrained_dict = {k: v for k, v in pretrained_dict.items() if k in model_dict}
            model_dict.update(pretrained_dict)
            model.load_state_dict(model_dict)
        return model
    if backbone_name == "resnest":
        model = ResNest(cfg,BasicBlock)
        return model