Incorrect number of output for custom layer
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, i try to create a custom layer than dulipcate the feature vector multiple times according to input arguement. I only define for predict becuase i saw the documentation saying that if the predict and forward is same, predict will be used for training. But i got the error for both forward and predict which i dont understand what is happening. May i know what is happening here, thank you
classdef repeatVectorLayer < nnet.layer.Layer % & nnet.layer.Formattable (Optional)
properties
% (Optional) Layer properties.
repeated_timestep=0;
% Declare layer properties here.
end
properties (Learnable)
% (Optional) Layer learnable parameters.
% Declare learnable parameters here.
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.
% Declare nested networks with learnable and state parameters here.
end
methods
function layer = repeatVectorLayer(n)
% (Optional) Create a myLayer.
% This function must have the same name as the class.
layer.repeated_timestep=n;
% Define layer constructor function here.
end
function Z = predict(layer,X)
% Forward input data through the layer at prediction time and
% output the result and updated state.
%
% Inputs:
% layer - Layer to forward propagate through
% X - Input data
% Outputs:
% Z - Output of layer forward function
% state - (Optional) Updated layer state.
%
% - For layers with multiple inputs, replace X with X1,...,XN,
% where N is the number of inputs.
% - For layers with multiple outputs, replace Z with
% Z1,...,ZM, where M is the number of outputs.
% - For layers with multiple state parameters, replace state
% with state1,...,stateK, where K is the number of state
% parameters.
% Define layer predict function here.
Z=repmat(X,[layer.repeated_timestep,1]);
end
function [Z,state,memory] = forward(layer,X)
% (Optional) Forward input data through the layer at training
% time and output the result, updated state, and a memory
% value.
%
% Inputs:
% layer - Layer to forward propagate through
% X - Layer input data
% Outputs:
% Z - Output of layer forward function
% state - (Optional) Updated layer state
% memory - (Optional) Memory value for custom backward
% function
%
% - For layers with multiple inputs, replace X with X1,...,XN,
% where N is the number of inputs.
% - For layers with multiple outputs, replace Z with
% Z1,...,ZM, where M is the number of outputs.
% - For layers with multiple state parameters, replace state
% with state1,...,stateK, where K is the number of state
% parameters.
% Define layer forward function here.
end
-----------------------------------------------------------------------------------------------------------------
Caused by:
Layer 3: Layer validation failed. Incorrect number of output arguments for 'forward'. Expected to have 2, but instead it has 3.
Layer 3: Error using 'forward' in layer repeatVectorLayer. The function threw an error and could not be executed.
Output argument "Z" (and possibly others) not assigned a value in the execution with "repeatVectorLayer/forward" function.
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Custom Layers finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!