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

6 comentarios

dpb
dpb hace 7 minutos
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 hace 2 minutos
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 hace alrededor de 2 horas
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 hace alrededor de 2 horas
can you pseudo code it for me pls.
much appreciated
dpb
dpb hace alrededor de 4 horas
Editada: dpb hace alrededor de 2 horas
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.

Iniciar sesión para comentar.

Respuestas (0)

Productos

Versión

R2025b

Preguntada:

hace alrededor de 9 horas

Comentada:

hace alrededor de 4 horas

Community Treasure Hunt

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

Start Hunting!

Translated by