位置: IT常识 - 正文

计算模型的GFLOPs和参数量 & 举例VGG16和DETR(计算模型的层次划分)

编辑:rootadmin
计算模型的GFLOPs和参数量 & 举例VGG16和DETR

推荐整理分享计算模型的GFLOPs和参数量 & 举例VGG16和DETR(计算模型的层次划分),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:计算模型的参数量和计算量,计算模型的作用,计算模型的创建与计算机有关,计算模型的层次划分,计算模型的概念,计算模型的概念,计算模型的概念,计算模型的层次划分,内容如对您有帮助,希望把文章链接给更多的朋友!

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

目录

一、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 profileimport torchimport 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)计算模型的GFLOPs和参数量 & 举例VGG16和DETR(计算模型的层次划分)

>>>output

参数量: 138357544.0 FLOPS: 15470314496.0

三、计算DETR的GFLOPs和参数量首先,访问网址:GitHub - facebookresearch/detr: End-to-End Object Detection with Transformers然后,下载DETR源码压缩包,调通源码。最后,把下面的代码封装到py文件中,放到DETR源码的根目录即可。import osimport timefrom PIL import Imageimport matplotlib.pyplot as pltimport torchimport torchvision.transforms as Ttorch.set_grad_enabled(False)from models import build_modelimport 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 parameters parser.add_argument('--frozen_weights', type=str, default=None, help="Path to the pretrained model. If set, only the mask head will be trained") # * Backbone parser.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") # * Transformer parser.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") # 论文中对象查询为100 parser.add_argument('--pre_norm', action='store_true') # * Segmentation parser.add_argument('--masks', action='store_true', help="Train segmentation head if the flag is provided") # Loss parser.add_argument('--no_aux_loss', dest='aux_loss', action='store_false', help="Disables auxiliary decoding losses (loss at each layer)") # * Matcher parser.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 coefficients parser.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 parameters parser.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 parameters parser.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 profile import torchsummary device = 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

四、整理数据表格ModelGFLOPsParamsVGG1615.4713.84 MDETR100.9436.74 M

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

本文链接地址:https://www.jiuchutong.com/zhishi/298853.html 转载请保留说明!

上一篇:【关系抽取】深入浅出讲解实体关系抽取(介绍、常用算法)(关系抽取系统的要求)

下一篇:【魔改YOLOv5-6.x(中)】加入ACON激活函数、CBAM和CA注意力机制、加权双向特征金字塔BiFPN(魔改6.67)

  • 提足折旧是指
  • 小规模纳税人销售农产品税率是多少
  • 增值税纳税申报时间
  • 建筑行业预缴增值税可以用进项抵缴吗
  • 赔偿费计入费用减应收账款怎么做账
  • 转出未交增值税和转出多交增值税
  • 劳务报酬所得怎么扣税
  • 过路费发票可以抵扣增值税吗
  • 印花税多缴纳怎么办
  • 企业所得税虚报成本多少属于犯罪
  • 所得税汇算清缴报告在哪查
  • 费用科目如何结转
  • 稳岗补贴计入哪个科目
  • 小规模纳税人未建账处罚
  • 自然人税收申报显示申报失败:未选择纳税人
  • 企业银行基本户
  • 外籍人士可以回国吗
  • 以前年度亏损在哪个报表体现
  • linux中tomcat如何启动
  • php操作json文件
  • cryptfunction.exe
  • 如何把电脑上锁屏密码
  • 小米无线路由器internet黄灯
  • 出售短期债券投资发生的净损失计入哪里
  • 企业所得税的概述
  • php proto
  • 跨年的发票作废重新开具需要入账
  • 三方债权债务抵消如何开发票
  • 企业财产租赁税率
  • 求源代码
  • 补缴上年度未开票收入增值税,怎么做账
  • 以前年度进项转出分录
  • 数字图像处理-应用篇
  • 论文笔记模板
  • 导入vue.js
  • php图像识别
  • thinkphp5微信公众号开发
  • 最好用的电脑强力卸载软件
  • 破解版微擎框架如何升级
  • wordpress jquery
  • 应收账款占比高
  • 个人收入如何开出发票
  • 生产油漆涂料的物质
  • 上年所得税费用借方有余额,怎么调整
  • mysql主要支持哪些数据类型?
  • mongodb自增主键
  • 厂区道路算建筑面积吗
  • 公司给部分员工长期停工怎么办
  • 工程发票多少点
  • 工会经费申报的计税比率是
  • 如何根据销售额的降序计算销售排名
  • 销售补偿法
  • 租金摊销会计分录
  • 往来款是什么意思
  • 长期借款涉及哪些账户
  • 子公司注销前资金怎么办
  • 员工办理健康证介绍信模板
  • 企业的职工福利费
  • 更换公司新公章流程
  • 保险由承租方还是出租方承担
  • 存货盘亏的账务处理怎么做
  • “制造费用”账户如何设置明细账?
  • win8恢复出厂设置方法
  • ubuntu服务器命令
  • xp怎么装系统步骤图解
  • dcs是什么文件
  • 硬件茶谈win10系统安装
  • 系统映像不存在怎么重装系统
  • bootstrap响应式导航条模板使用详解(含下拉菜单,弹出框)
  • js手机模拟器
  • bat批处理命令运行程序
  • js tabs
  • AndroidAnnotations框架Eclipse下的配置
  • jquery版本区别
  • 交通运输业的税率9%和13%
  • 百旺税控盘怎么备份数据
  • 安徽马鞍山税务局体检名单
  • 网上缴费如何开票
  • 南京国税局长是谁
  • 江西国家税务局电子税务局官网
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设