Ejemplo n.º 1
0
def resnet101_v1b_gn(pretrained=False,
                     root=os.path.expanduser('~/.torch/models'),
                     **kwargs):
    """Constructs a ResNetV1b-101 GroupNorm model.

    Parameters
    ----------
    pretrained : bool or str
        Boolean value controls whether to load the default pretrained weights for model.
    root : str, default '~/.torch/models'
        Location for keeping the model parameters.
    dilated: bool, default False
        Whether to apply dilation strategy to ResNetV1b, yielding a stride 8 model.
    norm_layer : object
        Normalization layer used (default: :class:`nn.BatchNorm`)
        Can be :class:`nn.BatchNorm` or :class:`other normalization`.
    last_gamma : bool, default False
        Whether to initialize the gamma of the last BatchNorm layer in each bottleneck to zero.
    use_global_stats : bool, default False
        Whether forcing BatchNorm to use global statistics instead of minibatch statistics;
        optionally set to True if finetuning using ImageNet classification pretrained models.
    """
    from model.module.basic import GroupNorm
    from model.module.convert import convert_norm_layer
    model = ResNetV1b(BottleneckV1b, [3, 4, 23, 3], **kwargs)
    norm_kwargs = {'num_groups': 32}
    model = convert_norm_layer(model,
                               norm_layer=GroupNorm,
                               norm_kwargs=norm_kwargs)
    if pretrained:
        import torch
        from model.model_store import get_model_file
        model.load_state_dict(
            torch.load(get_model_file('resnet%d_v%db_gn' % (101, 1),
                                      root=root)))
        from data.imagenet import ImageNetAttr
        attrib = ImageNetAttr()
        model.synset = attrib.synset
        model.classes = attrib.classes
        model.classes_long = attrib.classes_long
    return model
Ejemplo n.º 2
0
def resnet101_v1b_gn(pretrained=None, **kwargs):
    """Constructs a ResNetV1b-101 GroupNorm model.

    Parameters
    ----------
    pretrained : str
        the default pretrained weights for model.
    dilated: bool, default False
        Whether to apply dilation strategy to ResNetV1b, yielding a stride 8 model.
    """
    from model.module.basic import GroupNorm
    from model.module.convert import convert_norm_layer
    model = ResNetV1b(BottleneckV1b, [3, 4, 23, 3], **kwargs)
    norm_kwargs = {'num_groups': 32}
    model = convert_norm_layer(model, norm_layer=GroupNorm, norm_kwargs=norm_kwargs)
    if pretrained:
        model.load_state_dict(torch.load(pretrained))
        from data.imagenet import ImageNetAttr
        attrib = ImageNetAttr()
        model.synset = attrib.synset
        model.classes = attrib.classes
        model.classes_long = attrib.classes_long
    return model