複数の入力層を持つCNNにおいて加算層を持つ事前学習済みネットワークを使用する際に発生するエラーについて
2 ビュー (過去 30 日間)
古いコメントを表示
https://jp.mathworks.com/matlabcentral/fileexchange/74760-image-classification-using-cnn-with-multi-input-cnn
上記の手法を参考に2種類の画像データセットを用いたCNNの作成を試みているのですが,ネットワークのアーキテクチャを
事前学習済みネットワークに置き換え学習したところResNet-18やResNet-50、GoogleNetなど加算層を持つネットワークでエラーが発生しました.
エラー文から未接続の入力があると分かりましたが改善方法が分かりませんでした。
以下にプログラムの一部とエラー文を示します。このエラーの改善方法を教えていただきたいです。
よろしくお願いいたします。
%データセット
auimdsTrain=augmentedImageDatastore([224,224],imds,'OutputSizeMode','centercrop');
auimdsValidation=augmentedImageDatastore([224 224],imds3,'OutputSizeMode','centercrop');
auimdsTrain2=augmentedImageDatastore([224,224],imds2,'OutputSizeMode','centercrop');
auimdsValidation2=augmentedImageDatastore([224,224],imds4,'OutputSizeMode','centercrop');
auimdsTest=augmentedImageDatastore([224,224],imds5,'OutputSizeMode','centercrop');
auimdsTest2=augmentedImageDatastore([224,224],imds6,'OutputSizeMode','centercrop');
label1=imds.Labels;
label2=imds3.Labels;
label3=imds5.Labels;
[XTrainUpper,XTrainBottom,XValidUpper,XValidBottom,XTestUpper,XTestBottom,YTrain,YValid,YTest]=partitionData(auimdsTrain,auimdsTrain2,auimdsValidation,auimdsValidation2,auimdsTest,auimdsTest2,label1,label2,label3);
classes=categories(YTrain);
numClasses=numel(classes);
%ネットワーク
net=resnet18;
net=layerGraph(net);
layersTransfer=net.Layers(2:end-3);
layersTransfer2=net.Layers(3:end-3);
numHiddenDimension=142; % speficy the dimension of the hidden layer
layers = createSimpleLayer(XTrainUpper,numHiddenDimension,layersTransfer);
layers2 = createSimpleLayer2(XTrainBottom,numHiddenDimension,layersTransfer2);
layers2=renameLayer(layers2,'_2');
layersAdd=[fullyConnectedLayer(numHiddenDimension,'Name','fcAdd1')
fullyConnectedLayer(numClasses,'Name','fcAdd2')];
layersRemoved=[layers(1:end);concatenationLayer(1,2,'Name','cat');layersAdd];
lgraphAggregated = addLayers(layerGraph(layersRemoved),layers2(1:end));
lgraphAggregated = connectLayers(lgraphAggregated,'fc_2','cat/in2');
dlnet = dlnetwork(lgraphAggregated); % A dlnetwork object enables support for custom training loops using automatic differentiation
%アーキテクチャ定義
function layers=createSimpleLayer(XTrainData_4D,numHiddenDimension,layersTransfer)
layers = [
imageInputLayer([224 224 3],"Name","imageinput","Mean",mean(XTrainData_4D,'all'))
layersTransfer
fullyConnectedLayer(numHiddenDimension,"Name","fc")];
end
function layers=createSimpleLayer2(XTrainData_4D,numHiddenDimension,layersTransfer2)
layers = [
imageInputLayer([224 224 1],"Name","imageinput","Mean",mean(XTrainData_4D,'all'))
convolution2dLayer([7 7],64,"Stride",[2 2],"DilationFactor",[1 1],"Padding",[3,3,3,3],"PaddingValue",0,"BiasLearnRateFactor",0,"WeightL2Factor",1,"Name","conv_1","Padding","same")
layersTransfer2
fullyConnectedLayer(numHiddenDimension,"Name","fc")];
end
%パーティションデータ
function [XTrainUpper,XTrainBottom,XValidUpper,XValidBottom,XTestUpper,XTestBottom,YTrain,YValid,YTest]=partitionData(auimdsTrain,auimdsTrain2,auimdsValidation,auimdsValidation2,auimdsTest,auimdsTest2,label1,label2,label3)
XTrainUpper=readall(auimdsTrain);
XTrainUpper=cat(4,XTrainUpper.input{:});
XTrainBottom=readall(auimdsTrain2);
XTrainBottom=cat(4,XTrainBottom.input{:});
XValidUpper=readall(auimdsValidation);
XValidUpper=cat(4,XValidUpper.input{:});
XValidBottom=readall(auimdsValidation2);
XValidBottom=cat(4,XValidBottom.input{:});
XTestUpper=readall(auimdsTest);
XTestUpper=cat(4,XTestUpper.input{:});
XTestBottom=readall(auimdsTest2);
XTestBottom=cat(4,XTestBottom.input{:});
YTrain=label1;
YValid=label2;
YTest=label3;
end
%レイヤー名変更
function layers=renameLayer(layers,char)
for i=1:numel(layers)
layers(i).Name=[layers(i).Name,char];
end
end
使い方によるエラー dlnetwork/initialize
無効なネットワーク。
エラー: dlnetwork (行 218)
net = initialize(net, dlX{:});
エラー: test1 (行 32)
dlnet = dlnetwork(lgraphAggregated); % A dlnetwork object enables support for custom training loops using automatic differentiation
原因:
Example inputs: Incorrect number of example network inputs. 0 example network inputs provided but network has 18 inputs including 16 unconnected layer
inputs.
層 'res2a': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res2a_2': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res2b': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res2b_2': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res3a': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res3a_2': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res3b': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res3b_2': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res4a': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res4a_2': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res4b': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res4b_2': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res5a': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res5a_2': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res5b': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
層 'res5b_2': Unconnected input. Each input must be connected to input data or to the output of another layer.
未接続の入力を検出しました:
入力 'in2'
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Deep Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!