当前位置:网站首页>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
边栏推荐
- 81. search rotation sort array II
- win10子系统 WSL如果root和其他用户的密码都忘记的修复方法
- Kubernetes 核心对象概览详解
- “乘风破浪”的芒果超媒,能上岸吗?
- Cantilever beam calculation [matlab code]
- Application of pointer in STC89C52 single chip microcomputer and demonstration of practical cases
- ES6 one line code for array de duplication
- Precautions for postoperative fundus hemorrhage / / must see every day
- Solving plane stress problem with MATLAB
- MySql函数
猜你喜欢
![[Thesis Writing] English thesis writing guide](/img/59/88d34814a88a2da19ed6a236825649.png)
[Thesis Writing] English thesis writing guide

Cloud, IPv6 and all-optical network

Pytroch Learning Notes 6: NN network layer convolution layer

如何统一项目中包管理器的使用?

Stimulsoft Reports报告工具,Stimulsoft创建和构建报告

Mechanical --nx2007 (UG) -- gap analysis (interference inspection)

postman 之接口关联

cookie加密9

ctfshow 大赛原题 680-695

numpy的索引和图片的索引一样吗?
随机推荐
Database application
我,33岁,字节跳动测试开发,揭开北京“测试岗”的真实收入
Sentinel source code analysis Chapter 9 - core process - lookprocesschain finding resource processing chain
Cantilever beam calculation [matlab code]
Unity编辑器随机生成物体,更换场景之后物体丢失问题解决
Mysql 监控6
存储引擎分析
Quick pow: how to quickly find power
Interface Association of postman
RubyMine开发工具,重构和意图操作
[535. encryption and decryption of tinyurl]
c语言期末不挂科(上)
Seata and the three platforms are working together in the summer of programming. Millions of bonuses are waiting for you
How to build your own blog website by yourself
“乘风破浪”的芒果超媒,能上岸吗?
Some thoughts on small program subcontracting and verification of uiniapp subcontracting optimization logic
[machine learning Q & A] data sampling and model verification methods, hyperparametric optimization, over fitting and under fitting problems
Interview summary
Cloud, IPv6 and all-optical network
Three text to speech artifacts, each of which is very practical