ClassificationOutputLayer
説明
分類層は、互いに排他的なクラスをもつ分類タスクおよび重み付き分類タスクの交差エントロピー損失を計算します。
作成
分類層は classificationLayer
を使用して作成します。
プロパティ
分類出力
ClassWeights
— 交差エントロピー損失のクラスの重み
'none'
(既定値) | 正の数値のベクトル
交差エントロピー損失のクラスの重み。正の数値のベクトルまたは 'none'
として指定します。
クラスの重みをベクトルで指定した場合、各要素は、Classes
プロパティで該当するクラスの重みを表します。クラスの重みのベクトルを指定するには、'Classes'
を使用してクラスも指定しなければなりません。
ClassWeights
プロパティが 'none'
の場合は、重みなしの交差エントロピー損失が層に適用されます。
Classes
— 出力層のクラス
"auto"
(既定値) | categorical ベクトル | string 配列 | 文字ベクトルの cell 配列
出力層のクラス。categorical ベクトル、string 配列、文字ベクトルの cell 配列、または "auto"
として指定します。Classes
が "auto"
の場合、学習時にクラスが自動的に設定されます。string 配列または文字ベクトルの cell 配列 str
を指定すると、出力層のクラスが categorical(str,str)
に設定されます。
データ型: char
| categorical
| string
| cell
OutputSize
— 出力のサイズ
'auto'
(既定値) | 正の整数
この プロパティ は読み取り専用です。
出力のサイズ。正の整数として指定します。この値は、データに含まれるラベルの数です。学習前に、出力サイズが 'auto'
に設定されます。
LossFunction
— 学習用の損失関数
'crossentropyex'
この プロパティ は読み取り専用です。
学習用の損失関数。"k 個の互いに排他的なクラスの交差エントロピー関数" を意味する 'crossentropyex'
として指定します。
層
Name
— 層の名前
""
(既定値) | 文字ベクトル | string スカラー
層の名前。文字ベクトルまたは string スカラーとして指定します。Layer
配列入力の場合、関数 trainnet
、trainNetwork
、assembleNetwork
、layerGraph
、および dlnetwork
は、名前が ""
の層に自動的に名前を割り当てます。
ClassificationOutputLayer
オブジェクトは、このプロパティを文字ベクトルとして格納します。
データ型: char
| string
NumInputs
— 入力の数
1
(既定値)
この プロパティ は読み取り専用です。
層への入力の数。1
として返されます。この層は単一の入力のみを受け入れます。
データ型: double
InputNames
— 入力名
{'in'}
(既定値)
この プロパティ は読み取り専用です。
入力名。{'in'}
として返されます。この層は単一の入力のみを受け入れます。
データ型: cell
NumOutputs
— 出力の数
0 (既定値)
層の出力の数。この層には出力がありません。
データ型: double
OutputNames
— 出力名
{}
(既定値)
層の出力名。この層には出力がありません。
データ型: cell
例
分類層の作成
'output'
という名前の分類層を作成します。
layer = classificationLayer('Name','output')
layer = ClassificationOutputLayer with properties: Name: 'output' Classes: 'auto' ClassWeights: 'none' OutputSize: 'auto' Hyperparameters LossFunction: 'crossentropyex'
Layer
配列に分類出力層を含めます。
layers = [ ... imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer maxPooling2dLayer(2,'Stride',2) fullyConnectedLayer(10) softmaxLayer classificationLayer]
layers = 7x1 Layer array with layers: 1 '' Image Input 28x28x1 images with 'zerocenter' normalization 2 '' 2-D Convolution 20 5x5 convolutions with stride [1 1] and padding [0 0 0 0] 3 '' ReLU ReLU 4 '' 2-D Max Pooling 2x2 max pooling with stride [2 2] and padding [0 0 0 0] 5 '' Fully Connected 10 fully connected layer 6 '' Softmax softmax 7 '' Classification Output crossentropyex
重み付き分類層の作成
"cat"、"dog"、"fish" という名前をもち、重みがそれぞれ 0.7、0.2、0.1 である 3 つのクラスに対する重み付き分類層を作成します。
classes = ["cat" "dog" "fish"]; classWeights = [0.7 0.2 0.1]; layer = classificationLayer( ... 'Classes',classes, ... 'ClassWeights',classWeights)
layer = ClassificationOutputLayer with properties: Name: '' Classes: [cat dog fish] ClassWeights: [3x1 double] OutputSize: 3 Hyperparameters LossFunction: 'crossentropyex'
Layer 配列に重み付き分類出力層を含めます。
numClasses = numel(classes); layers = [ ... imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer maxPooling2dLayer(2,'Stride',2) fullyConnectedLayer(numClasses) softmaxLayer classificationLayer('Classes',classes,'ClassWeights',classWeights)]
layers = 7x1 Layer array with layers: 1 '' Image Input 28x28x1 images with 'zerocenter' normalization 2 '' 2-D Convolution 20 5x5 convolutions with stride [1 1] and padding [0 0 0 0] 3 '' ReLU ReLU 4 '' 2-D Max Pooling 2x2 max pooling with stride [2 2] and padding [0 0 0 0] 5 '' Fully Connected 3 fully connected layer 6 '' Softmax softmax 7 '' Classification Output Class weighted crossentropyex with 'cat' and 2 other classes
詳細
分類出力層
分類層は、互いに排他的なクラスをもつ分類タスクおよび重み付き分類タスクの交差エントロピー損失を計算します。
一般的な分類ネットワークでは、通常、分類層がソフトマックス層の後に続きます。分類層では、trainNetwork
がソフトマックス関数から値を取得し、1 対 K 符号化方式の交差エントロピー関数を使用して、K 個の互いに排他的なクラスのうちの 1 つに各入力を割り当てます[1]。
ここで、N は標本の数、K はクラスの数、 はクラス i の重み、 は n 番目の標本が i 番目のクラスに属することを表すインジケーターです。 はクラス i の標本 n の出力で、この場合はソフトマックス関数からの値です。つまり、 は、ネットワークが n 番目の入力をクラス i に関連付ける確率です。
参照
[1] Bishop, C. M. Pattern Recognition and Machine Learning. Springer, New York, NY, 2006.
バージョン履歴
R2016a で導入R2018b: ClassNames
プロパティは削除予定
ClassNames
は削除される予定です。代わりに Classes
を使用してください。コードを更新するには、ClassNames
のすべてのインスタンスを Classes
に置き換えます。プロパティの間に多少の違いがある場合は、コードをさらに更新する必要があります。
出力層の ClassNames
プロパティは文字ベクトルの cell 配列です。Classes
プロパティは categorical 配列です。cell 配列入力を必要とする関数に Classes
の値を使用するには、関数 cellstr
を使用してクラスを変換します。
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)