主要内容

删除参数

Remove parameter fromONNXParametersobject

    描述

    example

    params = removeParameter(params,name)删除由name来自ONNXParametersobjectparams

    例子

    collapse all

    导入以ONNX格式保存的网络作为函数,并修改网络参数。

    进口预处理simplenet3fc.onnxnetwork as a function.simplenet3fc是一个简单的卷积神经网络,该神经网络对数字图像数据进行了训练。有关如何创建类似于类似的网络的更多信息simplenet3fc, seeCreate Simple Image Classification Network

    Importsimplenet3fc.onnxusingimportONNXFunction, which returns anONNXParametersobject that contains the network parameters. The function also creates a new model function in the current folder that contains the network architecture. Specify the name of the model function asSimpleEnetFCN

    params = importONNXFunction('SimpleNet3fc.onnx','simplenetFcn');
    A function containing the imported ONNX network has been saved to the file simplenetFcn.m. To learn how to use this function, type: help simplenetFcn.

    Display the parameters that are updated during training (params.learnables) and the parameters that remain unchanged during training (params.Nonlearnables).

    params.learnables
    ans =带有字段的结构:imageInput_mean:[1×1 dlarray] conv_w:[5×5×1×20 dlarray] conv_b:[20×1 dlarray] batchnorm_scale:[20×1 dlarray] batchnorm_b:[20×1 dlarray] fc_1_w:[24×24×24×20×20 dlarray] fc_1_b:[20×1 dlarray] fc_2_w:[1×1×1×20×20 dlarray] fc_2_b:[20×1 dlarray] fc_3_w:[1×1×1×1×20×10×10×10 dlarray]×1 dlarray]
    params.Nonlearnables
    ans =带有字段的结构:ConvStride1004: [2×1 dlarray] ConvDilationFactor1005: [2×1 dlarray] ConvPadding1006: [4×1 dlarray] ConvStride1007: [2×1 dlarray] ConvDilationFactor1008: [2×1 dlarray] ConvPadding1009: [4×1 dlarray] ConvStride1010:[2×1 dlarray] ConvdilationFactor1011:[2×1 dlarray] Convpadding1012:[4×1 dlarray] Convstride1013:[2×1 dlarray] ConvdilationFactor1014:[2×1 Dlarray] Corvpadding1015:[4×1 Dlarray:[4×1 Dlarray]

    The network has parameters that represent three fully connected layers. To see the parameters of the convolutional layersfc_1,fc_2, 和fc_3, open the model functionSimpleEnetFCN

    openSimpleEnetFCN

    向下滚动到功能中的图层定义SimpleEnetFCN。下面的代码显示了层的定义fc_1,fc_2, 和fc_3

    % Conv:[weights, bias, stride, dilationFactor, padding, dataFormat, NumDims.fc_1] = prepareConvArgs(Vars.fc_1_W, Vars.fc_1_B, Vars.ConvStride1007, Vars.ConvDilationFactor1008, Vars.ConvPadding1009, 1, NumDims.relu1001, NumDims.fc_1_W); Vars.fc_1 = dlconv(Vars.relu1001, weights, bias,'Stride',大步“扩张量”, dilationFactor,'Padding', padding,“ dataformat',dataformat);% Conv:[weights, bias, stride, dilationFactor, padding, dataFormat, NumDims.fc_2] = prepareConvArgs(Vars.fc_2_W, Vars.fc_2_B, Vars.ConvStride1010, Vars.ConvDilationFactor1011, Vars.ConvPadding1012, 1, NumDims.fc_1, NumDims.fc_2_W);vars.fc_2 = dlconv(vars.fc_1,striges,bias,'Stride',大步“扩张量”, dilationFactor,'Padding', padding,“ dataformat',dataformat);% Conv:[权重,偏见,大步,扩张量,填充,填充,dataFormat,numdims.fc_3] = PrepareConvargs(vars.fc_3_w,vars.fc_3_b,vars.convstride1013,vars.convdilationfactor1014;Vars.fc_3 = dlconv(Vars.fc_2, weights, bias,'Stride',大步“扩张量”, dilationFactor,'Padding', padding,“ dataformat',dataformat);

    You can remove the parameters of the fully connected layerfc_2降低计算复杂性。检查上一层的输出尺寸和后续层的输入维度params。In this case, the output size of the previous layerfc_1为20,后续层的输入大小fc_3也是20。

    Remove the parameters of layerfc_2通过使用删除参数

    params = removeParameter(params,'fc_2_B'); params = removeParameter(params,'fc_2_w'); params = removeParameter(params,'ConvStride1010'); params = removeParameter(params,'ConvDilationFactor1011'); params = removeParameter(params,'ConvPadding1012');

    Display the updated learnable and nonlearnable parameters.

    params.learnables
    ans =带有字段的结构:imageInput_mean:[1×1 dlarray] conv_w:[5×5×1×20 dlarray] conv_b:[20×1 dlarray] batchnorm_scale:[20×1 dlarray] batchnorm_b:[20×1 dlarray] fc_1_w:[24×24×24×20×20 dlarray] fc_1_b:[20×1 dlarray] fc_3_w:[1×1×1×20×10 dlarray] fc_3_b:[10×1 dlarray]
    params.Nonlearnables
    ans =带有字段的结构:ConvStride1004: [2×1 dlarray] ConvDilationFactor1005: [2×1 dlarray] ConvPadding1006: [4×1 dlarray] ConvStride1007: [2×1 dlarray] ConvDilationFactor1008: [2×1 dlarray] ConvPadding1009: [4×1 dlarray] ConvStride1013: [2×1 dlarray] ConvDilationFactor1014: [2×1 dlarray] ConvPadding1015: [4×1 dlarray]

    Modify the architecture of the model function to reflect the changes inparamsso you can use the network for prediction with the new parameters or retrain the network. Open the model functionSimpleEnetFCN。Then, remove the fully connected layerfc_2, 和change the input data of the convolution operationDLCONVfor layerfc_3tovars.fc_1

    openSimpleEnetFCN

    The code below shows layersfc_1fc_3

    % Conv:[weights, bias, stride, dilationFactor, padding, dataFormat, NumDims.fc_1] = prepareConvArgs(Vars.fc_1_W, Vars.fc_1_B, Vars.ConvStride1007, Vars.ConvDilationFactor1008, Vars.ConvPadding1009, 1, NumDims.relu1001, NumDims.fc_1_W); Vars.fc_1 = dlconv(Vars.relu1001, weights, bias,'Stride',大步“扩张量”, dilationFactor,'Padding', padding,“ dataformat',dataformat);% Conv:[权重,偏见,大步,扩张量,填充,填充,dataFormat,numdims.fc_3] = PrepareConvargs(vars.fc_3_w,vars.fc_3_b,vars.convstride1013,vars.convdilationfactor1014;vars.fc_3 = dlconv(vars.fc_1,striges,bias,'Stride',大步“扩张量”, dilationFactor,'Padding', padding,“ dataformat',dataformat);

    Input Arguments

    collapse all

    网络参数, specified as anONNXParameters目的。paramscontains the network parameters of the imported ONNX™ model.

    Name of the parameter, specified as a character vector or string scalar.

    例子:'conv2_W'

    例子:'conv2_Padding'

    Output Arguments

    collapse all

    网络参数, returned as anONNXParameters目的。paramscontains the network parameters updated by删除参数

    Version History

    Introduced in R2020b