timm
官方文档
Model Summaries - Pytorch Image Models (rwightman.github.io)
安装
建立模型
1 2 3 4 import timmm = timm.create_model('mobilenetv3_large_100' , pretrained=True ) m.eval ()
1 2 3 4 import timmfrom pprint import pprintmodel_names = timm.list_models(pretrained=True ) pprint(model_names)
模块调用
Training Examples - Pytorch Image Models (rwightman.github.io)
Feature Extraction - Pytorch Image Models (rwightman.github.io)
1 2 3 4 5 import torchimport timmm = timm.create_model('resnet50' , pretrained=True , num_classes=0 , global_pool='' ) o = m(torch.randn(2 , 3 , 224 , 224 )) print (f'Unpooled shape: {o.shape} ' )
pretrainedmodels
https://github.com/Cadene/pretrained-models.pytorch
1 2 3 import pretrainedmodelsprint (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' ]
1 2 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 }}
1 2 3 model_name = 'nasnetalarge' model = pretrainedmodels.__dict__[model_name](num_classes=1000 , pretrained='imagenet' ) model.eval ()
各种ViT
https://github.com/lucidrains/vit-pytorch
专栏:https://www.zhihu.com/column/c_1260183218026213376
torchsummary可视化
安装
1 pip install torchsummary
使用方法
1 2 3 4 5 import torch, torchvisionmodel = torchvision.models.vgg model = torchvision.models.vgg16() from torchsummary import summarysummary(model, (3 , 224 , 224 ))
可视化
https://github.com/utkuozbulak/pytorch-cnn-visualizations
https://github.com/JonnesLin/Evison
https://www.jianshu.com/p/0431d6d89d8e
CAM可视化:
https://github.com/jacobgil/pytorch-grad-cam
t-SNE可视化
DmitryUlyanov/Multicore-TSNE: Parallel t-SNE implementation with Python and Torch wrappers. (github.com)
CannyLab/tsne-cuda: GPU Accelerated t-SNE for CUDA with Python bindings (github.com)
优雅地操作张量维度
PyTorch 70.einops:优雅地操作张量维度 - 知乎 (zhihu.com)
可微cv库
官方文档
https://kornia.readthedocs.io/en/latest/index.html
其它
基于 PyTorch 的开源 图像视频复原工具箱, 比如 超分辨率, 去噪, 去模糊, 去 JPEG 压缩噪声等.
https://github.com/xinntao/BasicSR
去雨去噪去模糊
hpcaitech/ColossalAI: Colossal-AI: A Unified Deep Learning System for Large-Scale Parallel Training (github.com)
用于模型训练
fairscale
hpcaitech/ColossalAI: Colossal-AI: A Unified Deep Learning System for Large-Scale Parallel Training (github.com)
GAN
eriklindernoren/PyTorch-GAN: PyTorch implementations of Generative Adversarial Networks. (github.com)
AutoDL
D-X-Y/AutoDL-Projects: Automated deep learning algorithms implemented in PyTorch. (github.com)
攻击&防御
https://github.com/thu-ml/ares
调参
https://github.com/optuna/optuna
用Optuna进行Pytorch超参数调优教程 - 知乎 (zhihu.com)
https://github.com/ray-project/ray
AutoML: 自动调参工具-Ray Tune - 知乎 (zhihu.com)
scikit-optimize: sequential model-based optimization in Python — scikit-optimize 0.8.1 documentation
ml_collections
ML Collections是为ML use cases而设计的一个Python Collections的一个库。它的两个类是ConfigDict和FrozenConfigDict,是"dict-like" 的数据结构,以下是ConfigDict、FrozenConfigDict和FieldReference的示例用法,
https://blog.csdn.net/weixin_47066348/article/details/113954876
Welcome to ml_collections’s documentation! — ml_collections 0.1.0 documentation (ml-collections.readthedocs.io)
https://github.com/google/ml_collections
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 import ml_collectionscfg = ml_collections.ConfigDict() cfg.float_field = 12.6 cfg.integer_field = 123 cfg.another_integer_field = 234 cfg.nested = ml_collections.ConfigDict() cfg.nested.string_field = 'tom' print (cfg.integer_field) print (cfg['integer_field' ]) try : cfg.integer_field = 'tom' except TypeError as e: print (e) cfg.float_field = 12 cfg.nested.string_field = u'bob' print (cfg)输出 123 123 Could not override field 'integer_field' (reference). tom is of type <class 'str' > but should be of type <class 'int' > another_integer_field: 234 float_field: 12.0 integer_field: 123 nested: string_field: bob
不可以改变的ConfigDict
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 import ml_collectionsinitial_dictionary = { 'int' : 1 , 'list' : [1 , 2 ], 'tuple' : (1 , 2 , 3 ), 'set' : {1 , 2 , 3 , 4 }, 'dict_tuple_list' : {'tuple_list' : ([1 , 2 ], 3 )} } cfg = ml_collections.ConfigDict(initial_dictionary) frozen_dict = ml_collections.FrozenConfigDict(initial_dictionary) print (frozen_dict.tuple ) print (frozen_dict.list ) print (frozen_dict.set ) print (frozen_dict.dict_tuple_list.tuple_list[0 ]) frozen_cfg = ml_collections.FrozenConfigDict(cfg) print (frozen_cfg == frozen_dict) print (hash (frozen_cfg) == hash (frozen_dict)) try : frozen_dict.int = 2 except AttributeError as e: print (e) thawed_frozen_cfg = ml_collections.ConfigDict(frozen_dict) print (thawed_frozen_cfg == cfg) frozen_cfg_to_cfg = frozen_dict.as_configdict() print (frozen_cfg_to_cfg == cfg)
可解释性
https://github.com/pytorch/captum
沙普利值,归因