当前位置:网站首页>Pytorch 修改hook源码 获取Per-Layer输出参数(带layer name)
Pytorch 修改hook源码 获取Per-Layer输出参数(带layer name)
2022-06-30 01:25:00 【Martin の Blog】
今天想用hook获取每层输出参数的时候。
调用pytorch中的API,发现没有好的方法能够将每层的层名和参数一对一的打印处理
为此修改了一下hook的源码,再调用就成了。
import torch
import torch.utils.hooks as hooks
def get_output_param(module, datasets):
output_param = {
}
def hook(module, input, output):
name = list(module._forward_hooks.keys())[0]
output_param[name] = output.data
for name, layer in module.named_modules():
if name != "":
handle = hooks.RemovableHandle(layer._forward_hooks)
layer._forward_hooks[f"{
name}"] = hook
module(datasets)
return output_param
end
边栏推荐
- Solving plane stress problem with MATLAB
- 3-6sql injection website instance step 5: break through the background to obtain web administrator permissions
- Questions about database: database attachment
- JS returned content is encoded by Unicode
- Interface Association of postman
- Kwai reached out to the "supply side" to find the "source" of live broadcast e-commerce?
- Cub school learning: manual query and ADC in-depth use
- Error reporting in Luban H5 installation
- 首届技术播客月开播在即
- 【论文写作】英文论文写作指南
猜你喜欢

3-6sql injection website instance step 5: break through the background to obtain web administrator permissions

Seata and the three platforms are working together in the summer of programming. Millions of bonuses are waiting for you

Kwai reached out to the "supply side" to find the "source" of live broadcast e-commerce?

Ctfshow competition original title 680-695

MES管理系统功能模块之质量管理

cookie加密8

Seata 与三大平台携手编程之夏,百万奖金等你来拿

The listing of Symantec electronic sprint technology innovation board: it plans to raise 623million yuan, with a total of 64 patent applications

Questions about database: database attachment

【机器学习Q&A】数据抽样和模型验证方法、超参数调优以及过拟合和欠拟合问题
随机推荐
post请求出现WebKitFormBoundaryk的解决办法
In depth analysis of a large number of clos on the server_ The root of wait
JS content confusion, return content encryption
GeoTools:WKT、GeoJson、Feature、FeatureCollection相互转换常用工具
浅析现代Web端im即时通讯开发技术
VIM编辑器常用指令
Mysql 监控
田口实验法
Cookie加密15 登录加密
Pytroch Learning Notes 6: NN network layer convolution layer
画画水族馆的应用特色及功能
【机器学习Q&A】准确率、精确率、召回率、ROC和AUC
[mrctf2020]ezpop-1 | PHP serialization
Kubernetes core object overview details
【535. TinyURL 的加密与解密】
[Thesis Writing] English thesis writing guide
Varnish 基础概览3
第八届“互联网+”大赛 | 云原生赛道邀你来挑战
HC32M0+ GPIO
传统微服务框架如何无缝过渡到服务网格 ASM