def __init__(self, arch='resnest50_2s2x40d', dropout_rate=0., num_classes=1000, fix_bn=False, partial_bn=False): super(OfficialResNeSt, self).__init__() self.num_classes = num_classes self.fix_bn = fix_bn self.partial_bn = partial_bn if arch == 'resnest50': self.model = resnest50(num_classes=num_classes, final_drop=dropout_rate) elif arch == 'resnest50_2s2x40d': radix = 2 groups = 2 width_per_group = 40 avg_first = False self.model = ResNet(Bottleneck, [3, 4, 6, 3], radix=radix, groups=groups, bottleneck_width=width_per_group, deep_stem=True, stem_width=32, avg_down=True, avd=True, avd_first=avg_first, final_drop=dropout_rate, num_classes=num_classes) elif arch == 'resnest50_2s2x40d_fast': radix = 2 groups = 2 width_per_group = 40 avg_first = True self.model = ResNet(Bottleneck, [3, 4, 6, 3], radix=radix, groups=groups, bottleneck_width=width_per_group, deep_stem=True, stem_width=32, avg_down=True, avd=True, avd_first=avg_first, final_drop=dropout_rate, num_classes=num_classes) else: raise ValueError('no such value')
def get_model(pretrained=True, n_class=24): # model = torchvision.models.resnext50_32x4d(pretrained=False) # model = torchvision.models.resnext101_32x8d(pretrained=False) model = ResNet(**MODEL_CONFIGS["resnest50_fast_1s1x64d"]) n_features = model.fc.in_features model.fc = nn.Linear(n_features, 264) # model.load_state_dict(torch.load('resnext50_32x4d_extra_2.pt')) # model.load_state_dict(torch.load('resnext101_32x8d_wsl_extra_4.pt')) fn = '../input/birds-cp-1/resnest50_fast_1s1x64d_conf_1.pt' model.load_state_dict(torch.load(fn, map_location='cpu')) model.fc = nn.Linear(n_features, n_class) return model
def resnet101(pretrained=False, root='~/.encoding/models', **kwargs): """Constructs a ResNet-101 model. Args: pretrained (bool): If True, returns a model pre-trained on ImageNet """ kwargs['radix'] = 0 kwargs['rectified_conv'] = True model = ResNet(Bottleneck, [3, 4, 23, 3], **kwargs) if pretrained: model.load_state_dict(torch.hub.load_state_dict_from_url( rectify_model_urls['resnet101'], progress=True, check_hash=True, map_location=torch.device('cpu'))) return model
def resnext50_32x4d(pretrained=False, root='~/.encoding/models', **kwargs): r"""ResNeXt-50 32x4d model from `"Aggregated Residual Transformation for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_ Args: pretrained (bool): If True, returns a model pre-trained on ImageNet progress (bool): If True, displays a progress bar of the download to stderr """ kwargs['radix'] = 0 kwargs['groups'] = 32 kwargs['bottleneck_width'] = 4 kwargs['rectified_conv'] = True model = ResNet(Bottleneck, [3, 4, 6, 3], **kwargs) if pretrained: model.load_state_dict(torch.hub.load_state_dict_from_url( rectify_model_urls['resnext50_32x4d'], progress=True, check_hash=True, map_location=torch.device('cpu'))) return model
def resnest50(num_classes, pretrained=True, **kwargs): model = ResNet(Bottleneck, [3, 4, 6, 3], radix=2, groups=1, bottleneck_width=64, num_classes=num_classes, deep_stem=True, stem_width=32, avg_down=True, avd=True, avd_first=False, dilation=2, **kwargs) if pretrained: model.load_state_dict( torch.hub.load_state_dict_from_url(resnest_model_urls['resnest50'], progress=True, check_hash=True)) return model