神经网络的flops估计

pthflops的Python项目详细描述


LicenseBuild StatusPyPI

pytorch估计失败

简单的pytorch实用程序,用于估计给定网络的失败次数。目前只支持一些基本操作(基本上是我的模型所需的操作)。很快还会有更多。

欢迎所有捐款。

安装

您可以使用pip:

pip install pthflops

或者直接从github存储库:

git clone https://github.com/1adrianb/pytorch-estimate-flops && pytorch-estimate-flops
python setup.py install

示例

importtorchfromtorchvision.modelsimportresnet18frompthflopsimportcount_ops# Create a network and a corresponding inputdevice='cuda:0'model=resnet18().to(device)inp=torch.rand(1,3,224,224).to(device)# Count the number of FLOPscount_ops(model,inp)

忽略某些层:

importtorchfromtorchimportnnfrompthflopsimportcount_opsclassCustomLayer(nn.Module):def__init__(self):super(CustomLayer,self).__init__()self.conv1=nn.Conv2d(5,5,1,1,0)# ... other layers present inside will also be ignoreddefforward(self,x):returnself.conv1(x)# Create a network and a corresponding inputinp=torch.rand(1,5,7,7)net=nn.Sequential(nn.Conv2d(5,5,1,1,0),nn.ReLU(inplace=True),CustomLayer())# Count the number of FLOPscount_ops(net,inp,ignore_layers=['CustomLayer'])

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
实现接口方法时不允许java@Override   使用BuffereImage加载映像时java高ram使用率   java For循环混乱,为什么不是循环?   java Android网格视图字符串对齐问题   java如何将方法与比较类型的附加功能进行比较?   在Java Swing中放置JSepator后的间隙大小   java如何避免并发访问我的网站中的支付链接   java如何从现有的Unix服务器连接到FTP服务器?   Spring中的java用户相关bean定义   带有scribesjava库的wordpress Woocommerce REST API返回消费者密钥参数缺失错误消息   java我可以自动检测特定设备连接的串行端口吗?   Javafx棋盘游戏   java使用JTextPane显示HTML,支持SVG吗?   SpringBoot如何在java中将映射转换为实体对象?   如何使用java代码对xls文件进行密码保护   Java JPA(EclipseLink)如何在持久化实际实体之前接收下一个生成的值?   Javaservlet启动外部进程