problem in using trackCLEARMetrics

1 view (last 30 days)
alex
alex on 30 Jan 2024
Answered: Gael Goron on 22 Feb 2024
Hello. I am evaluating my MOT algorithm with Matlab MOT metric trackCLEARMetrics and I use data from Result_Cell_122.mat that I uploaded an image of that. the code encounters this error :
The logical indices contain a true value outside of the array bounds.
Error in trackCLEARMetrics/validateEvalInputs (line 448)
truthsPerStep{i} = truths(truthtimesteps == curtime);
Error in trackCLEARMetrics/evaluate (line 219)
[nsteps, tracksPerStep, truthsPerStep, alltruthIDs] = validateEvalInputs(obj, tracks, truths);
Error in MOT_eval (line 103)
MOTCLEAR = evaluate(tcm, Tr_ped2_test7, GT_ped2_test7)
can anyone help me resolve it? I know there is an indexing issue I need to figure out how to resolve it. here is the code :
clc;clear;close;
% ped2 test7
load('Result_Cell_122.mat');
Det1_2p = [2;2;2;3;2;4;4;4;4;3;3;2;2;2;3;3;4;NaN;NaN;NaN;NaN;NaN;...
1;1;1;1;1;2;2;9;2;7;8;2;4;3;3;4;3;5;5;5;4;4;11;10;5;5;5;4;4;4;4;3];
Det2_8p = [8;8;8;8;4;3;3;3;3;8;8;7;7;6;9;7;3;6;7;2;1;1;2;2;2;2;2;...
8;10;10;9;8;9;3;5;4;4;5;4;6;6;6;5;5;4;4;12;6;6;6;10;6;6;5];
Time_Det1 = [1:54]';
Time_Det2 = [1:54]';
ID_Det1 = 2*ones(54,1);
ID_Det2 = 8*ones(54,1);
Det1_bbox = [];
for i=1:54
if i==18
Det1_bbox = [Det1_bbox;...
63.6515198,1.3538095e+02,14.5588455,28.0277100] ;
elseif i==19
Det1_bbox = [Det1_bbox;...
63.1005554,1.3549432e+02,14.5588455,28.0277100];
elseif i==20
Det1_bbox = [Det1_bbox;...
62.5495949,1.3560770e+02,14.5588455,28.0277100];
elseif i==21
Det1_bbox = [Det1_bbox;...
61.9986305,1.3572107e+02,14.5588455,28.0277100];
elseif i==22
Det1_bbox = [Det1_bbox;...
61.4476700,1.3583444e+02,14.5588455,28.0277100];
else
Det1_bbox = [Det1_bbox;Result_Cell_122{3,i}(Det1_2p(i),:)];
end
end
%%
Det2_bbox = [];
for j=1:54
if j==18
Det2_bbox = [Det2_bbox;...
52.7395325,1.3568140e+02,23.6471252,39.3582458] ;
elseif j==19
Det2_bbox = [Det2_bbox;...
54.4412346,1.3571327e+02,22.0156136,39.1851807];
elseif j==20
Det2_bbox = [Det2_bbox;...
56.9931030,1.3547293e+02,17.7221985,38.7711792];
elseif j==21
Det2_bbox = [Det2_bbox;...
59.5547447,1.3517345e+02,16.4176674,39.2759857];
elseif j==22
Det2_bbox = [Det2_bbox;...
59.8172073,1.3543347e+02,16.5407333,38.6043854];
else
Det2_bbox = [Det2_bbox;Result_Cell_122{3,j}(Det2_8p(j),:)];
end
end
tcm = trackCLEARMetrics(SimilarityMethod ="IoU2d", SimilarityThreshold = 0.1);
GT_ped2_test7 = struct();
GT_ped2_test7.Time = double([Time_Det1;Time_Det2]);
GT_ped2_test7.TruthID = double([ID_Det1;ID_Det2]);
GT_ped2_test7.BoundingBox = double([Det1_bbox;Det2_bbox]);
GT_ped2_test7.ClassID = double(-1.*ones(108,1));
Tr_ped2_test7 = struct();
Tr8_bbox = [0 0 0 0];
for hh = 2:54
for ff = 1:length(Result_Cell_122{10, hh})
if Result_Cell_122{10, hh}(ff).id==8
Tr8 = Result_Cell_122{10, hh}(ff).bbox;
Tr8_bbox = [Tr8_bbox;Tr8];
end
end
end
Tr2_bbox = [0 0 0 0];
for hh1 = 2:54
for gg=1:length(Result_Cell_122{10, hh1})
if Result_Cell_122{10, hh1}(gg).id==2
Tr2 = Result_Cell_122{10, hh1}(gg).bbox;
Tr2_bbox = [Tr2_bbox;Tr2];
end
end
end
Time1 = [Time_Det1;Time_Det2];
TrackID1 = [ID_Det1;ID_Det2];
BoundingBox1 = [Tr2_bbox;Tr8_bbox];
ClassID1 = -1.*ones(108,1);
combined_Tr = [Time1,TrackID1,...
BoundingBox1,ClassID1];
sortedcombined_Tr = sortrows(combined_Tr);
Tr_ped2_test7.Time = double(sortedcombined_Tr(:,1));
Tr_ped2_test7.TrackID = double(sortedcombined_Tr(:,2));
Tr_ped2_test7.BoundingBox = double(sortedcombined_Tr(:,3:6));
Tr_ped2_test7.ClassID = double(sortedcombined_Tr(:,7));
MOTCLEAR = evaluate(tcm, Tr_ped2_test7, GT_ped2_test7)

Answers (1)

Gael Goron
Gael Goron on 22 Feb 2024
Hi Alex,
This error comes from a wrong formatting of the truth and track inputs to the object function evaluate().
I am sure you have already read its documentation, but let me try and clarify. Both of these inputs must be an array of structs, and not a single struct with multidimensional data as you have it.
Currently your Tr_ped2_test7 is a scalar struct, and its field Time is a vector of length, say N. Instead you need to have N struct and each will have a field Time which is a scalar value.
And if that is still not clear, I believe this code should convert your current variables to the appropriate format, but of course I would recommend updating your script to construct the variables in this format to being with.
numTracks = length(Tr_ped2_test7.Time);
trackFormat = struct('Time',0,'BoundingBox',[0 0 0 0], 'TrackID',0, 'ClassID',0);
tracks = repmat(trackFormat, 1, numTracks); % tracks is an array of structs
for i=1:numTracks
tracks(i) = struct('Time',Tr_ped2_test7.Time(i),...
'TrackID',Tr_ped2_test7.TrackID(i), ...
'BoundingBox', Tr_ped2_test7.BoundingBox(i,:),...
'ClassID', -1);
end
numTruths = length(GT_ped2_test7.Time);
truthFormat = struct('Time',0,'BoundingBox',[0 0 0 0], 'TruthID',0, 'ClassID',0);
truths = repmat(truthFormat, 1, numTracks); % truths is an array of structs
for i=1:numTruths
truths(i) = struct('Time',GT_ped2_test7.Time(i),...
'TruthID',GT_ped2_test7.TruthID(i), ...
'BoundingBox', GT_ped2_test7.BoundingBox(i,:),...
'ClassID', -1);
end
% Evaluate with correctly formatted inputs
MOTCLEAR = evaluate(tcm, tracks, truths)

Community Treasure Hunt

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

Start Hunting!