Why the "minibatchqueue" converts my "categorical" array to "dlarray"?
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 28 Sep. 2023
Beantwortet: MathWorks Support Team
am 2 Okt. 2023
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"?
Akzeptierte Antwort
MathWorks Support Team
am 28 Sep. 2023
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Deep Learning Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!