模型复杂度

大小

直接看文件大小

模型复杂度

mmcls:

可参考:
https://mmclassification.readthedocs.io/zh_CN/latest/tools/analysis.html

python tools/analysis_tools/get_flops.py ${CONFIG_FILE} [--shape ${INPUT_SHAPE}]

单张图像的推理
或者直接在demo/image_demo.py中用profile(通用)

pip install thop


from thop import profile
input = torch.randn(1, 3, 64, 64).to(device)  # 放进和model相同的GPU中
flops, params = profile(model, inputs=(input,), verbose=True)
print("%s ------- params: %.2fMB ------- flops: %.2fG" % (model, params / (1000 ** 2), flops / (1000 ** 3)))  # 这里除以1000的平方,是为了化成M的单位

注意:用thop是GMACs, GFLOPs可能需要GMACs乘以2。

推理时间

torch.cuda.synchronize()
start = time.time()

result = model(input)

torch.cuda.synchronize()
end = time.time()