东方耀AI技术分享

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 5233|回复: 1

[课堂笔记] htop和thop傻傻分不清楚

[复制链接]

1365

主题

1856

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14429
QQ
发表于 2020-10-31 09:42:41 | 显示全部楼层 |阅读模式


htop和thop傻傻分不清楚




Pytorch: 用thop计算pytorch模型的FLOPs
pip3 install thop




from torchvision.models import resnet50
from thop import profile
model = resnet50()
input = torch.randn(1, 3, 224, 224)
flops, params = profile(model, inputs=(input, ))






查看自己模型的FLOPs
class YourModule(nn.Module):
    # your definition
def count_your_model(model, x, y):
    # your rule here


input = torch.randn(1, 3, 224, 224)
flops, params = profile(model, inputs=(input, ),
                        custom_ops={YourModule: count_your_model})






提升输出结果的可读性
调用thop.clever_format




from thop import clever_format
flops, params = clever_format([flops, params], "%.3f")




htop.png
让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

0

主题

100

帖子

236

积分

2W人工智能培训

Rank: 10Rank: 10Rank: 10

积分
236
发表于 2020-11-10 19:50:46 | 显示全部楼层
积分积分积分
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|人工智能工程师的摇篮 ( 湘ICP备2020019608号-1 )

GMT+8, 2024-4-19 02:03 , Processed in 0.191880 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表