Error calling trainNetwork with a combined image datastore - each with categorical labels
3 views (last 30 days)
Show older comments
I don't know how to approach fixing this error. My underlying image datastores all have categorical labels. ???
%%%%%%%%%%%%%%%%%%%
Error using trainNetwork (line 184)
Invalid training data. For image, sequence-to-label, and feature classification tasks,
responses must be categorical.
Error in deepLearnLVOvNoLVO (line 180)
trainedNet = trainNetwork(imds_train, lgraph, options);
where:
imds_train =
CombinedDatastore with properties:
UnderlyingDatastores: {1×4 cell}
SupportedOutputFormats: [1×16 string]
and, for example:
>> imds_train.UnderlyingDatastores{1}
ans =
ImageDatastore with properties:
Files: {
'REDACTED/S2-021-XR-00000926.jpg';
'REDACTED/S2-048-XR-00003697.jpg';
'REDACTED/S2-048-XR-00003673.jpg'
... and 1290 more
}
Folders: {
'REDACTED'
}
Labels: [REDACTED; REDACTED; REDACTED ... and 1290 more categorical]
AlternateFileSystemRoots: {}
ReadSize: 1
SupportedOutputFormats: ["png" "jpg" "jpeg" "tif" "tiff"]
DefaultOutputFormat: "png"
ReadFcn: @readDatastoreImage
0 Comments
Answers (1)
Srivardhan Gadila
on 28 Dec 2021
From the above information, I think you are trying to train a multi input network and all the imageDatastores you are combining has the label data. If that's the case, the read operation on the final datastore should output all the inputs, plus labels (or responses). Refer to the following pages for more information: trainNetwork - Data format & Multiple-Input and Multiple-Output Networks.
When we combine two or more imageDatastores, the read operation on resulting CombinedDatastore will only output the data of input images and not the label data. Hence we should also combine the label information along with imageDatastores. You can make use of arrayDatastore for it.
% Assuming that your imageDatastores are imds1, imds2, imds3 & imds4 with
% all of them having same "Labels" information.
labels = imds1;
labelsds = arrayDatastore(labels);
cdsTrain = combine(imds1,imds2,imds3,imds4,labelsds);
read(cdsTrain)
If this it not what you are working on and the individual imageDatastores are for four different label classes ("REDACTED" and etc.), and you are trying to combine them, then instead of doing it that way, just create an imageDatastore using the "IncludeSubfolders" and "LabelSource" Name-Value arguments. Refer to the Name-Value Pair Arguments of imageDatastore for more information.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!