Why the "minibatchqueue" converts my "categorical" array to "dlarray"?
10 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2023-9-28
回答: MathWorks Support Team
2023-10-2
I create a "datastore" from a "categorical" array, but after using the "minibatchqueue" function, it is converted to a "dlarray". You can find a simple code below that reproduces this issue:
% Generate some data
data=categorical(["red","green","violet","red","green","violet","violet","red","green","violet","magenta","yellow"]);
ncat=length(categories(data));
data = cellstr(data)
% Build datastore
ds=arrayDatastore(data,'IterationDimension',2);
% Check that the datastore outputs a categorical variable
sample=ds.read;
fprintf('arraydatastore outputs data with type %s\n',class(sample{1}));
% Build a minibatchqueue
mbq=minibatchqueue(ds,MiniBatchSize=3);
minibatch=mbq.next;
fprintf('mbq ouptus a mini batch data with type %s\n',class(minibatch));
Why is this happening?
Could you help me to retrieve the information of the "categories"?
采纳的回答
MathWorks Support Team
2023-9-28
The "minibatchqueue" function converts the "categorical" values to "dlarray" by default for memory efficiency. However, the information of the categories is not lost. Each "integer" in the "dlarray" represents a category with respect to the alphabetical order of the categories names. In case you need the categorical value, you can just use the "dlarray" output as an index, as in the sample code below:
mbq = minibatchqueue(ds,MiniBatchSize=2);
minibatch = mbq.next
unique_cat = unique(data);
minibatch_cat=unique_cat(minibatch)
fprintf('mbq ouptus a mini batch data with type %s\n',class(minibatch_cat));
In case you want the "minibatchqueue" function to outcast "char" values instead of "integers" you can set the "OutputAsDlarray" property to "false" and the "OutputCast" to "char" as in the command below:
mbq = minibatchqueue(ds,MiniBatchSize=2,OutputAsDlarray=false,OutputCast='char');
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!