推荐几个非常好用的计算flops、params、内存…的工具
1、ptflops
使用方法如下:
import torch
import torchvision.models as models
# import torch
from ptflops import get_model_complexity_info
model = resnet34(num_classes=5)
model_weight_path ='xxxx'
model.load_state_dict(torch.load(model_weight_path),False)
model_name = 'xxxx'
flops, params = get_model_complexity_info(model, (3, 300, 300), as_strings=True, print_per_layer_stat=True)
# print("%s |%s |%s" % (model_name, flops, params))
print("model_name",model_name)
print("flops:",flops)
print("params:",params)
实际图片中的内容并不是resnet的结果哈,只是使用方法打个比方,它可以详细的展示每一层的flops、params、MACs情况
2、torchsummary
from torchsummary import summary
model = resnet34(num_classes=5)
# # load model weights
model_weight_path =r"xxxxx" # "./resNet34.pth"
model.load_state_dict(torch.load(model_weight_path),False)
print(summary(model, (3, 300, 300)))
print(model, (3, 300, 300))
可以展示卷积的大小、params,可以直观的看到,方便修改网络结构。
3、torchstat
感觉最后这个简直是个神器了。
https://github.com/Swall0w/torchstat
使用方法官网有介绍哦。