Update custom layer's parameter every iteration
1 次查看(过去 30 天)
显示 更早的评论
I have defined a custom regression layer as follows
classdef Sparse_Layer < nnet.layer.RegressionLayer
% Example custom regression layer with mean-absolute-error loss.
properties
% (Optional) Layer properties.
L1_Lambda = 0;
% Layer properties go here.
end
methods
function layer = Sparse_Layer(L1_Lambda)
% Lambda should be 1xN, N-> Batch size
layer.L1_Lambda = L1_Lambda;
% Set layer description.
layer.Description = 'Mean absolute error';
end
function layer_out = myFun(layer_in)
end
function loss = forwardLoss(layer, Y, T)
% loss = forwardLoss(layer, Y, T) returns the MAE loss between
% the predictions Y and the training targets T.
% Calculate L1 error mean over batch.
Dif = Y-T;
Batch_sz = size(Y,2);
L1_err = sum(abs(Dif),1);
L2_err = sum(Dif.*Dif,1);
loss = sum(layer.L1_Lambda(iteration_num)*L1_err + .5*L2_err )/Batch_sz;
end
end
end
Now, i want to multiply Lambda(iteration_no), this iteration number is something that i am unable to update. I tried having a layer property that counts the iteration,but that cant work as this a Value Class and not a handler. The reason i want to do this is beacuse i want this lambda to change for every batch (the values i have pre-calcuated based on some feautures of the data in each batch).
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!