timm概述
概述
PyTorchImageModels,简称 timm,是一个巨大的 PyTorch 代码集合,包括了一系列:
- image models
- layers
- utilities
- optimizers
- schedulers
- data-loaders / augmentations
- training / validation scripts
旨在将各种 SOTA 模型整合在一起,并具有复现 ImageNet 训练结果的能力。虽然模型架构是 timm 的重点,但它还包括许多数据增强 (data augmentations)、正则化技术 (regularization techniques)、优化器 (optimizers) 和学习率策略 (learning rate schedulers) 的实现。
作者github链接:rwightman - Overview (opens new window) timm库链接:rwightman/pytorch-image-models (opens new window)
timm库特点
所有的模型都有默认的API
- accessing/changing the classifier -
get_classifier
andreset_classifier
- 只对features做前向传播 -
forward_features
所有模型都支持多尺度特征提取 (feature pyramids) (通过create_model函数):
create_model(name, features_only=True, out_indices=..., output_stride=...)
out_indices
指定返回哪个feature maps to return, 从0开始,out_indices[i]
对应着 C(i + 1)
feature level。
output_stride
通过dilated convolutions控制网络的output stride。大多数网络默认 stride 32 。
所有的模型都有一致的pretrained weight loader,adapts last linear if necessary。
训练方式支持
NVIDIA DDP w/ a single GPU per process, multiple processes with APEX present (AMP mixed-precision optional)
PyTorch DistributedDataParallel w/ multi-gpu, single process (AMP disabled as it crashes when enabled)
PyTorch w/ single GPU single process (AMP optional)
动态的全局池化方式可以选择:average pooling, max pooling, average + max, or concat([average, max]),默认是adaptive average。
Schedulers:
Schedulers 包括step
,cosine
w/ restarts,tanh
w/ restarts,plateau
。
Optimizer:
rmsprop_tf
adapted from PyTorch RMSProp by myself. Reproduces much improved Tensorflow RMSProp behaviour.radam
by https://github.com/LiyuanLucasLiu/RAdam (opens new window) (https://arxiv.org/abs/1908.03265 (opens new window))novograd
by https://github.com/convergence-lab/novograd (opens new window) (https://arxiv.org/abs/1905.11286 (opens new window))lookahead
adapted from impl by https://github.com/alphadl/lookahead.pytorch (opens new window) (https://arxiv.org/abs/1907.08610 (opens new window))fused<name>
optimizers by name with https://github.com/NVIDIA/apex/tree/master/apex/optimizers (opens new window) installedadamp
andsgdp
by https://github.com/clovaai (opens new window) (https://arxiv.org/abs/2006.08217 (opens new window))adafactor
adapted from https://github.com/pytorch/fairseq/blob/master/fairseq/optim/adafactor.py (opens new window) (https://arxiv.org/abs/1804.04235 (opens new window))adahessian
by https://github.com/davda54/ada-hessian (opens new window) (https://arxiv.org/abs/2006.00719 (opens new window))