Has anyone ever built a DRSN with matlab?I have some trouble,I do not know how to customize the need for soft threshold network?I always get an error on my custom layer.
classdef softthresholdingLayer < nnet.layer.Layer % ...
% & nnet.layer.Formattable ... % (Optional)
% & nnet.layer.Acceleratable % (Optional)
properties
% (Optional) Layer properties.
% Declare layer properties here.
end
properties (Learnable)
% (Optional) Layer learnable parameters.
% Declare learnable parameters here.
% thresholding
end
properties (State)
% (Optional) Layer state parameters.
% Declare state parameters here.
end
properties (Learnable, State)
% (Optional) Nested dlnetwork objects with both learnable
% parameters and state parameters.
% Declare nested networks with learnable and state parameters here.
end
methods
function layer = softthresholdingLayer(numInputs,name)
% (Optional) Create a myLayer.
% This function must have the same name as the class.
% Define layer constructor function here.
layer.NumInputs = numInputs;
layer.Name = name;
% layer.Description = "soft thresholding";
% Initialize layer weights.
% layer.Weights = rand(1,1);
end
function Z = predict(layer,vargin)
X = vargin;
% Initialize output
X1 = X{1};
th = X{2};
% x = extractdata(gather(x));
% th = extractdata(gather(th));
Z = 1.*(X1>th) + 0.*(X1<=th & X1>=(-th)) + 1.*(X1<-th);
% Z = dlarray(Z,'SSCB');
end
end
end
softthresholdingLayer/predict:Too many input parameters
Is that because I can't use “predict”?