autolabeler error of array indices

Hi,
I am trying to use model assisted labeling with the following code:
function autoLabels = yoloImageLabeler(I)
% Add your code here
% Set up the persistent variable for the detector
persistent detector
if isempty(detector)
% Note: make sure the detector is on your path
load mynewyolo.mat detector
end
% Detect the objects and save the bounding boxes and labels
[bbox,~,labels] = detect(detector,I);
% Get unique list of labels (to loop through later)
detectedLabels = unique(labels);
% Initialize output
autoLabels(length(detectedLabels)) = struct();
% Add results to the output autoLabels
for i = 1:length(detectedLabels)
label = string(detectedLabels(i));
autoLabels(i).Name = label;
autoLabels(i).Type = labelType("Rectangle");
autoLabels(i).Position = bbox(labels == label, :);
end
end
However, matlab runs into error after labeling 2-3 images from 300 and generates error:(ATTACHED IMAGE)
Error using vision.labeler.FunctionalAutomationAlgorithm/run (line 77)
The custom automation function threw the following error:
Array indices must be positive integers of logical values.
Please provide support. I have resized image to same size and named them sequentially. Also my model is custom yolo model with one class 'person' only.
Thanks

9 commentaires

dpb
dpb il y a 7 minutes
What is the content of detectedLabels?
As a note, length is a potentially dangerous function; it returns max(size(x)), not necessarily the size in the dimension of interest. Depending upon what the detectedLabels array is, you may not have what you think you have for the array of struct.
Set a breakpoint and see what is being returned for the label when it fails...
tren
tren il y a environ 3 heures
manually detected the image through trained model:
i=imread("image_0001.jpeg");
>> [bbox,~,labels] = detect(detector,i)
bbox =
0×4 empty single matrix
labels =
0×1 empty categorical array
Is this empty array being the problem, if the detector fails to find the label i.e., person: auto labeler will generate error??
any code to work around this problem?
dpb
dpb il y a environ 3 heures
I wondered about that as being an issue....
Put in a try...catch ... end block would be one relatively painless approach -- just let it go on to the next with an empty catch block.
tren
tren il y a environ 2 heures
can you pseudo code it for me pls.
much appreciated
dpb
dpb il y a environ 7 heures
Modifié(e) : dpb il y a environ 5 heures
for i = 1:length(detectedLabels)
try
label = string(detectedLabels(i));
autoLabels(i).Name = label;
autoLabels(i).Type = labelType("Rectangle");
autoLabels(i).Position = bbox(labels == label, :);
catch
disp(['Label:' label ' not found. Continuing.') % option indication to user
% you may want/need(?) to put in a dummy vector for the .Position field
% since this doesn't change the indices.
end
end
A different solution could keep a second counter of the found locations and not increment the output struct index if not found. Then the total size would end up less by the number not found. Which would work best would depend on your needs.
Potentially,
detectedLabels = detectedLabels(~ismissing(detectedLabels));
for i = 1:length(detectedLabels)
label = string(detectedLabels(i));
autoLabels(i).Name = label;
autoLabels(i).Type = labelType("Rectangle");
autoLabels(i).Position = bbox(labels == label, :);
end
We have pre-filtered to get rid of missing entries.
tren
tren il y a environ 6 heures
Hi GUYS,
Walter, the pre-filter is not working and same error is thrown. Only when the detector does not detect an object , it generates the subject error.
dpb: your method did not work as well...
I even tried isempty(label) but its not working....
dpb
dpb il y a environ 6 heures
I was afeered of that...the error coming from the run method of the autolabeler is way deeper than the shown code where the logical test shouldn't cause a problem or the try...catch block would trap it.
Would need to see the rest of the error message for additional clues, but setting a breakpoint there and seeing what the values of this, frame and info are would probably give us a klew as to what is occurring.
But, failing that much in depth, SAVE and attach a .mat file with the variables bbox and labels
tren
tren il y a environ 5 heures
i solved the problem by returning empty structure for autoLabelers..... This is interpreted as background only image by the auto-labeler.
Thanks guys

Connectez-vous pour commenter.

Réponses (0)

Produits

Version

R2025b

Question posée :

le 5 Mai 2026 à 15:49

Commenté :

il y a environ 5 heures

Community Treasure Hunt

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

Start Hunting!

Translated by