Error using trainMaskRCNN with reshape of classificationTargets in MaskRCNNLoss
3 views (last 30 days)
Show older comments
When attempting to train the maskrcnn net, i get an error code with a reshape function, the exact error code is:
Error using reshape
Product of known dimensions, 3, not divisible into total number of elements, 4000.
Error in vision.internal.cnn.maskrcnn.MaskRCNNLoss/lossFcn (line 73)
classificationTargets = reshape(classificationTargets ,1, 1, size(YRCNNClass,3),[]);
Error in images.dltrain.internal.SerialTrainer>modelGradients (line 138)
[loss,lossData] = lossFcn.lossFcn(networkOutputs{:},targets{:});
Error in deep.internal.dlfeval (line 17)
[varargout{1:nargout}] = fun(x{:});
Error in deep.internal.dlfevalWithNestingCheck (line 19)
[varargout{1:nargout}] = deep.internal.dlfeval(fun,varargin{:});
Error in dlfeval (line 31)
[varargout{1:nargout}] = deep.internal.dlfevalWithNestingCheck(fun,varargin{:});
Error in images.dltrain.internal.SerialTrainer/fit (line 76)
[loss,grad,state,networkOutputs,lossData] = dlfeval(@modelGradients,self.Network,self.LossFcn,...
Error in images.dltrain.internal.dltrain (line 102)
net = fit(networkTrainer);
Error in trainMaskRCNN (line 257)
[network,info] = images.dltrain.internal.dltrain(mbqTrain,network,options,lossFcn,metrics,'Loss', 'ExperimentMonitor',params.ExperimentMonitor);
Error in ActualTrainingCode (line 111)
[net,info] = trainMaskRCNN(ds,net,options,FreezeSubNetwork="backbone");
I think the error originates with the reshape of classificationTargets in the MaskRCNNLoss function, where it tries to reshape to a array size thats not possible.
Thanks
0 Comments
Answers (2)
Nihal
on 23 Jul 2024
Hi Lewis,
I understand from your error that the ‘reshape’ function is unable to divide the total number of elements into the known dimensions. The number of elements in the original array should be divisible by the product of the known dimensions.
For example, trying to divide an array of 11 elements into 5x2xn dimension array will throw a similar error.
a = zeros(11,1);
b = reshape(a,5,2,[]);
You can learn more about ‘reshape’ from the below documentation:
To get rid of the error, try and make the dimension of the arrays compatible by modifying the code such that either the size of ‘classificationTargets’ is a multiple of 3, or the product of the dimensions is a factor of 4000.
Hope this helps.
0 Comments
See Also
Categories
Find more on Containers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!