2入力CNNのデータセットの作成について
Show older comments
2入力1出力のCNNのデータセットの作成方法について教えていただきたいです。
2種類の画像データを異なる入力層から入力し、加算層で特徴量を統合、その後クラス分類を行うCNNを動作させたいと考えております。
以下のリンクに、多入力ネットワークの学習方法について記載があるのですが、以下の文章を実現するための方法が分かりません。
内容1部抜粋:
”combinedDatastore オブジェクトまたは transformedDatastore オブジェクトを使用して複数の入力を指定”
”データストアは、予測子と応答を含む列数が (numInputs+1) の cell 配列”
imageDatastoreを用いた2つのデータセットの作成、combineによる結合までは可能でしたが、そこに応答を結合する方法が分かりません。
以下にエラーが出るプログラムを記載させていただきます。
2入力CNNのデータセットの作成について、教えていただければ幸いです。
% file path
digitDatasetPath = fullfile(matlabroot,'toolbox','nnet','nndemos', ...
'nndatasets','DigitDataset');
% input1
imds1 = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
% input2
imds2 = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
%% create a new CNN
% input1
I = read(imds1);
[height, width, ch] = size(I);
layers = [
imageInputLayer([height width ch], 'Name', 'data1');
convolution2dLayer([1 1], 1, 'Name','conv1');
];
lgraph = layerGraph(layers);
% input2
layers = [
imageInputLayer([height width ch], 'Name', 'data2');
additionLayer(2, 'Name','add');
fullyConnectedLayer(10, 'Name','fc');
softmaxLayer('Name','prob');
classificationLayer('Name','classoutput');
];
lgraph = addLayers(lgraph, layers);
% connect
lgraph = connectLayers(lgraph, 'conv1', 'add/in2');
%% options
options = trainingOptions('adam', ...
'InitialLearnRate', 0.1, ...
'MinibatchSize', 1, ...
'MaxEpochs', 10, ...
'Shuffle', 'every-epoch', ...
'ExecutionEnvironment', 'gpu', ...
'Plots', 'training-progress');
%% training
train = combine(imds1, imds2);
% challenged → error
% train = combine(train, imds1);
trainNetwork(train, lgraph, options);
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!