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
最新推荐文章于 2023-05-09 19:06:52 发布