Error using trainNetwork for network with multiple input

59 views (last 30 days)
Teo
Teo on 29 Sep 2021
Commented: Teo on 5 Oct 2021
Hi,
I having a CNN that using two input where one of the input using zscore for normalization while the another input using zerocentre normalization (The input data are the same except for normalization setting). However when i tried to train the network using the following command the error occur (Invalid training datastore. For network with multiple inputs, used combined or transformed datastore.). I'm not sure how to insert 2 input into trainNewtork function. Hope someone could help me on this. Thank you very much.
imds = imageDatastore('MerchData', 'IncludeSubfolders',true, 'LabelSource','foldernames');
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7);
augimdsTrain = augmentedImageDatastore(inputSize(1:2),imdsTrain)
augimdsValidation = augmentedImageDatastore(inputSize(1:2),imdsValidation)
% the rest of the code -----
[testnet,traininfo] = trainNetwork(augimdsTrain,lgraph_1,options);
The two input are as followed
input 1 (normalization: zscore)
input 2 (normalization: zerocentre)

Accepted Answer

Srivardhan Gadila
Srivardhan Gadila on 5 Oct 2021
As per the above information, data for both the inputs is same except for normalizations on the input data, so you can create a combined datastore as follows:
cds = combine(imds,imds,labelds);
For more information, you can refer to the following pages on what should be the data format for multiple input networks trainNetwork - Data format & Multiple-Input and Multiple-Output Networks.
Since we are using augmentedImageDatastore and there is a knwon issue on combining the augmentedImageDatastores directly. The workaround is to apply transform on the augmentedImageDatastore and combine it. Also we have to do some other changes to make the workflow possible, as follows:
augimdsTrain.MiniBatchSize = 1;
taugimdsTrain = transform(augimdsTrain,@(x)x{1,1});
labelsTrain = transform(augimdsTrain,@(x){x{1,2}});
% combine the datastores
cds = combine(taugimdsTrain,taugimdsTrain,labelsTrain);
For more information, refer to the following answer on similar issue with other datastore when combining Error Combining two pixelLabelImageDatastores or randomPatchExtractionDatastores.
  3 Comments
Teo
Teo on 5 Oct 2021
Thanks @Srivardhan Gadila for your explanation and pointing out the "labelsValidation" that i miss out. once again thank you very much for your time and help.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by