How to Manually Change dlnet's Learnable Parameters?

5 次查看(过去 30 天)
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 个评论
Theron FARRELL
Theron FARRELL 2019-11-25
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.

请先登录,再进行评论。

采纳的回答

Gautam Pendse
Gautam Pendse 2020-1-8
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by