Pretrained ConvNets for pytorch: NASNet, ResNeXt, ResNet, InceptionV4, InceptionResnetV2, Xception, DPN, etc.

Overview

Pretrained models for Pytorch (Work in progress)

The goal of this repo is:

  • to help to reproduce research papers results (transfer learning setups for instance),
  • to access pretrained ConvNets with a unique interface/API inspired by torchvision.

News:

  • 27/10/2018: Fix compatibility issues, Add tests, Add travis
  • 04/06/2018: PolyNet and PNASNet-5-Large thanks to Alex Parinov
  • 16/04/2018: SE-ResNet* and SE-ResNeXt* thanks to Alex Parinov
  • 09/04/2018: SENet154 thanks to Alex Parinov
  • 22/03/2018: CaffeResNet101 (good for localization with FasterRCNN)
  • 21/03/2018: NASNet Mobile thanks to Veronika Yurchuk and Anastasiia
  • 25/01/2018: DualPathNetworks thanks to Ross Wightman, Xception thanks to T Standley, improved TransformImage API
  • 13/01/2018: pip install pretrainedmodels, pretrainedmodels.model_names, pretrainedmodels.pretrained_settings
  • 12/01/2018: python setup.py install
  • 08/12/2017: update data url (/!\ git pull is needed)
  • 30/11/2017: improve API (model.features(input), model.logits(features), model.forward(input), model.last_linear)
  • 16/11/2017: nasnet-a-large pretrained model ported by T. Durand and R. Cadene
  • 22/07/2017: torchvision pretrained models
  • 22/07/2017: momentum in inceptionv4 and inceptionresnetv2 to 0.1
  • 17/07/2017: model.input_range attribut
  • 17/07/2017: BNInception pretrained on Imagenet

Summary

Installation

  1. python3 with anaconda
  2. pytorch with/out CUDA

Install from pip

  1. pip install pretrainedmodels

Install from repo

  1. git clone https://github.com/Cadene/pretrained-models.pytorch.git
  2. cd pretrained-models.pytorch
  3. python setup.py install

Quick examples

  • To import pretrainedmodels:
import pretrainedmodels
  • To print the available pretrained models:
print(pretrainedmodels.model_names)
> ['fbresnet152', 'bninception', 'resnext101_32x4d', 'resnext101_64x4d', 'inceptionv4', 'inceptionresnetv2', 'alexnet', 'densenet121', 'densenet169', 'densenet201', 'densenet161', 'resnet18', 'resnet34', 'resnet50', 'resnet101', 'resnet152', 'inceptionv3', 'squeezenet1_0', 'squeezenet1_1', 'vgg11', 'vgg11_bn', 'vgg13', 'vgg13_bn', 'vgg16', 'vgg16_bn', 'vgg19_bn', 'vgg19', 'nasnetalarge', 'nasnetamobile', 'cafferesnet101', 'senet154',  'se_resnet50', 'se_resnet101', 'se_resnet152', 'se_resnext50_32x4d', 'se_resnext101_32x4d', 'cafferesnet101', 'polynet', 'pnasnet5large']
  • To print the available pretrained settings for a chosen model:
print(pretrainedmodels.pretrained_settings['nasnetalarge'])
> {'imagenet': {'url': 'http://data.lip6.fr/cadene/pretrainedmodels/nasnetalarge-a1897284.pth', 'input_space': 'RGB', 'input_size': [3, 331, 331], 'input_range': [0, 1], 'mean': [0.5, 0.5, 0.5], 'std': [0.5, 0.5, 0.5], 'num_classes': 1000}, 'imagenet+background': {'url': 'http://data.lip6.fr/cadene/pretrainedmodels/nasnetalarge-a1897284.pth', 'input_space': 'RGB', 'input_size': [3, 331, 331], 'input_range': [0, 1], 'mean': [0.5, 0.5, 0.5], 'std': [0.5, 0.5, 0.5], 'num_classes': 1001}}
  • To load a pretrained models from imagenet:
model_name = 'nasnetalarge' # could be fbresnet152 or inceptionresnetv2
model = pretrainedmodels.__dict__[model_name](num_classes=1000, pretrained='imagenet')
model.eval()

Note: By default, models will be downloaded to your $HOME/.torch folder. You can modify this behavior using the $TORCH_HOME variable as follow: export TORCH_HOME="/local/pretrainedmodels"

  • To load an image and do a complete forward pass:
import torch
import pretrainedmodels.utils as utils

load_img = utils.LoadImage()

# transformations depending on the model
# rescale, center crop, normalize, and others (ex: ToBGR, ToRange255)
tf_img = utils.TransformImage(model) 

path_img = 'data/cat.jpg'

input_img = load_img(path_img)
input_tensor = tf_img(input_img)         # 3x400x225 -> 3x299x299 size may differ
input_tensor = input_tensor.unsqueeze(0) # 3x299x299 -> 1x3x299x299
input = torch.autograd.Variable(input_tensor,
    requires_grad=False)

output_logits = model(input) # 1x1000
  • To extract features (beware this API is not available for all networks):
output_features = model.features(input) # 1x14x14x2048 size may differ
output_logits = model.logits(output_features) # 1x1000

Few use cases

Compute imagenet logits

$ python examples/imagenet_logits.py -h
> nasnetalarge, resnet152, inceptionresnetv2, inceptionv4, ...
$ python examples/imagenet_logits.py -a nasnetalarge --path_img data/cat.jpg
> 'nasnetalarge': data/cat.jpg' is a 'tiger cat' 

Compute imagenet evaluation metrics

$ python examples/imagenet_eval.py /local/common-data/imagenet_2012/images -a nasnetalarge -b 20 -e
> * Acc@1 82.693, Acc@5 96.13

Evaluation on imagenet

Accuracy on validation set (single model)

Results were obtained using (center cropped) images of the same size than during the training process.

Model Version Acc@1 Acc@5
PNASNet-5-Large Tensorflow 82.858 96.182
PNASNet-5-Large Our porting 82.736 95.992
NASNet-A-Large Tensorflow 82.693 96.163
NASNet-A-Large Our porting 82.566 96.086
SENet154 Caffe 81.32 95.53
SENet154 Our porting 81.304 95.498
PolyNet Caffe 81.29 95.75
PolyNet Our porting 81.002 95.624
InceptionResNetV2 Tensorflow 80.4 95.3
InceptionV4 Tensorflow 80.2 95.3
SE-ResNeXt101_32x4d Our porting 80.236 95.028
SE-ResNeXt101_32x4d Caffe 80.19 95.04
InceptionResNetV2 Our porting 80.170 95.234
InceptionV4 Our porting 80.062 94.926
DualPathNet107_5k Our porting 79.746 94.684
ResNeXt101_64x4d Torch7 79.6 94.7
DualPathNet131 Our porting 79.432 94.574
DualPathNet92_5k Our porting 79.400 94.620
DualPathNet98 Our porting 79.224 94.488
SE-ResNeXt50_32x4d Our porting 79.076 94.434
SE-ResNeXt50_32x4d Caffe 79.03 94.46
Xception Keras 79.000 94.500
ResNeXt101_64x4d Our porting 78.956 94.252
Xception Our porting 78.888 94.292
ResNeXt101_32x4d Torch7 78.8 94.4
SE-ResNet152 Caffe 78.66 94.46
SE-ResNet152 Our porting 78.658 94.374
ResNet152 Pytorch 78.428 94.110
SE-ResNet101 Our porting 78.396 94.258
SE-ResNet101 Caffe 78.25 94.28
ResNeXt101_32x4d Our porting 78.188 93.886
FBResNet152 Torch7 77.84 93.84
SE-ResNet50 Caffe 77.63 93.64
SE-ResNet50 Our porting 77.636 93.752
DenseNet161 Pytorch 77.560 93.798
ResNet101 Pytorch 77.438 93.672
FBResNet152 Our porting 77.386 93.594
InceptionV3 Pytorch 77.294 93.454
DenseNet201 Pytorch 77.152 93.548
DualPathNet68b_5k Our porting 77.034 93.590
CaffeResnet101 Caffe 76.400 92.900
CaffeResnet101 Our porting 76.200 92.766
DenseNet169 Pytorch 76.026 92.992
ResNet50 Pytorch 76.002 92.980
DualPathNet68 Our porting 75.868 92.774
DenseNet121 Pytorch 74.646 92.136
VGG19_BN Pytorch 74.266 92.066
NASNet-A-Mobile Tensorflow 74.0 91.6
NASNet-A-Mobile Our porting 74.080 91.740
ResNet34 Pytorch 73.554 91.456
BNInception Our porting 73.524 91.562
VGG16_BN Pytorch 73.518 91.608
VGG19 Pytorch 72.080 90.822
VGG16 Pytorch 71.636 90.354
VGG13_BN Pytorch 71.508 90.494
VGG11_BN Pytorch 70.452 89.818
ResNet18 Pytorch 70.142 89.274
VGG13 Pytorch 69.662 89.264
VGG11 Pytorch 68.970 88.746
SqueezeNet1_1 Pytorch 58.250 80.800
SqueezeNet1_0 Pytorch 58.108 80.428
Alexnet Pytorch 56.432 79.194

Notes:

  • the Pytorch version of ResNet152 is not a porting of the Torch7 but has been retrained by facebook.
  • For the PolyNet evaluation each image was resized to 378x378 without preserving the aspect ratio and then the central 331×331 patch from the resulting image was used.

Beware, the accuracy reported here is not always representative of the transferable capacity of the network on other tasks and datasets. You must try them all! :P

Reproducing results

Please see Compute imagenet validation metrics

Documentation

Available models

NASNet*

Source: TensorFlow Slim repo

  • nasnetalarge(num_classes=1000, pretrained='imagenet')
  • nasnetalarge(num_classes=1001, pretrained='imagenet+background')
  • nasnetamobile(num_classes=1000, pretrained='imagenet')

FaceBook ResNet*

Source: Torch7 repo of FaceBook

There are a bit different from the ResNet* of torchvision. ResNet152 is currently the only one available.

  • fbresnet152(num_classes=1000, pretrained='imagenet')

Caffe ResNet*

Source: Caffe repo of KaimingHe

  • cafferesnet101(num_classes=1000, pretrained='imagenet')

Inception*

Source: TensorFlow Slim repo and Pytorch/Vision repo for inceptionv3

  • inceptionresnetv2(num_classes=1000, pretrained='imagenet')
  • inceptionresnetv2(num_classes=1001, pretrained='imagenet+background')
  • inceptionv4(num_classes=1000, pretrained='imagenet')
  • inceptionv4(num_classes=1001, pretrained='imagenet+background')
  • inceptionv3(num_classes=1000, pretrained='imagenet')

BNInception

Source: Trained with Caffe by Xiong Yuanjun

  • bninception(num_classes=1000, pretrained='imagenet')

ResNeXt*

Source: ResNeXt repo of FaceBook

  • resnext101_32x4d(num_classes=1000, pretrained='imagenet')
  • resnext101_62x4d(num_classes=1000, pretrained='imagenet')

DualPathNetworks

Source: MXNET repo of Chen Yunpeng

The porting has been made possible by Ross Wightman in his PyTorch repo.

As you can see here DualPathNetworks allows you to try different scales. The default one in this repo is 0.875 meaning that the original input size is 256 before croping to 224.

  • dpn68(num_classes=1000, pretrained='imagenet')
  • dpn98(num_classes=1000, pretrained='imagenet')
  • dpn131(num_classes=1000, pretrained='imagenet')
  • dpn68b(num_classes=1000, pretrained='imagenet+5k')
  • dpn92(num_classes=1000, pretrained='imagenet+5k')
  • dpn107(num_classes=1000, pretrained='imagenet+5k')

'imagenet+5k' means that the network has been pretrained on imagenet5k before being finetuned on imagenet1k.

Xception

Source: Keras repo

The porting has been made possible by T Standley.

  • xception(num_classes=1000, pretrained='imagenet')

SENet*

Source: Caffe repo of Jie Hu

  • senet154(num_classes=1000, pretrained='imagenet')
  • se_resnet50(num_classes=1000, pretrained='imagenet')
  • se_resnet101(num_classes=1000, pretrained='imagenet')
  • se_resnet152(num_classes=1000, pretrained='imagenet')
  • se_resnext50_32x4d(num_classes=1000, pretrained='imagenet')
  • se_resnext101_32x4d(num_classes=1000, pretrained='imagenet')

PNASNet*

Source: TensorFlow Slim repo

  • pnasnet5large(num_classes=1000, pretrained='imagenet')
  • pnasnet5large(num_classes=1001, pretrained='imagenet+background')

PolyNet

Source: Caffe repo of the CUHK Multimedia Lab

  • polynet(num_classes=1000, pretrained='imagenet')

TorchVision

Source: Pytorch/Vision repo

(inceptionv3 included in Inception*)

  • resnet18(num_classes=1000, pretrained='imagenet')
  • resnet34(num_classes=1000, pretrained='imagenet')
  • resnet50(num_classes=1000, pretrained='imagenet')
  • resnet101(num_classes=1000, pretrained='imagenet')
  • resnet152(num_classes=1000, pretrained='imagenet')
  • densenet121(num_classes=1000, pretrained='imagenet')
  • densenet161(num_classes=1000, pretrained='imagenet')
  • densenet169(num_classes=1000, pretrained='imagenet')
  • densenet201(num_classes=1000, pretrained='imagenet')
  • squeezenet1_0(num_classes=1000, pretrained='imagenet')
  • squeezenet1_1(num_classes=1000, pretrained='imagenet')
  • alexnet(num_classes=1000, pretrained='imagenet')
  • vgg11(num_classes=1000, pretrained='imagenet')
  • vgg13(num_classes=1000, pretrained='imagenet')
  • vgg16(num_classes=1000, pretrained='imagenet')
  • vgg19(num_classes=1000, pretrained='imagenet')
  • vgg11_bn(num_classes=1000, pretrained='imagenet')
  • vgg13_bn(num_classes=1000, pretrained='imagenet')
  • vgg16_bn(num_classes=1000, pretrained='imagenet')
  • vgg19_bn(num_classes=1000, pretrained='imagenet')

Model API

Once a pretrained model has been loaded, you can use it that way.

Important note: All image must be loaded using PIL which scales the pixel values between 0 and 1.

model.input_size

Attribut of type list composed of 3 numbers:

  • number of color channels,
  • height of the input image,
  • width of the input image.

Example:

  • [3, 299, 299] for inception* networks,
  • [3, 224, 224] for resnet* networks.

model.input_space

Attribut of type str representating the color space of the image. Can be RGB or BGR.

model.input_range

Attribut of type list composed of 2 numbers:

  • min pixel value,
  • max pixel value.

Example:

  • [0, 1] for resnet* and inception* networks,
  • [0, 255] for bninception network.

model.mean

Attribut of type list composed of 3 numbers which are used to normalize the input image (substract "color-channel-wise").

Example:

  • [0.5, 0.5, 0.5] for inception* networks,
  • [0.485, 0.456, 0.406] for resnet* networks.

model.std

Attribut of type list composed of 3 numbers which are used to normalize the input image (divide "color-channel-wise").

Example:

  • [0.5, 0.5, 0.5] for inception* networks,
  • [0.229, 0.224, 0.225] for resnet* networks.

model.features

/!\ work in progress (may not be available)

Method which is used to extract the features from the image.

Example when the model is loaded using fbresnet152:

print(input_224.size())            # (1,3,224,224)
output = model.features(input_224) 
print(output.size())               # (1,2048,1,1)

# print(input_448.size())          # (1,3,448,448)
output = model.features(input_448)
# print(output.size())             # (1,2048,7,7)

model.logits

/!\ work in progress (may not be available)

Method which is used to classify the features from the image.

Example when the model is loaded using fbresnet152:

output = model.features(input_224) 
print(output.size())               # (1,2048, 1, 1)
output = model.logits(output)
print(output.size())               # (1,1000)

model.forward

Method used to call model.features and model.logits. It can be overwritten as desired.

Note: A good practice is to use model.__call__ as your function of choice to forward an input to your model. See the example bellow.

# Without model.__call__
output = model.forward(input_224)
print(output.size())      # (1,1000)

# With model.__call__
output = model(input_224)
print(output.size())      # (1,1000)

model.last_linear

Attribut of type nn.Linear. This module is the last one to be called during the forward pass.

  • Can be replaced by an adapted nn.Linear for fine tuning.
  • Can be replaced by pretrained.utils.Identity for features extraction.

Example when the model is loaded using fbresnet152:

print(input_224.size())            # (1,3,224,224)
output = model.features(input_224) 
print(output.size())               # (1,2048,1,1)
output = model.logits(output)
print(output.size())               # (1,1000)

# fine tuning
dim_feats = model.last_linear.in_features # =2048
nb_classes = 4
model.last_linear = nn.Linear(dim_feats, nb_classes)
output = model(input_224)
print(output.size())               # (1,4)

# features extraction
model.last_linear = pretrained.utils.Identity()
output = model(input_224)
print(output.size())               # (1,2048)

Reproducing

Hand porting of ResNet152

th pretrainedmodels/fbresnet/resnet152_dump.lua
python pretrainedmodels/fbresnet/resnet152_load.py

Automatic porting of ResNeXt

https://github.com/clcarwin/convert_torch_to_pytorch

Hand porting of NASNet, InceptionV4 and InceptionResNetV2

https://github.com/Cadene/tensorflow-model-zoo.torch

Acknowledgement

Thanks to the deep learning community and especially to the contributers of the pytorch ecosystem.

Comments
  • resnext speed

    resnext speed

    Hey, I tried resnext-101(32x4d) for 160x160 crops and also the torchvision resnet-101. For me resnext needs nearly double the time to train compared to the resnet. (Only thing I changed is the final GlobalAveragePooling and classifier layer) Is this expected behavior? Here it says the required FLOPs are the same, but obviously frameworks like Pytorch may be slower because of a more complicated network structure)

    opened by mctigger 13
  • NASNet

    NASNet

    Dear @Cadene, Thank your for your nice repository. Recently the Google Brain Team released a fantastic CNN model, NASNet, in TF-slim, which achieved the state-of-the-art Top-1 Accuracy on ImageNet by 82.7 %. Would you please kindly port this model into your nice repository (i.e., PyTorch Pre-Trained Models)?

    opened by ahkarami 12
  • Sending inputs through pnasnet error

    Sending inputs through pnasnet error

    I'm having a hard time using pnasnet5large. When I try to pass a test data input through the model I'm pulling it results in the error: TypeError: forward() missing 1 required positional argument: 'x_right'

    Pytroch version: 1.0.0 pretrainedmodels version: 0.7.4

    Example passthrough: model(batch[0].cuda())

    This is only the case for this particular network. For all other networks I have tried in this library, my test data input through works correctly. Is there something additional I need to do for my input data?

    bug 
    opened by mark-hoffmann 9
  • Preprocessing - input_range and mean/std

    Preprocessing - input_range and mean/std

    For example in se-resnet50, the input_range in [0,1]. So the input to model is input - mean / std and not actually [0,1], right?

    Does this preprocessing look correct?

    def train_transform(x):
        x = TF.resize(x, 256)
        i, j, h, w = transforms.RandomCrop.get_params(x, [224, 224])
        x = TF.crop(x, i, j, h, w)
        if TF.random.random() > 0.5:
            x = TF.hflip(x)
        x = TF.to_tensor(x)
        x = TF.normalize(x, [0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
        return x
    
    def val_transform(x):
        x = TF.resize(x, 224)
        x = TF.center_crop(x, 224)
        x = TF.to_tensor(x)
        x = TF.normalize(x, [0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
        return x
    
    opened by karandwivedi42 9
  • InceptionV1 relu

    InceptionV1 relu

    Hi,

    I Think some of the relu activations on the InceptionV1 model (bninception.py) are just ignored, for example in line 299

    inception_3b_relu_1x1_out = self.inception_3b_relu_1x1(inception_3b_1x1_bn_out)

    the output 'inception_3b_relu_1x1_out', is never used again, and the input 'inception_3b_1x1_bn_out' is passed to the inception module concatenated output, see line 310.

    inception_3b_output_out = torch.cat([inception_3b_1x1_bn_out,inception_3b_3x3_bn_out,inception_3b_double_3x3_2_bn_out,inception_3b_pool_proj_bn_out], 1)

    Is this a bug or am I missing something?

    bug 
    opened by fuankarion 8
  • Is the maxpool and avgpool interchanged here?

    Is the maxpool and avgpool interchanged here?

    https://github.com/Cadene/pretrained-models.pytorch/blob/dbacab66ca044c05eafd5978a14e85947a53e258/pretrainedmodels/nasnet.py#L82-L86

    I compared the tensorflow implementation, I think your implementation in ReductionCell0 is correct and the CellStem0 should stay the same as ReductionCell0.

    opened by Noplz 7
  • PNASNet-5-Large --TypeError: forward() missing 1 required positional argument: 'x_right'

    PNASNet-5-Large --TypeError: forward() missing 1 required positional argument: 'x_right'

    ~/anaconda36/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs) 487 result = self._slow_forward(*input, **kwargs) 488 else: --> 489 result = self.forward(*input, **kwargs) 490 for hook in self._forward_hooks.values(): 491 hook_result = hook(self, input, result)

    ~/anaconda36/lib/python3.6/site-packages/torch/nn/modules/container.py in forward(self, input) 90 def forward(self, input): 91 for module in self._modules.values(): ---> 92 input = module(input) 93 return input 94

    ~/anaconda36/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs) 487 result = self._slow_forward(*input, **kwargs) 488 else: --> 489 result = self.forward(*input, **kwargs) 490 for hook in self._forward_hooks.values(): 491 hook_result = hook(self, input, result)

    TypeError: forward() missing 1 required positional argument: 'x_right' pytorch1.0

    opened by Bonsen 6
  • Fail to load bninception

    Fail to load bninception

    Hello, when I try to load the bninception model with the following codes, something weird happens. I need some help, thanks.

    model_name = 'nasnetalarge' # could be fbresnet152 or inceptionresnetv2
    model = pretrainedmodels.__dict__[model_name](num_classes=1000, pretrained='imagenet')
    

    running the above code produces this:

    anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py:514: UserWarning: src is not broadcastable to dst, but they have the same number of elements.  Falling back to deprecated pointwise behavior.
      own_state[name].copy_(param)
    
    opened by Redoblue 5
  • NASNeta_mobile

    NASNeta_mobile

    Hi @Cadene ! I rewrote https://github.com/Cadene/pretrained-models.pytorch/blob/master/pretrainedmodels/models/nasnet.py#L487 , so now two options are available NASNetALarge (6 @ 4032) and NASNetAMobile (4 @ 1056). I can do a PR if it would be useful.

    opened by veronikayurchuk 5
  • Error when loading pre-trained ResNeXt weights

    Error when loading pre-trained ResNeXt weights

    After invoking ResNeXt from here like this

    resnext = resnext101_32x4d(num_classes=1000, pretrained='imagenet')

    I get this error


    KeyError Traceback (most recent call last) in () ----> 1 resnext = resnext101_32x4d(num_classes=1000, pretrained='imagenet')

    in resnext101_32x4d(num_classes, pretrained) 81 settings = pretrained_settings['resnext101_32x4d'][pretrained] 82 assert num_classes == settings['num_classes'], "num_classes should be {}, but is {}".format(settings['num_classes'], num_classes) ---> 83 model.load_state_dict(model_zoo.load_url(settings['url'])) 84 model.input_space = settings['input_space'] 85 model.input_size = settings['input_size']

    /opt/conda/lib/python3.5/site-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict) 353 if name not in own_state: 354 raise KeyError('unexpected key "{}" in state_dict' --> 355 .format(name)) 356 if isinstance(param, Parameter): 357 # backwards compatibility for serialized parameters

    KeyError: 'unexpected key "features.0.weight" in state_dict'

    opened by snakers4 5
  • Unable to NASNetALarge with toy example

    Unable to NASNetALarge with toy example

    I am able to run python test/toy-example.py -a fbresnet152 but when I try python test/toy-example.py -a NASNetALarge I got this error:

    pretrained-models.pytorch$ python test/toy-example.py -a NASNetALarge
    Traceback (most recent call last):
      File "test/toy-example.py", line 24, in <module>
        model = pretrainedmodels.__dict__[args.arch](num_classes=1000, pretrained='imagenet')
    TypeError: __init__() got an unexpected keyword argument 'pretrained'
    
    opened by mrteera 5
  • Deprecated Warning of torchvision

    Deprecated Warning of torchvision "pretrained"

    新的torchvision0.14在加载模型的时候已经弃用了pretrained, 而是使用weights, 当我在加载resnet50的时候出现的如下的警告。

    > model = pretrainedmodels.__dict__["resnet50"]()
    
    ...\torchvision\models\_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.
      warnings.warn(
    ...\torchvision\models\_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=None`.
      warnings.warn(msg)
    
    
    opened by lcycode 0
  • SSL certificate is expired

    SSL certificate is expired

    Hi! I'm trying to download pretrained densenet169 and getting error "certificate verify failed: certificate has expired".

    import pretrainedmodels
    pretrainedmodels.densenet169(num_classes=1000, pretrained='imagenet')
    
    Downloading: "http://data.lip6.fr/cadene/pretrainedmodels/densenet169-f470b90a4.pth" to /root/.cache/torch/hub/checkpoints/densenet169-f470b90a4.pth
    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/urllib/request.py", line 1354, in do_open
        h.request(req.get_method(), req.selector, req.data, headers,
      File "/opt/conda/lib/python3.8/http/client.py", line 1252, in request
        self._send_request(method, url, body, headers, encode_chunked)
      File "/opt/conda/lib/python3.8/http/client.py", line 1298, in _send_request
        self.endheaders(body, encode_chunked=encode_chunked)
      File "/opt/conda/lib/python3.8/http/client.py", line 1247, in endheaders
        self._send_output(message_body, encode_chunked=encode_chunked)
      File "/opt/conda/lib/python3.8/http/client.py", line 1007, in _send_output
        self.send(msg)
      File "/opt/conda/lib/python3.8/http/client.py", line 947, in send
        self.connect()
      File "/opt/conda/lib/python3.8/http/client.py", line 1421, in connect
        self.sock = self._context.wrap_socket(self.sock,
      File "/opt/conda/lib/python3.8/ssl.py", line 500, in wrap_socket
        return self.sslsocket_class._create(
      File "/opt/conda/lib/python3.8/ssl.py", line 1040, in _create
        self.do_handshake()
      File "/opt/conda/lib/python3.8/ssl.py", line 1309, in do_handshake
        self._sslobj.do_handshake()
    ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1131)
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/opt/conda/lib/python3.8/site-packages/pretrainedmodels/models/torchvision_models.py", line 225, in densenet169
        model = load_pretrained(model, num_classes, settings)
      File "/opt/conda/lib/python3.8/site-packages/pretrainedmodels/models/torchvision_models.py", line 118, in load_pretrained
        state_dict = model_zoo.load_url(settings['url'])
      File "/opt/conda/lib/python3.8/site-packages/torch/hub.py", line 553, in load_state_dict_from_url
        download_url_to_file(url, cached_file, hash_prefix, progress=progress)
      File "/opt/conda/lib/python3.8/site-packages/torch/hub.py", line 419, in download_url_to_file
        u = urlopen(req)
      File "/opt/conda/lib/python3.8/urllib/request.py", line 222, in urlopen
        return opener.open(url, data, timeout)
      File "/opt/conda/lib/python3.8/urllib/request.py", line 531, in open
        response = meth(req, response)
      File "/opt/conda/lib/python3.8/urllib/request.py", line 640, in http_response
        response = self.parent.error(
      File "/opt/conda/lib/python3.8/urllib/request.py", line 563, in error
        result = self._call_chain(*args)
      File "/opt/conda/lib/python3.8/urllib/request.py", line 502, in _call_chain
        result = func(*args)
      File "/opt/conda/lib/python3.8/urllib/request.py", line 755, in http_error_302
        return self.parent.open(new, timeout=req.timeout)
      File "/opt/conda/lib/python3.8/urllib/request.py", line 525, in open
        response = self._open(req, data)
      File "/opt/conda/lib/python3.8/urllib/request.py", line 542, in _open
        result = self._call_chain(self.handle_open, protocol, protocol +
      File "/opt/conda/lib/python3.8/urllib/request.py", line 502, in _call_chain
        result = func(*args)
      File "/opt/conda/lib/python3.8/urllib/request.py", line 1397, in https_open
        return self.do_open(http.client.HTTPSConnection, req,
      File "/opt/conda/lib/python3.8/urllib/request.py", line 1357, in do_open
        raise URLError(err)
    urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1131)>
    
    opened by qaohv 2
  • DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10

    DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10

    When running pytest with the latest version of Pillow, you'll see:

    ../../../anaconda/envs/adam-py37-min/lib/python3.7/site-packages/pretrainedmodels/datasets/utils.py:33
      /anaconda/envs/adam-py37-min/lib/python3.7/site-packages/pretrainedmodels/datasets/utils.py:33: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead.
        def __init__(self, size, interpolation=Image.BILINEAR):
    

    This attribute was moved to an enum in Pillow 9.1 and the old attribute will be removed in Pillow 10. We should update this soon.

    Related to https://github.com/pytorch/vision/pull/5898 and https://github.com/rwightman/pytorch-image-models/pull/1256.

    opened by adamjstewart 1
  • What are the differences between files with difference hashes?

    What are the differences between files with difference hashes?

    Take Xception models as an example. There are three weight files-"xception-43020ad28.pth","xception-b0b7af25.pth","xception-b5690688.pth" in link. What are the differences?

    opened by VictoryLN 0
  • Requesting pre-trained model variants trained on grayscale ImageNet

    Requesting pre-trained model variants trained on grayscale ImageNet

    opened by aisosalo 1
Owner
Remi
I'm working hard to create the first computer overlord.
Remi
Pretrained EfficientNet, EfficientNet-Lite, MixNet, MobileNetV3 / V2, MNASNet A1 and B1, FBNet, Single-Path NAS

(Generic) EfficientNets for PyTorch A 'generic' implementation of EfficientNet, MixNet, MobileNetV3, etc. that covers most of the compute/parameter ef

Ross Wightman 1.5k Jan 1, 2023
Tez is a super-simple and lightweight Trainer for PyTorch. It also comes with many utils that you can use to tackle over 90% of deep learning projects in PyTorch.

Tez: a simple pytorch trainer NOTE: Currently, we are not accepting any pull requests! All PRs will be closed. If you want a feature or something does

abhishek thakur 1.1k Jan 4, 2023
null 270 Dec 24, 2022
A lightweight wrapper for PyTorch that provides a simple declarative API for context switching between devices, distributed modes, mixed-precision, and PyTorch extensions.

A lightweight wrapper for PyTorch that provides a simple declarative API for context switching between devices, distributed modes, mixed-precision, and PyTorch extensions.

Fidelity Investments 56 Sep 13, 2022
A PyTorch repo for data loading and utilities to be shared by the PyTorch domain libraries.

A PyTorch repo for data loading and utilities to be shared by the PyTorch domain libraries.

null 878 Dec 30, 2022
Unofficial PyTorch implementation of DeepMind's Perceiver IO with PyTorch Lightning scripts for distributed training

Unofficial PyTorch implementation of DeepMind's Perceiver IO with PyTorch Lightning scripts for distributed training

Martin Krasser 251 Dec 25, 2022
PyTorch framework A simple and complete framework for PyTorch, providing a variety of data loading and simple task solutions that are easy to extend and migrate

PyTorch framework A simple and complete framework for PyTorch, providing a variety of data loading and simple task solutions that are easy to extend and migrate

Cong Cai 12 Dec 19, 2021
Model summary in PyTorch similar to `model.summary()` in Keras

Keras style model.summary() in PyTorch Keras has a neat API to view the visualization of the model which is very helpful while debugging your network.

Shubham Chandel 3.7k Dec 29, 2022
torch-optimizer -- collection of optimizers for Pytorch

torch-optimizer torch-optimizer -- collection of optimizers for PyTorch compatible with optim module. Simple example import torch_optimizer as optim

Nikolay Novik 2.6k Jan 3, 2023
A PyTorch implementation of EfficientNet

EfficientNet PyTorch Quickstart Install with pip install efficientnet_pytorch and load a pretrained EfficientNet with: from efficientnet_pytorch impor

Luke Melas-Kyriazi 7.2k Jan 6, 2023
The easiest way to use deep metric learning in your application. Modular, flexible, and extensible. Written in PyTorch.

News March 3: v0.9.97 has various bug fixes and improvements: Bug fixes for NTXentLoss Efficiency improvement for AccuracyCalculator, by using torch i

Kevin Musgrave 5k Jan 2, 2023
A collection of extensions and data-loaders for few-shot learning & meta-learning in PyTorch

Torchmeta A collection of extensions and data-loaders for few-shot learning & meta-learning in PyTorch. Torchmeta contains popular meta-learning bench

Tristan Deleu 1.7k Jan 6, 2023
PyTorch Extension Library of Optimized Scatter Operations

PyTorch Scatter Documentation This package consists of a small extension library of highly optimized sparse update (scatter and segment) operations fo

Matthias Fey 1.2k Jan 7, 2023
PyTorch Extension Library of Optimized Autograd Sparse Matrix Operations

PyTorch Sparse This package consists of a small extension library of optimized sparse matrix operations with autograd support. This package currently

Matthias Fey 757 Jan 4, 2023
Reformer, the efficient Transformer, in Pytorch

Reformer, the Efficient Transformer, in Pytorch This is a Pytorch implementation of Reformer https://openreview.net/pdf?id=rkgNKkHtvB It includes LSH

Phil Wang 1.8k Jan 6, 2023
higher is a pytorch library allowing users to obtain higher order gradients over losses spanning training loops rather than individual training steps.

higher is a library providing support for higher-order optimization, e.g. through unrolled first-order optimization loops, of "meta" aspects of these

Facebook Research 1.5k Jan 3, 2023
PyTorch implementation of TabNet paper : https://arxiv.org/pdf/1908.07442.pdf

README TabNet : Attentive Interpretable Tabular Learning This is a pyTorch implementation of Tabnet (Arik, S. O., & Pfister, T. (2019). TabNet: Attent

DreamQuark 2k Dec 27, 2022
PyTorch extensions for fast R&D prototyping and Kaggle farming

Pytorch-toolbelt A pytorch-toolbelt is a Python library with a set of bells and whistles for PyTorch for fast R&D prototyping and Kaggle farming: What

Eugene Khvedchenya 1.3k Jan 5, 2023
An implementation of Performer, a linear attention-based transformer, in Pytorch

Performer - Pytorch An implementation of Performer, a linear attention-based transformer variant with a Fast Attention Via positive Orthogonal Random

Phil Wang 900 Dec 22, 2022