神经网络的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 安卓 XMLPullParser错误   Java响应网格布局   Java中使用递归的不同方法   java变量可能尚未初始化(边加权图)   java如何将这样的文件插入MySQL数据库   java云端点:不允许实体类型的数组或集合   java(编译器或jvm)是否以不同方式处理类的静态最终成员?如果是,怎么做   java如何从lambda表达式返回新的非抽象映射?   java JDK 7支持的最大Spring版本是什么   我们如何从java类生成DTD   java在我的例子中BindingResult、FieldErrors或GlobalErrors是否可以为null?   java[LibGDX][GWT]读取文件外观时出错。HTML格式的json[序列化异常]   字典Java不可修改密钥集映射   java Admob在firebase sdk之后显示测试广告,但不显示真实广告