Error using trainNetwork (dimensions error) | Deep Learning Toolbox

2 views (last 30 days)
I am trying to create a custom layer and implement it in a network.
Attached here is the network code myNetwork.m, the layer myLayer.m and example of the training data I use data.mat.
Data Format
For the case that I do not input the data to the training function correctly and you know how to do it, I will describe the wanted dimensions:
  • In the input data (trainIn and testIn), each realisation has 12 elements (a vector).
  • In the output data (trainOut and testOut), each realisation has 6 elements (a vector too).
The Error
Running myNetwork.m you will recreate exactly the error I get which is:
Error using trainNetwork (line 165)
Unable to perform assignment because the left and right sides have a different number of
elements.
Error in myNetwork (line 38)
[trainedNet, traininfo] = trainNetwork(num2cell(trainIn', 1)', trainOut, layers, options);
Caused by:
Unable to perform assignment because the left and right sides have a different number of
elements.
The Question
What causes this error and how should I fix it?
In the following, I recreate my attempt to debug the network, if you know the answer you should not waste time reading it, if you don't, I hope it will give you a thinking direction.
Attempt to Debug
This error message does not point the place in the code where the error happens beyond trainNetwork function, so I've placed a breakpoint at trainNetwork (line 165):
breakpoint1.png
and executed:
doTrainNetwork(layersOrGraph, opts, X, Y)
while in the debugger. Here I got a very nested error message, whose last thread was:
Unable to perform assignment because the left and right sides have a different number of
elements.
Error in nnet.internal.cnn.DAGNetwork>iAssignActivationsToBuffer (line 1378)
activationsBuffer(bufferIndices) = activations;
So again, placing a breakpoint at nnet.internal.cnn.DAGNetwork>iAssignActivationsToBuffer (line 1378):
breakpoint2.png
then executing:
activationsBuffer(bufferIndices) = activations
I got the described "Unable to perform assignment" error.
This part of the code
if iscell(activations)
activationsBuffer(bufferIndices) = activations;
else
activationsBuffer{bufferIndices} = activations;
end
checks if those "activations" are cell or not (in this case the ARE) and tries to assign them to the bufferIndices's element of activationsBuffer, but at the time of assignment the preallocated activationsBuffer cell array at element number bufferIndices is empty (cell 0x0) and thus the assignment can not be performed.

Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!