Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

SeriesNetwork

深層学習用の系列ネットワーク

説明

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

作成

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

メモ

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

プロパティ

すべて展開する

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

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

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

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

データ型: cell

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

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

データ型: cell

オブジェクト関数

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

すべて折りたたむ

事前学習済みの AlexNet 畳み込みニューラル ネットワークを読み込み、層およびクラスを確認します。

alexnet を使用して事前学習済みの AlexNet ネットワークを読み込みます。出力 netSeriesNetwork オブジェクトです。

net = alexnet
net = 
  SeriesNetwork with properties:

    Layers: [25×1 nnet.cnn.layer.Layer]

Layers プロパティを使用して、ネットワーク アーキテクチャを表示します。このネットワークは 25 個の層で構成されています。学習可能な重みをもつ 8 個の層があります。そのうち 5 個が畳み込み層で、3 個が全結合層です。

net.Layers
ans = 
  25x1 Layer array with layers:

     1   'data'     Image Input                   227x227x3 images with 'zerocenter' normalization
     2   'conv1'    Convolution                   96 11x11x3 convolutions with stride [4  4] and padding [0  0  0  0]
     3   'relu1'    ReLU                          ReLU
     4   'norm1'    Cross Channel Normalization   cross channel normalization with 5 channels per element
     5   'pool1'    Max Pooling                   3x3 max pooling with stride [2  2] and padding [0  0  0  0]
     6   'conv2'    Grouped Convolution           2 groups of 128 5x5x48 convolutions with stride [1  1] and padding [2  2  2  2]
     7   'relu2'    ReLU                          ReLU
     8   'norm2'    Cross Channel Normalization   cross channel normalization with 5 channels per element
     9   'pool2'    Max Pooling                   3x3 max pooling with stride [2  2] and padding [0  0  0  0]
    10   'conv3'    Convolution                   384 3x3x256 convolutions with stride [1  1] and padding [1  1  1  1]
    11   'relu3'    ReLU                          ReLU
    12   'conv4'    Grouped Convolution           2 groups of 192 3x3x192 convolutions with stride [1  1] and padding [1  1  1  1]
    13   'relu4'    ReLU                          ReLU
    14   'conv5'    Grouped Convolution           2 groups of 128 3x3x192 convolutions with stride [1  1] and padding [1  1  1  1]
    15   'relu5'    ReLU                          ReLU
    16   'pool5'    Max Pooling                   3x3 max pooling with stride [2  2] and padding [0  0  0  0]
    17   'fc6'      Fully Connected               4096 fully connected layer
    18   'relu6'    ReLU                          ReLU
    19   'drop6'    Dropout                       50% dropout
    20   'fc7'      Fully Connected               4096 fully connected layer
    21   'relu7'    ReLU                          ReLU
    22   'drop7'    Dropout                       50% dropout
    23   'fc8'      Fully Connected               1000 fully connected layer
    24   'prob'     Softmax                       softmax
    25   'output'   Classification Output         crossentropyex with 'tench' and 999 other classes

分類出力層 (最後の層) の Classes プロパティを表示すると、ネットワークによって学習済みのクラスの名前を確認できます。最初の 10 個の要素を選択することによって、最初の 10 個のクラスを表示します。

net.Layers(end).Classes(1:10)
ans = 10×1 categorical array
     tench 
     goldfish 
     great white shark 
     tiger shark 
     hammerhead 
     electric ray 
     stingray 
     cock 
     hen 
     ostrich 

インポートする例ファイル 'digitsnet.prototxt' を指定します。

protofile = 'digitsnet.prototxt';

ネットワーク層をインポートします。

layers = importCaffeLayers(protofile)
layers = 

  1x7 Layer array with layers:

     1   'testdata'   Image Input             28x28x1 images
     2   'conv1'      Convolution             20 5x5x1 convolutions with stride [1  1] and padding [0  0]
     3   'relu1'      ReLU                    ReLU
     4   'pool1'      Max Pooling             2x2 max pooling with stride [2  2] and padding [0  0]
     5   'ip1'        Fully Connected         10 fully connected layer
     6   'loss'       Softmax                 softmax
     7   'output'     Classification Output   crossentropyex with 'class1', 'class2', and 8 other classes

データを 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 (29-Aug-2023 21:23:47) 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.9412

拡張機能

バージョン履歴

R2016a で導入