필터 지우기
필터 지우기

Error using trainMaskRCNN with reshape of classificationTargets in MaskRCNNLoss

조회 수: 11 (최근 30일)
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

답변 (2개)

Nihal
Nihal 대략 3시간 전
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,[]);
Error using reshape
Product of known dimensions, 10, not divisible into total number of elements, 11.
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.

Lewis Griffin
Lewis Griffin 대략 2시간 전
Hi,
I have since solved this problem, while it did originate with the reshape error, the cause of the error was the fact that the categorical label array did not contain all possible classes within the image. This was an oversight on my behalf and also nearly improssible to troubleshoot without further information so I apologise for that. Hope this helps if anyone else ever has a similar problem.
Thanks,
Lewis

카테고리

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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by