필터 지우기
필터 지우기

Error using trainNetwork for network with multiple input

조회 수: 31 (최근 30일)
Teo
Teo 2021년 9월 29일
댓글: Xuan Yang 2023년 6월 30일
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)

채택된 답변

Srivardhan Gadila
Srivardhan Gadila 2021년 10월 5일
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
Xuan Yang
Xuan Yang 2023년 6월 30일
Hi @Teo,
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:
  1. There is only one sample in YPred.
  2. 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
Xuan Yang 2023년 6월 30일
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:
  1. There is only one sample in YPred.
  2. 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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by