MATLAB Answers

How to Manually Change dlnet's Learnable Parameters?

14 views (last 30 days)
Hi,
I want to add some minor noise to a dlnet.Learnables.
Firstly, I tried to convert each learnables from table to cell to a single dlarray by
yy = cell2mat(table2array(dlnet.Learnables(1, 3)));
zz = yy + normrnd(0, 0.005, size(yy));
But I found I could not manage to convert zz back and have it stored in dlnet.Learnables(1, 3).
Then, I tried to use dlupdate() function like
Noise_Adder = @(para, Noise_Sigma) para + normrnd(0, Noise_Sigma, size(para));
G_Add_Noise_Sigma = 0.005;
for l = 1:size(dlnet.Learnables, 1)
dlnet.Learnables(i, 3) = dlupdate(Noise_Adder, dlnet.Learnables(i, 3), G_Add_Noise_Sigma);
end
Yet I got an error saying
Dot indexing is not supported for variables of this
type.
Error in
deep.internal.recording.containerfeval>iProcessTable_Nout_Nin
(line 262)
varargvals{input} = varargin{input}.Value;
Error in
deep.internal.recording.containerfeval>iDispatch_Nout_Nin
(line 194)
[varargout{1:nargout}] =
iProcessTable_Nout_Nin(allowNetInput,
makeNetOutput, fun, paramFun, c, varargin{:});
Error in deep.internal.recording.containerfeval
(line 41)
[c, varargout{1:nargout-1}] =
iDispatch_Nout_Nin(allowNetInput,
makeNetOutput, fun, paramFun, c,
varargin{:});
Error in deep.internal.networkContainerFun (line
15)
[c, varargout{1:nargout-1}] =
deep.internal.recording.containerfeval(...
Error in dlupdate (line 102)
[P, varargout{1:nargout-1}] =
deep.internal.networkContainerFun(...
So how can I achieve my goal? Many thanks.
  1 Comment
Theron FARRELL
Theron FARRELL on 25 Nov 2019
Actually, I managed to implement what I want manually by adding noise layer by layer
G_Para_Noise_Sigma = 0.05;
[dlnet_G.Learnables] = Add_Para_Noise(dlnet_G.Learnables, G_Para_Noise_Sigma);
function [para] = Add_Para_Noise(para, sigma)
for layer = 1:size(para, 1)
para.Value{layer} = para.Value{layer} + normrnd(0, sigma, size(para.Value{layer}));
end
end
But I know it is quite naive and inefficient. Is there any better way to do it, especially by using dlupdate?
Thanks.

Sign in to comment.

Accepted Answer

Gautam Pendse
Gautam Pendse on 8 Jan 2020
Hi Theron,
The first syntax for dlupdate may be what you are looking for:
% Update learnable parameters in dlnet by adding 1
myfun = @(x) x + 1;
dlnet = dlupdate(myfun,dlnet);
Hope this helps,
Gautam

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!