How to create a box label datastore?

26 ビュー (過去 30 日間)
Lorenzo Tonelli
Lorenzo Tonelli 2022 年 2 月 11 日
コメント済み: Lorenzo Tonelli 2022 年 2 月 11 日
Hello, I've been trying to create a box label datastore using the blds function.
What I understood, is that I need to create a table with the first column containing a type 'double' array, coordinates of bounding boxes, and a string variable with its class.
Now, how can I assign a 1x4 'double' vector into 1 single cell? In this 'fake' case, coordinates of bb are all the same, so is the class. I would need something like:
[0, 0, 300, 300] 'stopSignal'
[0, 0, 300, 300] 'stopSignal'
bbox = [0 0 300 300]; %images: 4170
maxSamples = 4170;
varTypes = {'double', 'string'};
size = [4170 2];
T = table('size',size, 'VariableTypes', varTypes);
for i = 1:maxSamples
T (i,1) = {bbox};
end
The error occurs because bbox is a 1x4 double vector, while MATLAB expects only a 1x1 variable to be stored in one single cell.
What am I missing?

採用された回答

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh 2022 年 2 月 11 日
you can easily create and edit a cell. then convert it to table.
here is an example:
boxes = cell(10,2); %number of images x 2=(coordinates of box , labels)
% fill boxes :
for i=1:10
n = randi(3); % number of box in i-th image, it maybe diffrenent so i consider it
boxes{i,1} = rand(n,4); % nx4 each row coordinate of a box
boxes{i,2} = string(randi(2,n,1)); % here i create n label for every image between 2 possible labels
end
% Convert to table
boxes = cell2table(boxes,'VariableNames',{'Boxes','Labels'});
blds = boxLabelDatastore(boxes)
blds =
boxLabelDatastore with properties: LabelData: 10x2 cell array {[0.1264 0.5256 0.1346 0.2392]} {[1 ]} {[0.3028 0.0742 0.1592 0.0875]} {[2 ]} {3×4 double } {3×1 categorical} ... and 7 more rows ReadSize: 1
Remember if this blds is gonna use for a deep learning applications, values of each box should be checked. 0 is invalid for deep learning. and sum of 3-th element and first one shouldn't be more than image width, and sum of 4th and 2th element shouldn't be more than image height.
  3 件のコメント
Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh 2022 年 2 月 11 日
Oh yes. when all boxes are 1x4, the cell2table automatically change the table first column to double not cell.
so here's the solution:
create boxes as cell, then use table function.
for i=1:10
boxes(i,1) = {[2 2 298 298]};
end
labels = num2cell(string(randi(2,10,1)));
boxes = table(boxes,labels);
blds = boxLabelDatastore(boxes)
blds =
boxLabelDatastore with properties: LabelData: 10x2 cell array {[2 2 298 298]} {[2]} {[2 2 298 298]} {[2]} {[2 2 298 298]} {[1]} ... and 7 more rows ReadSize: 1
Lorenzo Tonelli
Lorenzo Tonelli 2022 年 2 月 11 日
Thank you! Works like a charm.

サインインしてコメントする。

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by