已经训练好了cnn1,现在想要用cnn1输出的结果来训练cnn2,但是要完全 固定cnn1的参数:
self.step1=cnn1()
for p in cnn1.parameters():
p.requires_grad = False
self.init_=torch.load('cnn1.weight.path.pth.tar')
self.step1.load_state_dict(self.init_['state_dict'])
self.cnn2=~~~~
self.cnn3=~~~~~
def forward(x)
x=self.step1(x)
x=self.cnn2(x)
return self.cnn3(x)

本文介绍了一种在深度学习中固定预训练模型Cnn1参数的方法,用于训练新的模型Cnn2。通过设置requires_grad为False,确保Cnn1在训练过程中不更新权重,从而将Cnn1作为特征提取器使用。
1201

被折叠的 条评论
为什么被折叠?



