大佬教程收集整理的这篇文章主要介绍了PyTorch,nn.Sequential(),访问nn.Sequential()中特定模块的权重,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在PyTorch论坛上,推荐的方法是:
@H_861_5@model_2.layer[0].weight
这应该是一个快速的过程。当我在PyTorch中使用预定义的模块时,通常可以很容易地访问其权重。但是,如果首先将模块包装在Nn.Sequential()中,该如何访问它们?请参阅下面的玩具示例
class My_Model_1(nn.ModulE):
def __init__(self,D_in,D_out):
super(My_Model_1,self).__init__()
self.layer = nn.Linear(D_in,D_out)
def forWARD(self,X):
out = self.layer(X)
return out
class My_Model_2(nn.ModulE):
def __init__(self,D_out):
super(My_Model_2,self).__init__()
self.layer = nn.Sequential(nn.Linear(D_in,D_out))
def forWARD(self,X):
out = self.layer(X)
return out
model_1 = My_Model_1(10,10)
print(model_1.layer.weight)
model_2 = My_Model_2(10,10)
# How do I print the weights now?
# model_2.layer.0.weight doesn't work.
以上是大佬教程为你收集整理的PyTorch,nn.Sequential(),访问nn.Sequential()中特定模块的权重全部内容,希望文章能够帮你解决PyTorch,nn.Sequential(),访问nn.Sequential()中特定模块的权重所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。