输出ShuffleNetV2通道数
# 查看网络通道数
from mmcls.models import ShuffleNetV1, ShuffleNetV2, MobileNetV2, MobileNetV3, EfficientNet
import torch
# m = MobileNetV3(out_indices=(3, 8, 11))
m = ShuffleNetV2(out_indices=(0,1,2,3))
# m = EfficientNet(out_indices=(0,1,2,3))
m.eval()
inputs = torch.rand(1, 3, 224, 224)
level_outputs = m(inputs)
for level_out in level_outputs:
print(tuple(level_out.shape))
# (1, 116, 80, 80)
# (1, 232, 40, 40)
# (1, 464, 20, 20)
# (1, 1024, 20, 20)
可以看出0,1,2,3对应通道数为116,232,464,1024
输出efficientnet通道数
import torch
from mmcls.models.backbones import EfficientNet
# 创建 EfficientNet 模型
model = EfficientNet(arch='b3')
# 输入随机数据进行推断
input_data = torch.randn(1, 3, 224, 224)
outputs = model(input_data)
# 输出每个层级的形状
#for i, output in enumerate(outputs):
# print(f"Level {i} output shape: {output.shape}")
# 逐层遍历模型的子模块,以获取所有层级的输出形状
for i, layer in enumerate(model.layers):
input_data = layer(input_data)
print(f"Level {i} output shape: {input_data.shape}")
'b0'
Level 0 output shape: torch.Size([1, 32, 112, 112])
Level 1 output shape: torch.Size([1, 16, 112, 112])
Level 2 output shape: torch.Size([1, 24, 56, 56])
Level 3 output shape: torch.Size([1, 40, 28, 28])
Level 4 output shape: torch.Size([1, 112, 14, 14])
Level 5 output shape: torch.Size([1, 320, 7, 7])
Level 6 output shape: torch.Size([1, 1280, 7, 7])
# 'b1'
Level 0 output shape: torch.Size([1, 32, 112, 112])
Level 1 output shape: torch.Size([1, 16, 112, 112])
Level 2 output shape: torch.Size([1, 24, 56, 56])
Level 3 output shape: torch.Size([1, 40, 28, 28])
Level 4 output shape: torch.Size([1, 112, 14, 14])
Level 5 output shape: torch.Size([1, 320, 7, 7])
Level 6 output shape: torch.Size([1, 1280, 7, 7])
'b2'
Level 0 output shape: torch.Size([1, 32, 112, 112])
Level 1 output shape: torch.Size([1, 16, 112, 112])
Level 2 output shape: torch.Size([1, 24, 56, 56])
Level 3 output shape: torch.Size([1, 48, 28, 28])
Level 4 output shape: torch.Size([1, 120, 14, 14])
Level 5 output shape: torch.Size([1, 352, 7, 7])
Level 6 output shape: torch.Size([1, 1408, 7, 7])
'b3'
Level 0 output shape: torch.Size([1, 40, 112, 112])
Level 1 output shape: torch.Size([1, 24, 112, 112])
Level 2 output shape: torch.Size([1, 32, 56, 56])
Level 3 output shape: torch.Size([1, 48, 28, 28])
Level 4 output shape: torch.Size([1, 136, 14, 14])
Level 5 output shape: torch.Size([1, 384, 7, 7])
Level 6 output shape: torch.Size([1, 1536, 7, 7])
'b4'
Level 0 output shape: torch.Size([1, 48, 112, 112])
Level 1 output shape: torch.Size([1, 24, 112, 112])
Level 2 output shape: torch.Size([1, 32, 56, 56])
Level 3 output shape: torch.Size([1, 56, 28, 28])
Level 4 output shape: torch.Size([1, 160, 14, 14])
Level 5 output shape: torch.Size([1, 448, 7, 7])
Level 6 output shape: torch.Size([1, 1792, 7, 7])
'b5'
Level 0 output shape: torch.Size([1, 48, 112, 112])
Level 1 output shape: torch.Size([1, 24, 112, 112])
Level 2 output shape: torch.Size([1, 40, 56, 56])
Level 3 output shape: torch.Size([1, 64, 28, 28])
Level 4 output shape: torch.Size([1, 176, 14, 14])
Level 5 output shape: torch.Size([1, 512, 7, 7])
Level 6 output shape: torch.Size([1, 2048, 7, 7])
'b6'
Level 0 output shape: torch.Size([1, 56, 112, 112])
Level 1 output shape: torch.Size([1, 32, 112, 112])
Level 2 output shape: torch.Size([1, 40, 56, 56])
Level 3 output shape: torch.Size([1, 72, 28, 28])
Level 4 output shape: torch.Size([1, 200, 14, 14])
Level 5 output shape: torch.Size([1, 576, 7, 7])
Level 6 output shape: torch.Size([1, 2304, 7, 7])
'b7'
Level 0 output shape: torch.Size([1, 64, 112, 112])
Level 1 output shape: torch.Size([1, 32, 112, 112])
Level 2 output shape: torch.Size([1, 48, 56, 56])
Level 3 output shape: torch.Size([1, 80, 28, 28])
Level 4 output shape: torch.Size([1, 224, 14, 14])
Level 5 output shape: torch.Size([1, 640, 7, 7])
Level 6 output shape: torch.Size([1, 2560, 7, 7])