PyTorch实现更新部分网络,其他不更新
作者:KevinUSTC 时间:2022-06-15 21:01:33
torch.Tensor.detach()的使用
detach()的官方说明如下:
Returns a new Tensor, detached from the current graph.
The result will never require gradient.
假设有模型A和模型B,我们需要将A的输出作为B的输入,但训练时我们只训练模型B. 那么可以这样做:
input_B = output_A.detach()
它可以使两个计算图的梯度传递断开,从而实现我们所需的功能。
来源:https://blog.csdn.net/jinxin521125/article/details/83621268
标签:PyTorch,更新,网络
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python操作JSON实现网络数据交换
2023-01-27 02:21:53
利用Python 实现分布式计算
2021-12-21 22:59:26
![](https://img.aspxhome.com/file/2023/6/100926_0s.webp)
Python爬虫实战案例之爬取喜马拉雅音频数据详解
2023-07-19 07:05:02
![](https://img.aspxhome.com/file/2023/2/79402_0s.png)
利用python实现.dcm格式图像转为.jpg格式
2021-08-28 04:16:35
Scrapy爬虫Response子类在应用中的问题解析
2023-11-03 01:29:31
![](https://img.aspxhome.com/file/2023/4/95834_0s.png)
站长必须要了解的九条平面设计常识
2008-06-07 14:33:00
Python OpenCV实现图像傅里叶变换
2022-06-19 04:43:55
![](https://img.aspxhome.com/file/2023/4/92314_0s.png)
灵活调用xsl来解析xml文档(js异步)
2008-09-05 17:12:00
Python实现两个list求交集,并集,差集的方法示例
2021-12-27 19:52:06
php中支持多种编码的中文字符串截取函数!
2023-09-27 02:08:15
python实现石头剪刀布小游戏
2022-03-22 15:47:36
![](https://img.aspxhome.com/file/2023/0/110390_0s.jpg)
基于Python获取照片的GPS位置信息
2021-02-25 03:32:00
![](https://img.aspxhome.com/file/2023/2/109892_0s.png)
在python中获取div的文本内容并和想定结果进行对比详解
2021-09-05 07:29:37
python遍历文件夹,指定遍历深度与忽略目录的方法
2022-12-28 23:57:27
一个asp伪静态的程序实现方法
2010-06-28 18:56:00
Python类的继承、多态及获取对象信息操作详解
2023-09-09 21:27:52
Python中eval带来的潜在风险代码分析
2023-05-24 03:29:03
Python logging模块写入中文出现乱码
2023-10-18 14:48:12
python统计RGB图片某像素的个数案例
2021-09-30 11:25:56
![](https://img.aspxhome.com/file/2023/3/77683_0s.jpg)
python url 参数修改方法
2023-09-12 19:02:24