How can I freeze specific weights of Neural network model?

조회 수: 48 (최근 30일)
Abdelwahab Afifi
Abdelwahab Afifi 2020년 6월 14일
편집: Ahmad Gad 2021년 8월 25일
I need to set some specific weights before training, and keep these weights fixed during training

채택된 답변

Utkarsh
Utkarsh 2020년 6월 18일
Hi Abdelwahab,
If you wish to assign those weights in the beginning and keep them as constant, you can set the ‘WeightLearnRateFactor’ property as 0 (which defines the learning rate for that layer) for those layers.
For example,
convolution2dLayer(3,1,'Padding',[1 1 1 1],'WeightLearnRateFactor',0);
You may refer to this link to learn more about such properties.
Or if you want to fix certain weights to some layers in a trained network , then directly assign those layers the values after training the network.
net = alexnet; % or your pre-trained network
layer = net.Layers(1) % here 1 can be replaced with the layer number you wish to change
layer.Weights = randn(11,11,3,96); %the weight matrix which you wish to assign
  댓글 수: 1
Ahmad Gad
Ahmad Gad 2021년 8월 25일
편집: Ahmad Gad 2021년 8월 25일
Can I do the same for a shallow network? And using which function?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by