Error using trainNetwork for network with multiple input
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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)
0 commentaires
Réponse acceptée
Srivardhan Gadila
le 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.
6 commentaires
Xuan Yang
le 30 Juin 2023
Thanks for your question and code. But I have a question. I don't known how to evaluate the test set on the trained multiple input neural network. Since there is no test set in your source code, I just use the validation set as the test set. I run the following code
[YPred,scores] = classify(testnet,cds2);
accuracy = mean(YPred == labelsValidation);
however, it doesn't work. There are two problems:
- There is only one sample in YPred.
- The error information is 'Incorrect use== There is no comparison defined between categorical and matlab.io.datastore.TransformedDatastore arrays.'
I suppose the datastore of cds and cds2 is not suitble for testing. I want to get the final accuracy on the test set. I don't know how to arrange the test samples and test set labels.
How did you solve this problem? Do you have any suggestion? Thank you very much!
Xuan Yang
le 30 Juin 2023
Thanks for your answer. But I have a question. I don't known how to evaluate the test set on the trained multiple input neural network. Since there is no test set in Teo's source code, I just use the validation set as the test set. I run the following code
[YPred,scores] = classify(testnet,cds2);
accuracy = mean(YPred == labelsValidation);
however, it doesn't work. There are two problems:
- There is only one sample in YPred.
- The error information is 'Incorrect use== There is no comparison defined between categorical and matlab.io.datastore.TransformedDatastore arrays.'
I suppose the datastore of cds and cds2 is not suitble for testing. I want to get the final accuracy on the test set. I don't know how to arrange the test samples and test set labels.
How did you solve this problem? Do you have any suggestion? Thank you very much!
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Data Workflows dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!