trainpath1 = fullfile("PATH TO INPUT1 IMAGES");
trainpath2 = fullfile("PATH TO INPUT2 IMAGES");
imds1 = imageDatastore(trainpath1, 'IncludeSubfolders',true, 'FileExtensions','.PNG','LabelSource','foldernames');
imds2 = imageDatastore(trainpath2, 'IncludeSubfolders',true, 'FileExtensions','.PNG','LabelSource','foldernames');
labelds = fileDatastore('labelData.mat','ReadFcn',@myReadFcn,'ReadMode','partialfile');
cds = combine(imds1,imds2,labelds);
imsize1 = [32 80 3];
imsize2 = [48 64 3];
numClasses = 5;
layers1 = [
imageInputLayer(imsize1,'Name','input1')
convolution2dLayer(3,16,'Padding','same','Name','conv_1')
reluLayer('Name','relu_1')
fullyConnectedLayer(10,'Name','fc11')
additionLayer(2,'Name','add')
fullyConnectedLayer(numClasses,'Name','fc12')
softmaxLayer('Name','softmax')
classificationLayer('Name','classOutput')];
lgraph = layerGraph(layers1);
layers2 = [imageInputLayer(imsize2,'Name','input2')
convolution2dLayer(3,16,'Padding','same','Name','conv_2')
reluLayer('Name','relu_2')
fullyConnectedLayer(10,'Name','fc21')];
lgraph = addLayers(lgraph,layers2);
lgraph = connectLayers(lgraph,'fc21','add/in2');
plot(lgraph)
options = trainingOptions('adam', ...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise',...
'MaxEpochs',3, ...
'MiniBatchSize',1, ...
'Verbose',1, ...
'Plots','training-progress');
net = trainNetwork(cds,lgraph,options);
function [data,userdata,done] = myReadFcn(filename,userdata)
if isempty(userdata)
labels = load(filename);
userdata = labels.labels;
end
data = userdata(1);
userdata(1) = [];
done = isempty(userdata);
end
Best Answer