There is a problem running minibatchqueue function.

12 次查看(过去 30 天)
I made my data set. Here is a part of it.
I run my dataset and an error occurs at this step.
mbqTrain = minibatchqueue(preprocessedTrainingData, 2,...
"MiniBatchSize", miniBatchSize,...
"MiniBatchFcn", @(images, boxes, labels) createBatchData(images, boxes, labels, classNames), ...
"MiniBatchFormat", ["SSCB", ""],...
"DispatchInBackground", dispatchInBackground,...
"OutputCast", ["", "double"]);
It says: Error using minibatchqueue, Unable to apply function specified by 'MiniBatchFcn' value.
Caused by: Error using cat, Dimensions of arrays being concatenated are not consistent.
I checked and found that when running the function createBatchData:
function [XTrain, YTrain] = createBatchData(data, groundTruthBoxes, groundTruthClasses, classNames)
some of the data in the input argumentsr groundTruthBoxes become empty. LIke the third line:
But it's supposed to have a 3*4double data here. But it just disappear.
I dont know whether other people have met this question, or it just me. But I'm really frustrated with this question.
Please help me.

回答(1 个)

泽宇 王
泽宇 王 2021-5-18
I figured out what was the problem. After my step-by-step debugging, I found problem in this line of code.
preprocessedTrainingData = transform(augmentedTrainingData, @(data)preprocess(yolov3Detector, data));
data = read(preprocessedTrainingData);
This line of code points to this function: vision.internal.cnn.LetterBoxImage
function [Inew,bboxnew] = LetterBoxImage(I,targetSize,varargin):
[Irow,Icol,Ichannels] = size(I);
bboxnew = [];
% Compute aspect Ratio.
arI = Irow./Icol;
% Preserve the maximum dimension based on the aspect ratio.
if arI<1
IcolFin = targetSize(1,2);
IrowFin = floor(IcolFin.*arI);
else
IrowFin = targetSize(1,1);
IcolFin = floor(IrowFin./arI);
end
% Resize the input image.
Itmp = imresize(I,[IrowFin,IcolFin]);
% Initialize Inew with gray values.
Inew = ones([targetSize,Ichannels],'like',I).*0.5;
% Compute the offset.
if arI<1
buff = targetSize(1,1)-IrowFin;
else
buff = targetSize(1,2)-IcolFin;
end
% Place the resized image on the canvas image.
if (buff==0)
Inew = Itmp;
else
buffVal = floor(buff/2);
if arI<1
Inew(buffVal:buffVal+IrowFin-1,:,:) = Itmp;
if ~isempty(varargin)
% Resize bounding boxes.
bboxnew = iScaleBboxes(varargin{1,1},size(Itmp),size(I));
bboxnew(:,2) = bboxnew(:,2)+buffVal;
end
else
Inew(:,buffVal:buffVal+IcolFin-1,:) = Itmp;
if ~isempty(varargin)
% Resize bounding boxes.
bboxnew = iScaleBboxes(varargin{1,1},size(Itmp),size(I));
bboxnew(:,1) = bboxnew(:,1)+buffVal;
end
end
end
end
I find the picture which gets error has the size with 612*612*3, and the target size is 227*227*3. So the variable arI goes to 1, and the varible buff goes to 0. The calculation of bboxnew has been skipped, so it goes to [].
  1 个评论
bipun manpati
bipun manpati 2021-5-29
hi there,
I would like to know if this error is due to the same size of width and height of the image. as you have mentioned the image size is 612. i had checked in vehicle dataset and found that it has different size of width and height. For my case, image size is 256*256* 3 and found all bounding boxes empty.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by