近期忙于写论文,分享一下论文中表格数据的计算方法。

目录

一、FLOPS、FLOPs和GFLOPs的概念

二、计算VGG16的GFLOPs和参数量

三、计算DETR的GFLOPs和参数量

四、整理数据表格


一、FLOPS、FLOPs和GFLOPs的概念

  • FLOPS:注意S是大写,是 “每秒所执行的浮点运算次数”(floating-point operations per second)的缩写。它常被用来估算电脑的执行效能,尤其是在使用到大量浮点运算的科学计算领域中。正因为FLOPS字尾的那个S,代表秒,而不是复数,所以不能省略掉。
  • FLOPs:注意s小写,是floating point operations的缩写(s表复数),意指浮点运算数,理解为计算量。可以用来衡量算法/模型的复杂度。
  • GFLOPs:一个GFLOPs等于每秒十亿(=10^9)次的浮点运算

二、计算VGG16的GFLOPs和参数量

from thop import profile
import torch
import torchvision.models as modelsmodel = models.vgg16()
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model.to(device)
input = torch.zeros((1, 3, 224, 224)).to(device)
flops, params = profile(model.to(device), inputs=(input,))print("参数量:", params)
print("FLOPS:", flops)

>>>output

参数量: 138357544.0
FLOPS: 15470314496.0

三、计算DETR的GFLOPs和参数量

  1. 首先,访问网址:GitHub - facebookresearch/detr: End-to-End Object Detection with Transformers
  2. 然后,下载DETR源码压缩包,调通源码。
  3. 最后,把下面的代码封装到py文件中,放到DETR源码的根目录即可。
import os
import timefrom PIL import Image
import matplotlib.pyplot as pltimport torch
import torchvision.transforms as T
torch.set_grad_enabled(False)from models import build_model
import argparsefrom torch.nn.functional import dropout,linear,softmaxdef get_args_parser():parser = argparse.ArgumentParser('Set transformer detector', add_help=False)parser.add_argument('--lr', default=1e-4, type=float)parser.add_argument('--lr_backbone', default=1e-5, type=float)parser.add_argument('--batch_size', default=1, type=int)parser.add_argument('--weight_decay', default=1e-4, type=float)# parser.add_argument('--epochs', default=300, type=int)parser.add_argument('--epochs', default=100, type=int)parser.add_argument('--lr_drop', default=200, type=int)parser.add_argument('--clip_max_norm', default=0.1, type=float,help='gradient clipping max norm')# Model parametersparser.add_argument('--frozen_weights', type=str, default=None,help="Path to the pretrained model. If set, only the mask head will be trained")# * Backboneparser.add_argument('--backbone', default='resnet50', type=str,help="Name of the convolutional backbone to use")parser.add_argument('--dilation', action='store_true',help="If true, we replace stride with dilation in the last convolutional block (DC5)")parser.add_argument('--position_embedding', default='sine', type=str, choices=('sine', 'learned'),help="Type of positional embedding to use on top of the image features")# * Transformerparser.add_argument('--enc_layers', default=6, type=int,help="Number of encoding layers in the transformer")parser.add_argument('--dec_layers', default=6, type=int,help="Number of decoding layers in the transformer")parser.add_argument('--dim_feedforward', default=2048, type=int,help="Intermediate size of the feedforward layers in the transformer blocks")parser.add_argument('--hidden_dim', default=256, type=int,help="Size of the embeddings (dimension of the transformer)")parser.add_argument('--dropout', default=0.1, type=float,help="Dropout applied in the transformer")parser.add_argument('--nheads', default=8, type=int,help="Number of attention heads inside the transformer's attentions")parser.add_argument('--num_queries', default=40, type=int,help="Number of query slots")  # 论文中对象查询为100parser.add_argument('--pre_norm', action='store_true')# * Segmentationparser.add_argument('--masks', action='store_true',help="Train segmentation head if the flag is provided")# Lossparser.add_argument('--no_aux_loss', dest='aux_loss', action='store_false',help="Disables auxiliary decoding losses (loss at each layer)")# * Matcherparser.add_argument('--set_cost_class', default=1, type=float,help="Class coefficient in the matching cost")parser.add_argument('--set_cost_bbox', default=5, type=float,help="L1 box coefficient in the matching cost")parser.add_argument('--set_cost_giou', default=2, type=float,help="giou box coefficient in the matching cost")# * Loss coefficientsparser.add_argument('--mask_loss_coef', default=1, type=float)parser.add_argument('--dice_loss_coef', default=1, type=float)parser.add_argument('--bbox_loss_coef', default=5, type=float)parser.add_argument('--giou_loss_coef', default=2, type=float)parser.add_argument('--eos_coef', default=0.1, type=float,help="Relative classification weight of the no-object class")# dataset parametersparser.add_argument('--dataset_file', default='coco')parser.add_argument('--coco_path', default='', type=str)parser.add_argument('--coco_panoptic_path', type=str)parser.add_argument('--remove_difficult', action='store_true')parser.add_argument('--output_dir', default='E:\project_yd\paper_sci_one_yd\Transformer\DETR\detr\\runs\\train',help='path where to save, empty for no saving')parser.add_argument('--device', default='cuda',help='device to use for training / testing')parser.add_argument('--seed', default=42, type=int)# ============================================================================= #parser.add_argument('--resume', default='', help='resume from checkpoint')# ============================================================================= #parser.add_argument('--start_epoch', default=0, type=int, metavar='N',help='start epoch')parser.add_argument('--eval', action='store_true')parser.add_argument('--num_workers', default=2, type=int)# distributed training parametersparser.add_argument('--world_size', default=1, type=int,help='number of distributed processes')parser.add_argument('--dist_url', default='env://', help='url used to set up distributed training')return parserif __name__ == '__main__':parser = argparse.ArgumentParser('DETR training and evaluation script', parents=[get_args_parser()])args = parser.parse_args()# 建立模型model, criterion, postprocessors = build_model(args)model.to('cuda:0')url = r'detr-r50-dc5-f0fb7ef5.pth'state_dict = torch.load(url)# print(state_dict)# 加载模型参数,以字典的形式表示model.load_state_dict(state_dict['model'])model.eval()  # 把字符串类型转换成字典类型# ==================================================== #from thop import profileimport torchsummarydevice = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")model.to(device)input = torch.zeros((1, 3, 800, 1422)).to(device)flops, params = profile(model.to(device), inputs=(input,))print("参数量:", params)print("FLOPS:", flops)# ==================================================== #

>>> output

参数量: 36739785.0
FLOPS: 100937364480.0

四、整理数据表格

Model GFLOPs Params
VGG16 15.47 13.84 M
DETR 100.94 36.74 M

>>> 如有疑问,欢迎评论区一起探讨!

计算模型的GFLOPs和参数量 举例VGG16和DETR相关推荐

  1. 电动汽车动力系统匹配计算模型:输入整车参数及性能要求,一键生成驱动系统的扭矩功率峰值转速等参数

    1.电动汽车动力系统匹配计算模型:输入整车参数及性能要求,一键生成驱动系统的扭矩功率峰值转速等参数. 2.整车动力经济性计算模型:包含NEDC WLTC CLTC工况,输入整车参数可生成工况电耗.百公 ...

  2. vgg 16模型的内存和参数量的计算

    cs231n上关于VGG-16模型的内存和参数的计算过程如下. INPUT: [224x224x3] memory: 224*224*3=150K weights: 0 CONV3-64: [224x ...

  3. 模型的显存和参数量计算

    写在前面:以此记录关于模型显存和参数量的一些理解和计算. 首先是"运算量"和"参数量"两个概念: 参数量:这个比较好理解,例如卷积层中的卷积核c_i*k*k*n ...

  4. 性能媲美BERT,但参数量仅为1/300,这是谷歌最新的NLP模型

    选自Google AI Blog 作者:Prabhu Kaliamoorthi 机器之心编译 机器之心编辑部 在最新的博客文章中,谷歌公布了一个新的 NLP 模型,在文本分类任务上可以达到 BERT ...

  5. 性能媲美BERT,参数量仅为1/300,谷歌最新的NLP模型

    在最新的博客文章中,谷歌公布了一个新的 NLP 模型,在文本分类任务上可以达到 BERT 级别的性能,但参数量仅为 BERT 的 1/300. 在过去的十年中,深度神经网络从根本上变革了自然语言处理( ...

  6. 深度学习模型参数量/计算量和推理速度计算

    作者|龟壳 来源 | 知乎 地址 | https://zhuanlan.zhihu.com/p/376925457 本文仅作学术分享,若侵权请联系后台删文处理 本文总结了一些关于模型参数量计算以及推理 ...

  7. 模型大小 与参数量计算

    1.model size 就是模型的大小,我们一般使用参数量parameter来衡量,注意,它的单位是个.但是由于很多模型参数量太大,所以一般取一个更方便的单位:兆(M) 来衡量.比如ResNet-1 ...

  8. vgg16卷积层的计算量_vgg16模型参数量和使用的的内存计算

    关于VGG-16模型的内存和参数的计算过程如下. INPUT: [224x224x3] memory: 224*224*3=150K weights: 0 CONV3-64: [224x224x64] ...

  9. CNN模型复杂度(FLOPs、MAC)、参数量与运行速度

    CNN模型复杂度(FLOPs.MAC).参数量与运行速度 先转载一下,有空再来整理 文章目录 0. 模型复杂度简介 1. 模型复杂度之一:模型参数量的计算方法 卷积层参数量计算 全连接层参数量计算 2 ...

  10. 关于 FLOPS、FLOPs、参数量的相关计算

    关于 FLOPS.FLOPs.参数量的相关计算 一.FLOPS 二.FLOPs 2.1 2D 卷积运算 FLOPs Parameters 2.2 全连接层 FLOPs Parameters 2.3 B ...

最新文章

  1. 车企纷抢无人驾驶赛道,中国智能汽车确定将立法
  2. cucumber_java从入门到精通(5)使用maven创建cucumber_java项目
  3. linux 系统邮件 查看清空
  4. vc的速度有c语言快吗,大家帮看看,怎么回事?Delphi竟比vc++还快
  5. jquery(ajax)+ashx简单开发框架(原创)
  6. “自启动”树莓派上的 .NET Core 3.0 环境
  7. 全连接神经网络_【模型解读】从“局部连接”回到“全连接”的Non-Local神经网络...
  8. Android 系统(149)---如何初步定位异常关机问题
  9. php函数方法属性吗,为什么PHP属性不允许使用函数?
  10. 2019-07-03
  11. Java Lambda
  12. PHP实现一个在线选择答题系统
  13. android换肤的实现方案,Android 换肤的思路
  14. 什么是智能制造成能力成熟度模型?
  15. Leetcode506.Relative Ranks相对名次
  16. linux查看nbu数据库命令,NBU基本常用命令
  17. 商业模式新生代_免费商业模式——《商业模式新生代》读书笔记之五
  18. 如何打印菱形图案(C语言)
  19. 事业单位采购计算机的申请报告,事业单位采购申请报告
  20. RN:metro缓存以及如何清除缓存

热门文章

  1. excel冻结窗格怎么同时冻结行和列
  2. openjudge 1.9.8 白细胞计数
  3. html中单元格向下合并单元格,html中单元格合并 HTML 怎么给合并单元格设置宽度...
  4. 一年级abb式词语并造句_一年级abb式词语并造句_一年级语文下册总复习
  5. 修改文件 火车票买下铺_为什么坐火车时,尽量不要买下铺?过来人用亲身经历告诉你原因...
  6. Java基础之多态的运用
  7. Scrapy爬虫流程
  8. IEEE754-2008 标准详解(五):异常
  9. 一文带你由浅入深Netty异步非阻塞世界
  10. PowerApps社区计划