フィルターのクリア

Error using trainMaskRCNN with reshape of classificationTargets in MaskRCNNLoss

11 ビュー (過去 30 日間)
Lewis Griffin
Lewis Griffin 2023 年 11 月 23 日
回答済み: Lewis Griffin 約3時間 前
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 約3時間 前
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 Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by