在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设计】。

相关文章

python显示生日是星期几的方法

本文实例讲述了python显示生日是星期几的方法。分享给大家供大家参考。具体实现方法如下: # find the day of the week of a given date #...

Python中使用md5sum检查目录中相同文件代码分享

复制代码 代码如下: """This module contains code from Think Python by Allen B. Downey http://thinkpyth...

Python之pymysql的使用小结

在python3.x中,可以使用pymysql来MySQL数据库的连接,并实现数据库的各种操作,本次博客主要介绍了pymysql的安装和使用方法。  PyMySQL的安装 一、...

python使用Matplotlib改变坐标轴的默认位置

python使用Matplotlib改变坐标轴的默认位置

使用Matplotlib绘制的图表的默认坐标轴是在左下角的,这样对于一些函数的显示不是非常方便,要改变坐标轴的默认显示方式主要要使用gca()方法 plt.gca()表示 Get cur...

基于python指定包的安装路径方法

通常python安装包都会被默认装在/usr/local/pythonx/lib/site-packages(linux),但是我们有时想自定义包的安装路径,比如自己项目的某个路径,这样...