Why the "minibatchqueue" converts my "categorical" array to "dlarray"?

10 ビュー (過去 30 日間)
MathWorks Support Team
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
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 件)

カテゴリ

Help Center および File ExchangeDeep Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by