在Pytorch中计算自己模型的FLOPs方式

yipeiwu_com6年前Python基础

https://github.com/Lyken17/pytorch-OpCounter

安装方法很简单:

pip install thop

基本用法:

from torchvision.models import resnet50from thop import profile
model = resnet50()
flops, params = profile(model, input_size=(1, 3, 224,224))

对自己的module进行特别的计算:

class YourModule(nn.Module):
# your definition
def count_your_model(model, x, y):
# your rule
hereflops, params = profile(model, input_size=(1, 3, 224,224),
custom_ops={YourModule: count_your_model})

以上这篇在Pytorch中计算自己模型的FLOPs方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python3实现定时任务的四种方式

最近做一个小程序开发任务,主要负责后台部分开发;根据项目需求,需要实现三个定时任务: 1>定时更新微信token,需要2小时更新一次; 2>商品定时上线; 3>定时检测...

在Python 3中实现类型检查器的简单方法

示例函数 为了开发类型检查器,我们需要一个简单的函数对其进行实验。欧几里得算法就是一个完美的例子:   def gcd(a, b): '''Return the g...

Pytorch Tensor的统计属性实例讲解

1. 范数 示例代码: import torch a = torch.full([8], 1) b = a.reshape([2, 4]) c = a.reshape([2, 2...

树莓派4B+opencv4+python 打开摄像头的实现方法

树莓派4B+opencv4+python 打开摄像头的实现方法

在树莓派自带得python IDE Thonny中写如下代码,并在树莓派上插上usb摄像头 import cv2 cap=cv2.VideoCapture(0) #调用摄像头‘0'一...

python统计cpu利用率的方法

本文实例讲述了python统计cpu利用率的方法。分享给大家供大家参考。具体实现方法如下: #-*-coding=utf-8-*- import win32pdh import ti...