ShuffleNet v2
前言知识
在代码中:
setattr(self, name, nn.Sequential(*seq))
语法: setattr(object, name, value)
代码中,name 分别为 stage2,stage3,stage4
1. 模型描述
以往的神经网络架构设计主要以计算复杂度为间接指标,即 FLOPs。然而,直接的度量指标,例如速度,还取决于其他因素,例如内存访问成本和平台特性。在一系列对照实验的基础上,本文得出了一些有效网络设计的实用指南。因此,提出了一种新的架构,称为 ShuffleNet V2。综合消融实验表明,我们的模型在速度和精度权衡方面是state of-the-art 。
ShuffleNet V2 来自于:2018年
Model structure | Top-1 error | Top-5 error |
---|---|---|
shufflenet_v2 | 30.64 | 11.68 |
Model structure | 模型大小 |
---|---|
shufflenet_v2_x0_5 onnx | 5.6 MB |
shufflenet_v2_x1_0 onnx | 9.2 MB |
2. onxx 导出
参考:轻量化模型之mobilenet v3_星魂非梦的博客-CSDN博客
知识点1:pytorch chunk
x1, x2 = x.chunk(2, dim=1)
表示将x,在维度1处,分为两块 。
torch.chunk — PyTorch 1.11.0 documentation
知识点2:pytorch contiguous
Pytorch中contiguous()函数理解_清晨的光明的博客-CSDN博客_contiguous pytorch
torch.Tensor.contiguous — PyTorch 1.11.0 documentation
知识点3:
x = x.mean([2, 3]) # globalpool
因此该代码可修改为:
# Cannot use "squeeze" as batch-size can be 1 => must use reshape with x.shape[0]
x = nn.functional.adaptive_avg_pool2d(x, 1).reshape(x.shape[0], -1)
https://github.com/pytorch/vision/pull/1838
https://github.com/pytorch/vision/commit/1e27b533490d5b375c4656d2dd67961baaa1dced
pretrained shufflenetv2_x1.5 is not supported as of now
pretrained shufflenetv2_x2.0 is not supported as of now
torchvision 1.5 2.0 没提供预训练模型。
0.5x、1.0x、1.5x 和 2.0x 不同点只在于输出通道的个数。
3. 核心组件
个人导出的资源: