thop 计算flops和params

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的单位

你可能感兴趣的:(python,AI,深度学习,pytorch,神经网络)