How to input CNN images from two sources?
Afficher commentaires plus anciens
Good afternoon!
Can you please tell me how to submit images from two different sources to the CNN input at once?
I use two inputs (two imageInputLayer layers), which I then combine using the depthConcatenationLayer layer (see attached file). However, it is not possible to transfer data from two sources when training the network. I use the line:
net = trainNetwork([imdsTrain1, imdsTrain2],lgraph,options);
but it does not work, writes "wrong data format".
Or is the approach being used fundamentally wrong and another way should be applied?
% first image source
digitDatasetPath = uigetdir;
imds1 = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true, ...
'LabelSource','foldernames');
% second image source
digitDatasetPath = uigetdir;
imds2 = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true, ...
'LabelSource','foldernames');
[imdsTrain1,imdsValidation1] = splitEachLabel(imds1,numTrainFiles,'randomize');
[imdsTrain2,imdsValidation2] = splitEachLabel(imds2,numTrainFiles,'randomize');
lgraph = layerGraph();
tempLayers = imageInputLayer([90 90 3],"Name","imageinput_1");
lgraph = addLayers(lgraph,tempLayers);
tempLayers = imageInputLayer([90 90 3],"Name","imageinput_2");
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","depthcat")
convolution2dLayer([3 3],32,"Name","conv_1","Padding","same")
batchNormalizationLayer("Name","batchnorm_1")
reluLayer("Name","relu_1")
maxPooling2dLayer([5 5],"Name","maxpool","Padding","same")
convolution2dLayer([3 3],32,"Name","conv_2","Padding","same")
batchNormalizationLayer("Name","batchnorm_2")
reluLayer("Name","relu_2")
fullyConnectedLayer(3,"Name","fc")
softmaxLayer("Name","softmax")
classificationLayer("Name","classoutput")];
lgraph = addLayers(lgraph,tempLayers);
clear tempLayers; % clean up helper variable
lgraph = connectLayers(lgraph,"imageinput_1","depthcat/in1");
lgraph = connectLayers(lgraph,"imageinput_2","depthcat/in2");
plot(lgraph);
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.01, ...
'MaxEpochs',25, ...
'MiniBatchSize',128, ...
'Shuffle','every-epoch', ...
'ValidationFrequency',3, ...
'Verbose',false, ...
'Plots','training-progress')
net = trainNetwork([imdsTrain1, imdsTrain2],lgraph,options); % it throws an error that you can't merge like this

Thanks in advance!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Semantic Segmentation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!