الهدف من هذا الريبو هو:
أخبار:
pip install pretrainedmodels ، pretrainedmodels.model_names ، pretrainedmodels.pretrained_settingspython setup.py installgit pull )model.last_linear واجهة model.features(input) model.logits(features) model.forward(input)pip install pretrainedmodelsgit clone https://github.com/Cadene/pretrained-models.pytorch.gitcd pretrained-models.pytorchpython setup.py install pretrainedmodels : import pretrainedmodels 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' ] 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 }} model_name = 'nasnetalarge' # could be fbresnet152 or inceptionresnetv2
model = pretrainedmodels . __dict__ [ model_name ]( num_classes = 1000 , pretrained = 'imagenet' )
model . eval () ملاحظة : بشكل افتراضي ، سيتم تنزيل النماذج إلى مجلد $HOME/.torch . يمكنك تعديل هذا السلوك باستخدام متغير $TORCH_HOME على النحو التالي: export TORCH_HOME="/local/pretrainedmodels"
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 output_features = model . features ( input ) # 1x14x14x2048 size may differ
output_logits = model . logits ( output_features ) # 1x1000 $ 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'
$ python examples/imagenet_eval.py /local/common-data/imagenet_2012/images -a nasnetalarge -b 20 -e
> * Acc@1 82.693, Acc@5 96.13
تم الحصول على النتائج باستخدام الصور (المركز القائم) من نفس الحجم مما كانت عليه أثناء عملية التدريب.
| نموذج | إصدار | ACC@1 | ACC@5 |
|---|---|---|---|
| pnasnet-5-large | Tensorflow | 82.858 | 96.182 |
| pnasnet-5-large | النقل لدينا | 82.736 | 95.992 |
| nasnet-a-large | Tensorflow | 82.693 | 96.163 |
| nasnet-a-large | النقل لدينا | 82.566 | 96.086 |
| Senet154 | الكافيين | 81.32 | 95.53 |
| Senet154 | النقل لدينا | 81.304 | 95.498 |
| بولينيت | الكافيين | 81.29 | 95.75 |
| بولينيت | النقل لدينا | 81.002 | 95.624 |
| InceptionResnetv2 | Tensorflow | 80.4 | 95.3 |
| InceptionV4 | Tensorflow | 80.2 | 95.3 |
| se-resnext101_32x4d | النقل لدينا | 80.236 | 95.028 |
| se-resnext101_32x4d | الكافيين | 80.19 | 95.04 |
| InceptionResnetv2 | النقل لدينا | 80.170 | 95.234 |
| InceptionV4 | النقل لدينا | 80.062 | 94.926 |
| DualPathNet107_5k | النقل لدينا | 79.746 | 94.684 |
| resnext101_64x4d | Torch7 | 79.6 | 94.7 |
| DualPathnet131 | النقل لدينا | 79.432 | 94.574 |
| DualPathnet92_5k | النقل لدينا | 79.400 | 94.620 |
| DualPathnet98 | النقل لدينا | 79.224 | 94.488 |
| se-resnext50_32x4d | النقل لدينا | 79.076 | 94.434 |
| se-resnext50_32x4d | الكافيين | 79.03 | 94.46 |
| Xception | كيراس | 79.000 | 94.500 |
| resnext101_64x4d | النقل لدينا | 78.956 | 94.252 |
| Xception | النقل لدينا | 78.888 | 94.292 |
| resnext101_32x4d | Torch7 | 78.8 | 94.4 |
| SE-RESNET152 | الكافيين | 78.66 | 94.46 |
| SE-RESNET152 | النقل لدينا | 78.658 | 94.374 |
| RESNET152 | Pytorch | 78.428 | 94.110 |
| SE-RESNET101 | النقل لدينا | 78.396 | 94.258 |
| SE-RESNET101 | الكافيين | 78.25 | 94.28 |
| resnext101_32x4d | النقل لدينا | 78.188 | 93.886 |
| fbresnet152 | Torch7 | 77.84 | 93.84 |
| SE-RESNET50 | الكافيين | 77.63 | 93.64 |
| SE-RESNET50 | النقل لدينا | 77.636 | 93.752 |
| Densenet161 | Pytorch | 77.560 | 93.798 |
| RESNET101 | Pytorch | 77.438 | 93.672 |
| fbresnet152 | النقل لدينا | 77.386 | 93.594 |
| InceptionV3 | Pytorch | 77.294 | 93.454 |
| Densenet201 | Pytorch | 77.152 | 93.548 |
| DualPathNet68b_5k | النقل لدينا | 77.034 | 93.590 |
| cafferesnet101 | الكافيين | 76.400 | 92.900 |
| cafferesnet101 | النقل لدينا | 76.200 | 92.766 |
| Densenet169 | Pytorch | 76.026 | 92.992 |
| RESNET50 | Pytorch | 76.002 | 92.980 |
| DualPathnet68 | النقل لدينا | 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 | النقل لدينا | 74.080 | 91.740 |
| resnet34 | Pytorch | 73.554 | 91.456 |
| bninception | النقل لدينا | 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 |
| اليكسنيت | Pytorch | 56.432 | 79.194 |
ملحوظات:
احذر ، فإن الدقة المذكورة هنا لا تمثل دائمًا السعة القابلة للتحويل للشبكة في المهام الأخرى ومجموعات البيانات. يجب أن تجربهم جميعًا! : ص
يرجى الاطلاع على مقاييس التحقق من صحة ImageNet
المصدر: Tensorflow Slim Repo
nasnetalarge(num_classes=1000, pretrained='imagenet')nasnetalarge(num_classes=1001, pretrained='imagenet+background')nasnetamobile(num_classes=1000, pretrained='imagenet') المصدر: Torch7 Repo of Facebook
هناك اختلاف قليلاً عن resnet* من torchvision. RESNET152 هو حاليا الوحيد المتاح.
fbresnet152(num_classes=1000, pretrained='imagenet') المصدر: كافي ريبو من Kaiminghe
cafferesnet101(num_classes=1000, pretrained='imagenet') المصدر: Tensorflow Slim Repo و 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') المصدر: مدرب مع الكافيين من قبل Xiong Yuanjun
bninception(num_classes=1000, pretrained='imagenet') المصدر: RESNEXT REPO من Facebook
resnext101_32x4d(num_classes=1000, pretrained='imagenet')resnext101_62x4d(num_classes=1000, pretrained='imagenet') المصدر: MXNET Repo of Chen Yunpeng
أصبح النورف ممكنًا من قبل روس وايتمان في ريبو Pytorch.
كما ترون هنا يتيح لك DualPathNetWorks تجربة موازين مختلفة. الافتراضي في هذا الريبو هو 0.875 يعني أن حجم الإدخال الأصلي هو 256 قبل الاقتصاد إلى 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' تعني أن الشبكة قد تم تجهيزها على ImageNet5K قبل أن يتم تحريكها على ImageNet1k.
المصدر: كيراس ريبو
أصبح النقل ممكنًا من قِبل T Standley.
xception(num_classes=1000, pretrained='imagenet') المصدر: كافي ريبو من جي هو
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') المصدر: Tensorflow Slim Repo
pnasnet5large(num_classes=1000, pretrained='imagenet')pnasnet5large(num_classes=1001, pretrained='imagenet+background') المصدر: كافي ريبو من مختبر الوسائط المتعددة Cuhk
polynet(num_classes=1000, pretrained='imagenet') المصدر: Pytorch/Vision Repo
( inceptionv3 مدرج في البداية*)
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')بمجرد تحميل نموذج مسبق ، يمكنك استخدامه بهذه الطريقة.
ملاحظة مهمة : يجب تحميل جميع الصور باستخدام PIL التي تحدد قيم البكسل بين 0 و 1.
model.input_size يعزى list النوع المكونة من 3 أرقام:
مثال:
[3, 299, 299] للشبكات*[3, 224, 224] لشبكات Resnet*. model.input_space يعزى من نوع str تمثيل مساحة لون الصورة. يمكن أن يكون RGB أو BGR .
model.input_range يعزى list النوع المكونة من رقمين:
مثال:
[0, 1] لـ Resnet* و Inception* شبكات ،[0, 255] لشبكة bninception. model.mean يعزى list النوع المكونة من 3 أرقام تُستخدم لتطبيع صورة الإدخال (الفرعية "القناة الملونة").
مثال:
[0.5, 0.5, 0.5] للشبكات*[0.485, 0.456, 0.406] لشبكات Resnet*. model.std يعزى list النوع المكونة من 3 أرقام تستخدم لتطبيع صورة الإدخال (قسّم "قناة الألوان").
مثال:
[0.5, 0.5, 0.5] للشبكات*[0.229, 0.224, 0.225] لشبكات Resnet*. model.features/! العمل قيد التقدم (قد لا يكون متاحًا)
الطريقة التي يتم استخدامها لاستخراج الميزات من الصورة.
مثال عندما يتم تحميل النموذج باستخدام 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/! العمل قيد التقدم (قد لا يكون متاحًا)
الطريقة التي يتم استخدامها لتصنيف الميزات من الصورة.
مثال عندما يتم تحميل النموذج باستخدام fbresnet152 :
output = model . features ( input_224 )
print ( output . size ()) # (1,2048, 1, 1)
output = model . logits ( output )
print ( output . size ()) # (1,1000) model.forward الطريقة المستخدمة لاستدعاء model.features model.logits يمكن الكتابة فوقها حسب الرغبة.
ملاحظة : الممارسة الجيدة هي استخدام model.__call__ كوظيفة اختيارك لإعادة توجيه إدخال إلى النموذج الخاص بك. انظر المثال يملأ.
# 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 يعزى من النوع nn.Linear . هذه الوحدة هي آخر وحدة يتم استدعاؤها خلال التمريرة الأمامية.
nn.Linear المكيّنة لضبط جيد.pretrained.utils.Identity لاستخراج الميزات. مثال عندما يتم تحميل النموذج باستخدام 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) th pretrainedmodels/fbresnet/resnet152_dump.lua
python pretrainedmodels/fbresnet/resnet152_load.py
https://github.com/clcarwin/convert_torch_to_pytorch
https://github.com/cadene/tensorflow-model-zoo.torch
بفضل مجتمع التعلم العميق وخاصة للمساهمين في النظام الإيكولوجي Pytorch.