• 【matlab深度学习工具箱】classificationLayer参数详解


    classificationLayer


    分类输出图层

    语法

    layer = classificationLayer
    layer = classificationLayer(Name,Value)
    
    • 1
    • 2

    描述

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

    该层根据前一层的输出大小推断类的数量。例如,要指定网络的类 K 的数量,可以在分类图层之前包括输出大小为 K 的全连接图层和 softmax 图层。

    图层 = 分类图层创建分类图层。

    layer = classificationLayer(Name,Value)` 使用一个或多个名称-值对设置可选的 、 和属性。例如,创建名为 的分类图层。`Name``ClassWeights``Classes``classificationLayer('Name','output')``'output'
    
    • 1

    例子

    创建分类图层

    复制命令复制代码

    创建名为 的分类图层。'output'

    layer = classificationLayer('Name','output')
    layer = 
      ClassificationOutputLayer with properties:
    
                Name: 'output'
             Classes: 'auto'
        ClassWeights: 'none'
          OutputSize: 'auto'
    
       Hyperparameters
        LossFunction: 'crossentropyex'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    数组中包括分类输出图层。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   ''   Convolution             20 5x5 convolutions with stride [1  1] and padding [0  0  0  0]
         3   ''   ReLU                    ReLU
         4   ''   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
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    创建加权分类图层

    复制命令复制代码

    为名称分别为“cat”、“dog”和“fish”的三个类创建加权分类图层,权重分别为 0.7、0.2 和 0.1。

    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'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    在图层数组中包括加权分类输出图层。

    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   ''   Convolution             20 5x5 convolutions with stride [1  1] and padding [0  0  0  0]
         3   ''   ReLU                    ReLU
         4   ''   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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    输入参数

    名称-值参数

    指定可选的逗号分隔参数对。 是参数名称,并且是相应的值。 必须出现在引号内。可以按任意顺序指定多个名称和值对参数,如 。Name,Value``Name``Value``Name``Name1,Value1,...,NameN,ValueN

    示例:分类层(“名称”、“输出”)创建一个名为“输出”的分类图层

    Name— 图层名称 " "(默认)|字符向量|字符串标量

    图层名称,指定为字符向量或字符串标量。对于 Layer 数组输入,trainNetworkassembleNetworklayerGraphdlnetwork 函数会自动为 Name 设置为 '' 的层分配名称

    数据类型: char|string

    ClassWeights— 加权交叉熵损失 "none"(默认值)的类权重|正数向量

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

    对于矢量类权重,每个元素表示属性中相应类的权重。若要指定类权重的向量,还必须使用“Classes”指定类。Classes

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

    Classes— 输出层 的类"auto"(默认)|分类向量|字符串数组 |字符向量的单元格数组

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

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

    输出参数

    layer— 分类层 分类输出层对象

    分类层,作为 ClassificationOutputLayer 对象返回。

  • 相关阅读:
    C#/WPF/.NET 找到的程序集清单定义与程序集引用不匹配
    python最常用的三种输出格式
    华为服务器安装操作系统
    Java笔试复盘
    【Docker】搭建 Docker 镜像仓库
    Learn How Long Does It Take To Learn C++ From Starting
    SpringCloud学习笔记 - 服务调用、负载均衡组件 - ribbon
    最高薪15k!“转行软件测试后,我想要的生活,就应该是这样!”
    Nacos Client 端服务注册流程源码分析
    day43 数据库
  • 原文地址:https://blog.csdn.net/weixin_47370211/article/details/125381065