matlab DRSN:how to cutom my layer?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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”?
0 Kommentare
Antworten (1)
Venu
am 1 Apr. 2024
Hi @BB
The "predict" method in your custom layer should only take two arguments: layer and X. Your implementation attempts to take an unspecified number of input arguments with "vargin", which seems to be a typo for MATLAB's variable input argument "varargin". This is not the correct approach for layer methods in MATLAB's Deep Learning Toolbox. Instead, the input to the layer should be directly passed as the second argument.
function Z = predict(layer, X)
Hope this helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Custom Layers finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!