Custom Layer- Incorrent number of outputs

조회 수: 1 (최근 30일)
Valentin Steininger
Valentin Steininger 2019년 8월 9일
댓글: Valentin Steininger 2019년 8월 9일
Hi,
I'm trying to create a custom intermediate layer that can split up data. When I use checkLayer to validate the functionality it throws the error: "Incorrect number of output arguments for 'predict' in Layer splitDataLayer. Expected to have 1, but instead it has 4." although I've set the number of Outputs to 4 in the constructor.
classdef splitDataLayer < nnet.layer.Layer
methods
function obj = splitDataLayer(name)
obj.Name = name;
obj.numOutputs = 4;
obj.OutputNames = {'out1','out2','out3','out4'};
end
function [Z1, Z2, Z3, Z4] = predict(~, X)
Z1 = X(1, :, :, :);
Z2 = X(2, :, :, :);
Z3 = X(3, :, :, :);
Z4 = X(4, :, :, :);
end
function [dLdX] = backward(~,~,~,~,~,~,dLdZ1,dLdZ2,dLdZ3,dLdZ4,~)
dLdX = cat(1, dLdZ1,...
dLdZ2,...
dLdZ3,...
dLdZ4);
end
end
end
As can be seen above, both the number of outputs as well as the output matrix in the predict function have been set correctly. So I don't know what could be wrong about the code and cause that error.
I would be happy for any help!

채택된 답변

Maria Duarte Rosa
Maria Duarte Rosa 2019년 8월 9일
Hi Valentin,
Thank you for your question.
Multi-input/Multi-output custom layers are supported from R2019a. From your error message I suspect you are on a older release.
Your layer looks good though, apart from obj.numOutputs = 4; which should be obj.NumOutputs = 4;
When I correct for that all the checkLayer tests pass in R2019a:
layer = splitDataLayer('test');
validInputSize = [4 5 20 4]; % Some arbitrary dimensions
checkLayer(layer,validInputSize,'ObservationDimension',4)
Running nnet.checklayer.TestCase
.......... .......... ....
Done nnet.checklayer.TestCase
__________
Test Summary:
24 Passed, 0 Failed, 0 Incomplete, 0 Skipped.
Time elapsed: 1.3818 seconds.
I hope this helps.
  댓글 수: 1
Valentin Steininger
Valentin Steininger 2019년 8월 9일
Hi Maria,
I also just realized that it's not available on 2018b as I tried the "custom weighted addition layer" example from the documenation and it threw the same error.
I'm just about to upgrade to 2019a.
Thanks for the answer!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by