QCFS-related work
一、代码
def replace_maxpool2d_by_avgpool2d(model): # 将模型中的所有MaxPool2d层替换为AvgPool2d层。for name, module in model._modules.items(): # 函数使用递归方式遍历模型的所有模块,通过model._modules.items()获取模型的子模块以及它们对应的名称。if hasattr(module, "_modules"): # 对于每个子模块,首先检查是否有进一步的子模块,如果有,则递归调用replace_maxpool2d_by_avgpool2d函数对其进行替换。model._modules[name] = replace_maxpool2d_by_avgpool2d(module)if module.__class__.__name__ == 'MaxPool2d': # 然后,检查当前模块的类名是否为MaxPool2d,如果是,则将该模块替换为一个具有相同参数的AvgPool2d层。model._modules[name] = nn.AvgPool2d(kernel_size=module.kernel_size,stride=module.stride,padding=module.padding)return model
_modules 是一个特殊的属性,用于访问模型对象中的子模块。
model._modules
是一个字典,其中键是子模块的名称,值是对应的子模块对象。items()
是字典的方法之一,它返回一个由键-值对组成的元组列表,表示字典中的所有项。每个元组的第一个元素是子模块的名称,第二个元素是对应的子模块对象。
在
比如:
换完之后:
modelVGG16有5个Sequential
模块和1个Classifer
模块。(Sequential模块本身不是一层,而是一种容器,用于将多个层按顺序组合成一个模块)
- 打印
module.__class__
如下:
<class ‘torch.nn.modules.container.Sequential’> × 6 - 打印
module.__class__.__name__
如下:
Sequential × 6
sequential
容器内部还有很多的如Conv2d
等子模块,即对于<class ‘torch.nn.modules.container.Sequential’>来说hasattr(module, "_modules")
成立,还有子模块,所以要继续递归到每个最小子模块,才能判断
二、
torch.ones_like(x)
是一个函数,它返回一个与输入张量 x 具有相同形状的张量,且所有元素的值都设置为1。
三、
计算机永远正确定律
aka:also known as
无语了。。这种错误只有不学计算机的才能。。。犯出来吧。。
这样输出的args.id: __
因为这三个变量为空
四、
spikes_number = {}def save_spikes_number(module, inputdata, output):global spikes_numberif not module in spikes_number:spikes_number[module] = {}#字典套字典{"module1": {"1": 10,"2": 100},...... }spikes_number[module]["1"] = torch.sum(torch.abs(output))spikes_number[module]["2"] = output.numel()else:spikes_number[module]["1"] = spikes_number[module]["1"]+torch.sum(torch.abs(output))def add_IF_hook(model):children = list(model.named_children())for name, child in children:is_need = Falseif isinstance(child, ScaledNeuron):model._modules[name].register_forward_hook(save_spikes_number)is_need = Trueif not is_need:add_IF_hook(child)
五、
can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
六、
cifar五万个训练集,一万个测试集(79*128 = 10112(最后一个bs不满))
七、并行训练
参考文章1
参考文章2
代码+教程
QCFS-related work相关推荐
- vue install 报错 This is a problem related to network connectivity.
在终端安装任何包,执行 npm i均报错 npm ERR! code ENOTFOUND npm ERR! errno ENOTFOUND npm ERR! network request to ht ...
- 文献学习(part28)--Biclustering of gene expression data based on related genes and conditions extraction
学习笔记,仅供参考,有错必究 文章目录 Biclustering of gene expression data based on related genes and conditions extra ...
- 使用代码获得document的related document 列表
Created by Jerry Wang, last modified on May 12, 2015 例如需要获得opportunity 1718的planned activity list: 执 ...
- OSL LLVM 3.3 Related Changes
OSL LLVM 3.3 Related Changes https://github.com/imageworks/OpenShadingLanguage/commit/6a21287f4a4b9e ...
- Error:Unable to make the module: core, related gradle configuration was not found. Please, re-import
IDEA run kakfa的时候报错这个 Error:Unable to make the module: core, related gradle configuration was not fo ...
- Optical Flow related Tutorials
Optical Flow related Tutorials 2017-04-01 10:50:55 Reference: 1. http://blog.csdn.net/carson2005/art ...
- 使用xadmin搜索search_fields报错:Related Field got invalid lookup: icontains
在adminx.py文件定义的类里面添加这三个字段list_display = ['code','email','send_type','send_time'] #显示的字段类型search_fiel ...
- this is related to npm not being able to find a file
导致这类错误的可能性很多,只要按下面的方法顺序试一遍就欧克了~ 类似的错误:(当时忘记截图了,所以只能凑合看我的error log,里面可以看到我node版本是v14,npm是v6) 8 verbos ...
- django后台搜索显示Related Field got invalid lookup: icontains
项目场景: django后台搜索 问题描述 输入搜索后显示字段错误类型并报Related Field got invalid lookup: icontains的错误 原因分析: 根据百度查找原因是查 ...
- 论文写作——韬ASMI29 introduction、related work两部分语句修改
文章目录 1 introduction 2 related work 1 introduction 1.1 Therefore, a bag is described by a single bag ...
最新文章
- 卧槽!又一个Python神器!
- 模板初步——定义模板
- 京东面试题:Java中 ++i 的操作是线程安全的么?为什么?如何使其线程安全呢?
- 计算机二级测试试题及答案,2017计算机二级测试题及答案解释
- 【Less-9】基于SQLI的SQL时间盲注
- 简单的聊天应用程序(多客户端聊天服务器) from multithread
- linux php 源码安装,Linux下PHP的源码安装与配置
- paip.hadoop的应用研究总结
- 使用BeautifulSoup爬取“0daydown”网站的信息(1)
- eclipse环境变量的配置
- 基因重组-冲刺日志(第一天)
- 虚拟服务器和vdi,比较瘦客户端和VDI
- vue项目 报错 Extra semicolon (semi)
- 某zhan sign
- cpu外部三大总线的解释和作用
- AppleScript基础语法讲解
- curl 支持ws吗_使用CURL请求WebService | 字痕随行
- j - 分组(动态规划)
- [附源码]Java计算机毕业设计SSM高校互联网班级管理系统
- 开关电源方案 12V2A 或24v1A,EFD25磁芯,实测12V时可带2.4A