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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
| def shufflenet_1x(num_classes=10):
return ShuffleNetV2(1, num_classes)
model=shufflenet_1x()
from torchstat import stat
a=torch.randn(1,3,224,224)
# print(model(a))
"""通过torchstat.stat 可以查看网络模型的参数量和计算复杂度FLOPs"""
from torchstat import stat
# stat(model,(3,224,224))
#=======================================================================================================================================================
#Total params: 561,706
#-------------------------------------------------------------------------------------------------------------------------------------------------------
#Total memory: 6.88MB
#Total MAdd: 79.01MMAdd
#Total Flops: 39.96MFlops
#Total MemR+W: 14.08MB
"""thop工具包仅支持FLOPs和参数量的计算"""
# from thop import profile
# from thop import clever_format
# input=torch.randn(1,3,224,224)
# flops, params = profile(model, inputs=(input, ))
# print(flops, params) # 46388784.0 561706.0
# flops, params = clever_format([flops, params], "%.3f")
# print(flops, params) # 46.389M 561.706K
"""ptflops统计 参数量 和 FLOPs"""
from ptflops import get_model_complexity_info
macs, params = get_model_complexity_info(model, (3, 224, 224), as_strings=True,
print_per_layer_stat=True, verbose=True)
print('{:<30} {:<8}'.format('Computational complexity: ', macs))
print('{:<30} {:<8}'.format('Number of parameters: ', params))
#Computational complexity: 0.05 GMac
#Number of parameters: 1.26 M
"""torchsummary 用来计算网络的计算参数等信息"""
from torchsummary import summary
model2 = ShuffleNetV2(scale=1.5, in_channels=3, c_tag=0.5, num_classes=10, activation=nn.ReLU,SE=False, residual=False)
a=torch.randn(1,3,224,224)
summary(model2.cuda(),input_size=(3,224,224))
# ================================================================
#Total params: 2,489,770
#Trainable params: 2,489,770
#Non-trainable params: 0
#----------------------------------------------------------------
#Input size (MB): 0.57
#Forward/backward pass size (MB): 62.77
#Params size (MB): 9.50
#Estimated Total Size (MB): 72.84
#----------------------------------------------------------------
|