autolabeler error of array indices
Mostrar comentarios más antiguos
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
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
hace 2 minutos
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
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.
Walter Roberson
hace alrededor de 1 hora
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.
Respuestas (0)
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!