Custom Layer- Incorrent number of outputs


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

function obj = splitDataLayer(name)

obj.Name = name;
obj.numOutputs = 4;
obj.OutputNames = {'out1','out2','out3','out4'};

function [Z1, Z2, Z3, Z4] = predict(~, X)

Z1 = X(1, :, :, :);
Z2 = X(2, :, :, :);
Z3 = X(3, :, :, :);
Z4 = X(4, :, :, :);

function [dLdX] = backward(~,~,~,~,~,~,dLdZ1,dLdZ2,dLdZ3,dLdZ4,~)

dLdX = cat(1, dLdZ1,...


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.

ANSWER provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

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
Running nnet.checklayer.TestCase
.......... .......... ....
Done nnet.checklayer.TestCase
Test Summary:
24 Passed, 0 Failed, 0 Incomplete, 0 Skipped.
Time elapsed: 1.3818 seconds.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Technical Source

Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.