在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基于Tkinter模块实现的弹球小游戏

Python基于Tkinter模块实现的弹球小游戏

本文实例讲述了Python基于Tkinter模块实现的弹球小游戏。分享给大家供大家参考,具体如下: #!usr/bin/python #-*- coding:utf-8 -*- fr...

Python面向对象之类的定义与继承用法示例

本文实例讲述了Python面向对象之类的定义与继承用法。分享给大家供大家参考,具体如下: 定义一个类 类中的方法同,类外方法,默认传self值 类的构造函数是  __init_...

Python中__init__和__new__的区别详解

__init__ 方法是什么? 使用Python写过面向对象的代码的同学,可能对 __init__ 方法已经非常熟悉了,__init__ 方法通常用在初始化一个类实例的时候。例如:...

DataFrame 将某列数据转为数组的方法

如下所示: playerIds =salaries_2016['playerID'].tolist() data['列名'].tolist() 以上这篇DataFrame 将某列...

python实现烟花小程序

本文实例为大家分享了python实现烟花小程序的具体代码,供大家参考,具体内容如下 ''' FIREWORKS SIMULATION WITH TKINTER *self-conta...