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:
- 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 pullis 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
- Quick examples
- Few use cases
- Evaluation on ImageNet
- Documentation
- Available models
- AlexNet
- BNInception
- CaffeResNet101
- DenseNet121
- DenseNet161
- DenseNet169
- DenseNet201
- DenseNet201
- DualPathNet68
- DualPathNet92
- DualPathNet98
- DualPathNet107
- DualPathNet113
- FBResNet152
- InceptionResNetV2
- InceptionV3
- InceptionV4
- NASNet-A-Large
- NASNet-A-Mobile
- PNASNet-5-Large
- PolyNet
- ResNeXt101_32x4d
- ResNeXt101_64x4d
- ResNet101
- ResNet152
- ResNet18
- ResNet34
- ResNet50
- SENet154
- SE-ResNet50
- SE-ResNet101
- SE-ResNet152
- SE-ResNeXt50_32x4d
- SE-ResNeXt101_32x4d
- SqueezeNet1_0
- SqueezeNet1_1
- VGG11
- VGG13
- VGG16
- VGG19
- VGG11_BN
- VGG13_BN
- VGG16_BN
- VGG19_BN
- Xception
- Model API
- Available models
- Reproducing porting
Installation
Install from pip
pip install pretrainedmodels
Install from repo
git clone https://github.com/Cadene/pretrained-models.pytorch.gitcd pretrained-models.pytorchpython 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_MODEL_ZOO variable as follow: export TORCH_MODEL_ZOO="/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
- See examples/imagenet_logits.py to compute logits of classes appearance over a single image with a pretrained model on imagenet.
$ python examples/imagenet_logits.py -h
> nasnetalarge, resnet152, inceptionresnetv2, inceptionv4, ...
$ python examples/imagenet_logits.py -a nasnetalarge --path_img data/cat.png
> 'nasnetalarge': data/cat.png' is a 'tiger cat'
Compute imagenet evaluation metrics
- See examples/imagenet_eval.py to evaluate pretrained models on imagenet valset.
$ python examples/imagenet_eval.py /local/common-data/imagenet_2012/images -a nasnetalarge -b 20 -e
> * Acc@1 92.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.522 | 91.560 |
| 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!
Pretrained models for Pytorch (Work in progress)的更多相关文章
- Caffe2 载入预训练模型(Loading Pre-Trained Models)[7]
这一节我们主要讲述如何使用预训练模型.Ipython notebook链接在这里. 模型下载 你可以去Model Zoo下载预训练好的模型,或者使用Caffe2的models.download模块获取 ...
- (转载)PyTorch代码规范最佳实践和样式指南
A PyTorch Tools, best practices & Styleguide 中文版:PyTorch代码规范最佳实践和样式指南 This is not an official st ...
- pytorch中tensorboardX的用法
在代码中改好存储Log的路径 命令行中输入 tensorboard --logdir /home/huihua/NewDisk1/PycharmProjects/pytorch-deeplab-xce ...
- (转)Awesome PyTorch List
Awesome-Pytorch-list 2018-08-10 09:25:16 This blog is copied from: https://github.com/Epsilon-Lee/Aw ...
- Ubuntu 16.04上源码编译和安装pytorch教程,并编写C++ Demo CMakeLists.txt | tutorial to compile and use pytorch on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/54e7a3d8/,欢迎阅读最新内容! tutorial to compile and use pytorch on ubuntu ...
- (转) The Incredible PyTorch
转自:https://github.com/ritchieng/the-incredible-pytorch The Incredible PyTorch What is this? This is ...
- Run Your Tensorflow Deep Learning Models on Google AI
People commonly tend to put much effort on hyperparameter tuning and training while using Tensoflow& ...
- FaceNet pre-trained模型以及FaceNet源码使用方法和讲解
Pre-trained models Model name LFW accuracy Training dataset Architecture 20180408-102900 0.9905 CASI ...
- 【翻译】OpenVINO Pre-Trained 预训练模型介绍
OpenVINO 系列软件包预训练模型介绍 本文翻译自 Intel OpenVINO 的 "Overview of OpenVINO Toolkit Pre-Trained Models& ...
随机推荐
- CF995A Tesla
题目描述 Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He kno ...
- springboot2.0 集成elasticsearch,实现检索、分页、排序
springboot整合es的方式: transport方式(7.0弃用,8.0移除) spring-data(完全当做数据库来用,无法全部支持es,内部也是基于transport,包装后使用非常简单 ...
- [LOJ #6433]「PKUSC2018」最大前缀和
题目大意:给你一个$n(n\leqslant20)$项的数列$A$,设重排后的数列为$A'$,令$pre_p=\sum\limits_{i=1}^pA'_i$,求$max\{pre_i\}$的期望,乘 ...
- 【以前的空间】bzoj1009 [HNOI2008]GT考试
动态规划+kmp+矩阵快速幂 关于这题可以写出一个dp方程(f[i,j]表示准考证前i位中后j位为不吉利的数字的前j位的情况的个数) f[i,j]=Σf[i-1,k],其中j表示不吉利数字前k个数字加 ...
- POJ1523:SPF——题解
http://poj.org/problem?id=1523 这题明显就是求割点然后求割完之后的强连通分量的个数. 割点都会求,怎么求割完的分量个数呢? 我们可以通过万能的并查集啊!(具体做法看代码吧 ...
- BZOJ1053:[HAOI2007]反素数——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1053 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4.如果某个正整数x满 ...
- bzoj2761: [JLOI2011]不重复数字(hash)
题目大意:给出N个数,要求把其中重复的去掉,只保留第一次出现的数.例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 6 5 4. ...
- [BZOJ1106/POI2007]Tet立方体大作战
Description 一个叫做立方体大作战的游戏风靡整个Byteotia.这个游戏的规则是相当复杂的,所以我们只介绍他的简单规则:给定玩家一个有2n个元素的栈,元素一个叠一个地放置.这些元素拥有n个 ...
- Java的各种中文乱码解决方法
一.Servlet输出乱码 1. 用servlet.getOutStream字节流输出中文,假设要输出的是String str ="钓鱼岛是中国的,无耻才是日本的". 1.1 若是 ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A
A. Orchestra time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...