from torchvision.models import resnet50
from thop import profile
import torch
model = resnet50()
input = torch.randn(1, 3, 224, 224)
flops, params = profile(model, inputs=(input, ))
print("%s ------- params: %.2fMB ------- flops: %.2fG" % (model, params / (1000 ** 2), flops / (1000 ** 3))) # 这里除以1000的平方,是为了化成M的单位
thop 计算flops和params
最新推荐文章于 2025-01-09 14:33:03 发布
本文介绍如何使用Thop库计算PyTorch中ResNet50模型的参数数量(Params)和计算量(FLOPs),并以MB和GFLOPs为单位展示。这对于理解模型复杂度和效率至关重要。

2187

被折叠的 条评论
为什么被折叠?



