Finetune a Torch model

﹥>﹥吖頭↗ 提交于 2019-12-06 15:33:42

问题


I have loaded a model in Torch and I would like to fine-tune it. For now I'd like to retrain the last 2 layers of the network (though in the future I may want to add layers). How can I do this? I have been looking for tutorials, but I haven't found what I am looking for. Any tips?


回答1:


I don't know if I understood what you are asking for. If you want to leave the net as it was except for the 2 layers you want to train (or fine-tune) you have to stop the backpropagation on the ones you don't want to train, like this:

for i=1, x do
  c = model:get(i)
  c.updateGradInput = function(self, inp, out) end
  c.accGradParameters = function(self,inp, out) end
 end

Now only the layers outside of this loop will upgrade their parameters. If you want to add new layers just call model:insert(module, position), you can have a look here Torch containers

If that was not what you were looking for, please elaborate more on the question.



来源:https://stackoverflow.com/questions/37459812/finetune-a-torch-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!