How to train a DAG with two inputs with a combined data store?

조회 수: 1 (최근 30일)
Thyagharajan K K
Thyagharajan K K 2021년 12월 5일
답변: Nivedita 2025년 2월 20일
I have combined two data stores using the code
imdsCombined = combine(Stream1_imds,Stream2_imds)
The two datastores are combined as 1x2 cell array. Each cell has one datastore as shown below.
Then I wanted to split the labels of combined datastore for training and testing using the function
[imdsTrain,imdsTest] = splitEachLabel(imdsCombined,numTrainFiles);
The above step is necessary to train the network using
kkt_net_transfer = trainNetwork(imdsTrain,Combined_lgraph,Stream1_opts);
But I got an error "Check for missing argument or incorrect argument data type in call to function 'splitEachLabel'".
This is because of the non availablity of the labels in the combined datastore. I couldn't attach lables to the combined datastore and it was not supported.
We can combine two image datastores in many ways. I tried those methods but they are not suitable to train the network using trainNetwork().
I have used MATLAB version 2020a. Is there any solution?

답변 (1개)

Nivedita
Nivedita 2025년 2월 20일
In MATLAB, when you combine datastores using combine, it creates a CombinedDatastore object, which doesn't directly support label operations like splitEachLabel. To work around this, you can manually merge the files and labels from the individual datastores before splitting them. Here is a sample code for your reference:
% Extract files and labels from each datastore
files1 = Stream1_imds.Files;
labels1 = Stream1_imds.Labels;
files2 = Stream2_imds.Files;
labels2 = Stream2_imds.Labels;
% Concatenate files and labels
allFiles = [files1; files2];
allLabels = [labels1; labels2];
% Create a new ImageDatastore
imdsCombined = imageDatastore(allFiles, 'Labels', allLabels);
% Split the datastore
[imdsTrain, imdsTest] = splitEachLabel(imdsCombined, numTrainFiles);
% Train the network
kkt_net_transfer = trainNetwork(imdsTrain, Combined_lgraph, Stream1_opts);

카테고리

Help CenterFile Exchange에서 Get Started with Deep Learning Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by