主要内容

ClassificationOutputLayer

(不推荐)分类输出层

不推荐使用 ClassificationOutputLayer 对象。请改用 trainnet 函数,并将损失函数设置为 "crossentropy"。有关详细信息,请参阅版本历史记录

说明

分类层计算具有互斥类的分类和加权分类任务的交叉熵损失。

创建对象

使用 classificationLayer 创建一个分类层。

属性

全部展开

分类输出

加权交叉熵损失的类权重,指定为正数向量或 'none'

对于向量类权重,每个元素都表示 Classes 属性中对应类的权重。要指定类权重的向量,还必须使用 Classes 选项指定类。

如果 ClassWeights 属性为 'none',则该层应用未加权交叉熵损失。

输出层的类,指定为分类向量、字符串数组、字符向量元胞数组或 "auto"。如果 Classes"auto",则软件会在训练时自动设置类。如果您指定字符串数组或字符向量元胞数组 str,则软件会将输出层的类设置为 categorical(str,str)

数据类型: char | categorical | string | cell

此 属性 为只读。

输出的大小,指定为正整数。此值是数据中的标签数量。在训练之前,输出大小设置为 'auto'

此 属性 为只读。

用于训练的损失函数,指定为 'crossentropyex',即适用于 k 个互斥类的交叉熵函数

层名称,指定为字符向量或字符串标量。对于 Layer 数组输入,trainNetwork 函数会自动为层指定名称 ""

ClassificationOutputLayer 对象将此属性存储为字符向量。

数据类型: char | string

层的输入数,返回为 1。此层只接受一个输入。

数据类型: double

输入名称,返回为 {'in'}。此层只接受一个输入。

数据类型: cell

层的输出的数目,以 0 形式返回。此层没有输出。

数据类型: double

层的输出的名称,以 {} 形式返回。此层没有输出。

数据类型: 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

详细信息

全部展开

参考

[1] Bishop, C. M. Pattern Recognition and Machine Learning. Springer, New York, NY, 2006.

版本历史记录

在 R2016a 中推出

全部展开