2入力CNNのデータセットの作成について
23 views (last 30 days)
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);
0 Comments
Accepted Answer
Kenta
on 13 Jul 2020
こちらは「カスタムループ」という方法で書いてますが、同様のことができると思います。こちらでよい精度がでるかもしれません。そちらのデータの状況によりますが、例えば、入力AとBの枚数がおなじ/違うのか、AとBが厳密には1対1対応しているか/いないか、AとBをそれぞれどのような方法でサンプリングしたいかなど、色々と改良を加えたい場合が出てくると思うのですが、そのときは「カスタムループ」のほうですると書きやすいかもしれません。
2入力を使うのは、conditional GANやconditional VAE でも見られます。こちらの実装のアイデアも役に立つかもしれません。
More Answers (0)
See Also
Categories
Find more on イメージを使用した深層学習 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!