How to create a box label datastore?

12 次查看(过去 30 天)
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
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
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

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by