Main Content

SeriesNetwork

(非推奨) 深層学習用の系列ネットワーク

SeriesNetwork オブジェクトは推奨されません。代わりに、dlnetwork オブジェクトを使用してください。詳細については、バージョン履歴を参照してください。

説明

系列ネットワークは、層が 1 つずつ連続して配置された深層学習用のニューラル ネットワークです。これには、1 つの入力層と 1 つの出力層があります。

作成

SeriesNetwork オブジェクトは、次のようにいくつかの方法で作成できます。

メモ

googlenetresnet50 など、他の事前学習済みのネットワークについては、事前学習済みの深層ニューラル ネットワークを参照してください。

プロパティ

すべて展開する

この プロパティ は読み取り専用です。

ネットワーク層。Layer 配列として指定します。

この プロパティ は読み取り専用です。

入力層の名前。文字ベクトルの cell 配列として指定します。

データ型: cell

この プロパティ は読み取り専用です。

出力層の名前。文字ベクトルの cell 配列として指定します。

データ型: cell

オブジェクト関数

activations(非推奨) 深層学習ネットワーク層の活性化の計算
classify(非推奨) 学習済み深層学習ニューラル ネットワークを使用したデータの分類
predict(非推奨) 学習済み深層学習ニューラル ネットワークを使用した応答の予測
predictAndUpdateState(非推奨) 学習済み再帰型ニューラル ネットワークを使用した応答の予測とネットワーク状態の更新
classifyAndUpdateState(非推奨) 学習済み再帰型ニューラル ネットワークを使用したデータの分類とネットワーク状態の更新
resetStateニューラル ネットワークの状態パラメーターのリセット
plotニューラル ネットワーク アーキテクチャのプロット

すべて折りたたむ

イメージ分類をネットワークに学習させます。

データを ImageDatastore オブジェクトとして読み込みます。

digitDatasetPath = fullfile(matlabroot,'toolbox','nnet', ...
    'nndemos','nndatasets','DigitDataset');
imds = imageDatastore(digitDatasetPath, ...
    'IncludeSubfolders',true, ...
    'LabelSource','foldernames');

データストアには、0 ~ 9 の数字から成る 10,000 個の合成イメージが格納されています。イメージは、さまざまなフォントを使用して作成された数字のイメージにランダム変換を適用して生成されたものです。数字のイメージはそれぞれ 28 x 28 ピクセルです。データストアには、カテゴリごとに同じ数のイメージが含まれます。

データストアのイメージをいくつか表示します。

figure
numImages = 10000;
perm = randperm(numImages,20);
for i = 1:20
    subplot(4,5,i);
    imshow(imds.Files{perm(i)});
    drawnow;
end

Figure contains 20 axes objects. Axes object 1 contains an object of type image. Axes object 2 contains an object of type image. Axes object 3 contains an object of type image. Axes object 4 contains an object of type image. Axes object 5 contains an object of type image. Axes object 6 contains an object of type image. Axes object 7 contains an object of type image. Axes object 8 contains an object of type image. Axes object 9 contains an object of type image. Axes object 10 contains an object of type image. Axes object 11 contains an object of type image. Axes object 12 contains an object of type image. Axes object 13 contains an object of type image. Axes object 14 contains an object of type image. Axes object 15 contains an object of type image. Axes object 16 contains an object of type image. Axes object 17 contains an object of type image. Axes object 18 contains an object of type image. Axes object 19 contains an object of type image. Axes object 20 contains an object of type image.

データストアを分割して、学習セットの各カテゴリに 750 個のイメージが含まれ、テスト セットに各ラベルの残りのイメージが含まれるようにします。

numTrainingFiles = 750;
[imdsTrain,imdsTest] = splitEachLabel(imds,numTrainingFiles, ...
    'randomize');

splitEachLabel は、digitData 内のイメージ ファイルを 2 つの新しいデータストア imdsTrainimdsTest に分割します。

畳み込みニューラル ネットワーク アーキテクチャを定義します。

layers = [ ...
    imageInputLayer([28 28 1])
    convolution2dLayer(5,20)
    reluLayer
    maxPooling2dLayer(2,'Stride',2)
    fullyConnectedLayer(10)
    softmaxLayer
    classificationLayer];

モーメンタム項付き確率的勾配降下法の既定の設定にオプションを設定します。エポックの最大回数を 20 に設定し、初期学習率 0.0001 で学習を開始します。

options = trainingOptions('sgdm', ...
    'MaxEpochs',20,...
    'InitialLearnRate',1e-4, ...
    'Verbose',false, ...
    'Plots','training-progress');

ネットワークに学習をさせます。

net = trainNetwork(imdsTrain,layers,options);

Figure Training Progress (15-Aug-2023 20:45:20) contains 2 axes objects and another object of type uigridlayout. Axes object 1 with xlabel Iteration, ylabel Loss contains 6 objects of type patch, text, line. Axes object 2 with xlabel Iteration, ylabel Accuracy (%) contains 6 objects of type patch, text, line.

ネットワークの学習に使用されなかったテスト セットについて学習済みネットワークを実行し、イメージのラベル (数字) を予測します。

YPred = classify(net,imdsTest);
YTest = imdsTest.Labels;

精度を計算します。精度とは、テスト データ内のイメージの数に対する、classify による分類に一致するテスト データ内の真のラベルの数の比率です。

accuracy = sum(YPred == YTest)/numel(YTest)
accuracy = 0.9416

拡張機能

バージョン履歴

R2016a で導入

すべて折りたたむ

R2024a: 非推奨

R2024a 以降、SeriesNetwork オブジェクトは非推奨となりました。代わりに dlnetwork オブジェクトを使用してください。

SeriesNetwork オブジェクトのサポートを削除する予定はありません。ただし、dlnetwork オブジェクトには次の利点があるため、代わりにこのオブジェクトを使うことを推奨します。

  • dlnetwork オブジェクトは、ネットワークの構築、予測、組み込み学習、可視化、圧縮、検証、およびカスタム学習ループをサポートする統合されたデータ型です。

  • dlnetwork オブジェクトは、ユーザーが作成したり外部のプラットフォームからインポートしたりできる、さまざまなネットワーク アーキテクチャをサポートしています。

  • 関数 trainnetdlnetwork オブジェクトをサポートしているため、損失関数を簡単に指定できます。組み込みの損失関数を選択するか、カスタム損失関数を指定できます。

  • dlnetwork オブジェクトを使用した学習と予測は、通常、LayerGraphtrainNetwork を使用したワークフローよりも高速です。

学習済みの SeriesNetwork オブジェクトを dlnetwork オブジェクトに変換するには、関数 dag2dlnetwork を使用します。

SeriesNetwork オブジェクトの代表的な使用法と、代わりにオブジェクト関数 dlnetwork を使用するためのコードの更新方法を、次の表に示します。

非推奨推奨
Y = predict(net,X);
Y = minibatchpredict(net,X);
Y = classify(net,X);
scores = minibatchpredict(net,X);
Y = scores2label(scores,classNames);
plot(net);
plot(net);
Y = activations(net,X,layerName);
Y = predict(net,X,Outputs=layerName);
[net,Y] = predictAndUpdateState(net,X);
[Y,state] = predict(net,X);
net.State = state;
[net,Y] = classifyAndUpdateState(net,X);
[scores,state] = predict(net,X);
Y = scores2label(scores,classNames);
net.State = state;