锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

视觉神经网络模型优秀开源工作:PyTorch Image Models(timm)库

时间:2022-12-26 09:30:00 101e电位器trimmercj19b电容器接触器

视觉神经网络模型优秀开源工作:PyTorch Image Models(timm)库

PyTorchImageModels,简称timm,是巨大的PyTorch包括一系列代码集:

  • image models
  • layers
  • utilities
  • optimizers
  • schedulers
  • data-loaders / augmentations
  • training / validation scripts

旨在将各种SOTA模型集成在一起,复制ImageNet训练结果的能力。

PyTorch Image Models(timm) 优秀的图像分类 Python 它包含了大量的图像模型(Image Models)、Optimizers、Schedulers、Augmentations 等等.

除了使用torchvision.models除了预训练,还有一个常见的预训练模型库,叫做预训练timm,这个库来自加拿大温哥华Ross Wightman创建的。它提供了许多计算机视觉SOTA模型,可视为是torchvision扩展版本,模型的准确性也很高。在本章中,我们主要描述了图书馆预训练模型的使用。如果您感兴趣,可以参考以下链接(数据扩展、优化器等)。

  • Github链接:https://github.com/rwightman/pytorch-image-models
  • 官网链接:https://fastai.github.io/timmdocs/ https://rwightman.github.io/pytorch-image-models/
  • 简略文档:https://rwightman.github.io/pytorch-image-models/
  • 详细文档:https://fastai.github.io/timmdocs/

安装

PyTorch Image Models(timm) 优秀的图像分类 Python 它包含了大量的图像模型(Image Models)、Optimizers、Schedulers、Augmentations 等等.

timm 提供参考 training 和 validation 脚本,用于复现 ImageNet 训练结果;以及更多 官方文档 和 timmdocs project.

https://rwightman.github.io/pytorch-image-models/

https://fastai.github.io/timmdocs/

但,由于 timm 有很多功能,所以在定制使用时很难知道如何开始. 这里主要进行概述.

pip install timm==0.5.4 

所有的开发和测试都是在 Linux x86-64系统上的 Conda Python 3.在环境中完成,特别是 Python 3.6和3.7 3.8 3.9
PyTorch 版本1.4、1.5. x、1.6、1.7. x 和1.该代码已用于测试。

import timm 

加载预训练模型

我们只需要简单create_model如果我们需要使用我们的预训练模型,我们只需要添加参数pretrained=True即可

import timm  m = timm.create_model('mobilenetv3_large_100', pretrained=True) m.eval() MobileNetV3(   (conv_stem): Conv2d(3, 16, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)   (bn1): BatchNorm2d(16, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act1): Hardswish() (blocks): Sequential( (0): Sequential( (0): DepthwiseSeparableConv( (conv_dw): Conv2d(16, 16, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=16, bias=False) (bn1): BatchNorm2d(16, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act1): ReLU(inplace=True) (se): Identity() (conv_pw): Conv2d(16, 16, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn2): BatchNorm2d(16, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act2): Identity() ) ) (1): Sequential( (0): InvertedResidual( (conv_pw): Conv2d(16, 64, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act1): ReLU(inplace=True) (conv_dw): Conv2d(64, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), groups=64, bias=False) (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act2): ReLU(inplace=True) (se): Identity() (conv_pwl): Conv2d(64, 24, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(24, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) ) (1): InvertedResidual( (conv_pw): Conv2d(24, 72, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(72, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act1): ReLU(inplace=True) (conv_dw): Conv2d(72, 72, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=72, bias=False) (bn2): BatchNorm2d(72, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act2): ReLU(inplace=True) (se): Identity() (conv_pwl): Conv2d(72, 24, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(24, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) ) ) (2): Sequential( (0): InvertedResidual( (conv_pw): Conv2d(24, 72, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(72, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act1): ReLU(inplace=True) (conv_dw): Conv2d(72, 72, kernel_size=(5, 5), stride=(2, 2), padding=(2, 2), groups=72, bias=False) (bn2): BatchNorm2d(72, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act2): ReLU(inplace=True) (se): SqueezeExcite( (conv_reduce): Conv2d(72, 24, kernel_size=(1, 1), stride=(1, 1)) (act1): ReLU(inplace=True) (conv_expand): Conv2d(24, 72, kernel_size=(1, 1), stride=(1, 1)) (gate): Hardsigmoid() ) (conv_pwl): Conv2d(72, 40, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(40, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) ) (1): InvertedResidual( (conv_pw): Conv2d(40, 120, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(120, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act1): ReLU(inplace=True) (conv_dw): Conv2d(120, 120, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=120, bias=False) (bn2): BatchNorm2d(120, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act2): ReLU(inplace=True) (se): SqueezeExcite( (conv_reduce): Conv2d(120, 32, kernel_size=(1, 1), stride=(1, 1)) (act1): ReLU(inplace=True) (conv_expand): Conv2d(32, 120, kernel_size=(1, 1), stride=(1, 1)) (gate): Hardsigmoid() ) (conv_pwl): Conv2d(120, 40, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(40, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) ) (2): InvertedResidual( (conv_pw): Conv2d(40, 120, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(120, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act1): ReLU(inplace=True) (conv_dw): Conv2d(120, 120, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=120, bias=False) (bn2): BatchNorm2d(120, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act2): ReLU(inplace=True) (se): SqueezeExcite( (conv_reduce): Conv2d(120, 32, kernel_size=(1, 1), stride=(1, 1)) (act1): ReLU(inplace=True) (conv_expand): Conv2d(32, 120, kernel_size=(1, 1), stride=(1, 1)) (gate): Hardsigmoid() ) (conv_pwl): Conv2d(120, 40, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(40, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) ) ) (3): Sequential( (0): InvertedResidual( (conv_pw): Conv2d(40, 240, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(240, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act1): Hardswish() (conv_dw): Conv2d(240, 240, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), groups=240, bias=False) (bn2): BatchNorm2d(240, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act2): Hardswish() (se): Identity() (conv_pwl): Conv2d(240, 80, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(80, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) ) (1): InvertedResidual( (conv_pw): Conv2d(80, 200, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(200, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act1): Hardswish() (conv_dw): Conv2d(200, 200, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=200, bias=False) (bn2): BatchNorm2d(200, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act2): Hardswish() (se): Identity() (conv_pwl): Conv2d(200, 80, kernel_size=(1, 1), stride=(1, 1), bias=False) (<

相关文章