このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
SeriesNetwork
深層学習用の系列ネットワーク
説明
系列ネットワークは、層が 1 つずつ連続して配置された深層学習用のニューラル ネットワークです。これには、1 つの入力層と 1 つの出力層があります。
作成
SeriesNetwork
オブジェクトは、次のようにいくつかの方法で作成できます。
alexnet
、darknet19
、vgg16
、またはvgg19
を使用して、事前学習済みのネットワークを読み込む。例については、事前学習済み AlexNet 畳み込みニューラル ネットワークの読み込みを参照してください。trainNetwork
を使用して、ネットワークの学習または微調整を行う。例については、イメージ分類についてのネットワークの学習を参照してください。関数
assembleNetwork
を使用して、事前学習済みの層から深層学習ネットワークを組み立てる。
メモ
googlenet
、resnet50
など、他の事前学習済みのネットワークについては、事前学習済みの深層ニューラル ネットワークを参照してください。
プロパティ
Layers
— ネットワーク層
Layer
配列
この プロパティ は読み取り専用です。
ネットワーク層。Layer
配列として指定します。
InputNames
— 入力層の名前
文字ベクトルの cell 配列
この プロパティ は読み取り専用です。
入力層の名前。文字ベクトルの cell 配列として指定します。
データ型: cell
OutputNames
— 出力層の名前
cell 配列
この プロパティ は読み取り専用です。
出力層の名前。文字ベクトルの cell 配列として指定します。
データ型: cell
オブジェクト関数
activations | 深層学習ネットワーク層の活性化の計算 |
classify | 学習済み深層学習ニューラル ネットワークを使用したデータの分類 |
predict | 学習済み深層学習ニューラル ネットワークを使用した応答の予測 |
predictAndUpdateState | 学習済み再帰型ニューラル ネットワークを使用した応答の予測とネットワーク状態の更新 |
classifyAndUpdateState | 学習済み再帰型ニューラル ネットワークを使用したデータの分類とネットワーク状態の更新 |
resetState | ニューラル ネットワークの状態パラメーターのリセット |
plot | ニューラル ネットワーク アーキテクチャのプロット |
例
事前学習済み AlexNet 畳み込みニューラル ネットワークの読み込み
事前学習済みの AlexNet 畳み込みニューラル ネットワークを読み込み、層およびクラスを確認します。
alexnet
を使用して事前学習済みの AlexNet ネットワークを読み込みます。出力 net
は SeriesNetwork
オブジェクトです。
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
Caffe ネットワークからの層のインポート
インポートする例ファイル '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
データストアを分割して、学習セットの各カテゴリに 750 個のイメージが含まれ、テスト セットに各ラベルの残りのイメージが含まれるようにします。
numTrainingFiles = 750;
[imdsTrain,imdsTest] = splitEachLabel(imds,numTrainingFiles,'randomize');
splitEachLabel
は、digitData
内のイメージ ファイルを 2 つの新しいデータストア imdsTrain
と imdsTest
に分割します。
畳み込みニューラル ネットワーク アーキテクチャを定義します。
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);
ネットワークの学習に使用されなかったテスト セットについて学習済みネットワークを実行し、イメージのラベル (数字) を予測します。
YPred = classify(net,imdsTest); YTest = imdsTest.Labels;
精度を計算します。精度とは、テスト データ内のイメージの数に対する、classify
による分類に一致するテスト データ内の真のラベルの数の比率です。
accuracy = sum(YPred == YTest)/numel(YTest)
accuracy = 0.9412
拡張機能
C/C++ コード生成
MATLAB® Coder™ を使用して C および C++ コードを生成します。
使用上の注意および制限:
オブジェクト関数
activations
、classify
、predict
、predictAndUpdateState
、classifyAndUpdateState
、およびresetState
のみがサポートされます。コード生成用の
SeriesNetwork
オブジェクトを作成するには、コード生成のための事前学習済みネットワークの読み込み (MATLAB Coder)を参照してください。
GPU コード生成
GPU Coder™ を使用して NVIDIA® GPU のための CUDA® コードを生成します。
使用上の注意および制限:
オブジェクト関数
activations
、classify
、predict
、predictAndUpdateState
、classifyAndUpdateState
、およびresetState
のみがサポートされます。コード生成用の
SeriesNetwork
オブジェクトを作成するには、コード生成用の事前学習済みのネットワークの読み込み (GPU Coder)を参照してください。
バージョン履歴
R2016a で導入
参考
alexnet
| vgg16
| vgg19
| darknet19
| importCaffeNetwork
| trainNetwork
| trainingOptions
| DAGNetwork
| analyzeNetwork
| assembleNetwork
| plot
| classify
| predict
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)