Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Ältere Kommentare anzeigen
Hi, I got an error and I don't know why it happened.
The error is "Unable to perform assignment because the size of the left side is 6-by-7-by-1-by-128 and the size of the right side is 768-by-7".
Here are the details of my network:

I find that the error occurred at the 7th layer ("new_reshape_layer")
This layer is a functionLayer:
new_reshape_layer = functionLayer(@(X) dlarray(reshape(X,[],7,1,1),"SSCB"),Name='new_reshape_layer',Formattable=true,Acceleratable=true);
I also try to use
features = activations(net,X,layer)
to get the output of each layer, and the output is
No.1 layer: 14 x 150
No.2 layer: 128 x 150
No.3 layer: 128 x 150
No.4 layer: 128 x 150
No.5 layer: 128 x 150
No.6 layer: 42 x 150
No.7 layer: error happened:
Unable to perform assignment because the size of the left side is 6-by-7-by-1-by-128 and the size of the right side is 768-by-7.
Error in DAGNetwork/calculateActivations>iDoInference (line 156)
Y(indices{:}) = reshapeFcn(Yb, numel(info.MiniBatchIdx));
Error in DAGNetwork/calculateActivations (line 90)
Y = iDoInference(dispatcher, numObservations, predictNetwork, gpuShouldBeUsed, ...
Error in DAGNetwork/activations (line 257)
Y = this.calculateActivations(X, layerIndex, layerOutputIndex, nameValuePairs{:});
Error in DNNTest_reshape67_2_functionlayer (line 61)
activations_after7 = activations(new_net, xtest, 'new_reshape_layer');
I don't know why this error happened and how to get into the network to debug it.
Akzeptierte Antwort
Weitere Antworten (1)
Richard
am 22 Jun. 2023
The functionLayer you created will only work with inputs that have a batch size of 1 - it is reshaping the input to K x 7 x 1 x 1. You are then using the network with a batch size of 128.
You need to use a resize shape that keeps the batch size from the input: Try this instead:
new_reshape_layer = functionLayer(@(X) dlarray(reshape(X,size(X,1)/7,7,1,size(X, 2)),"SSCB"),Name='new_reshape_layer',Formattable=true,Acceleratable=true);
Kategorien
Mehr zu Deep Learning Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!