Main Content


Class: dlhdl.ProcessorConfig
Package: dlhdl

Register the custom layer definition and Simulink model representation of the custom layer

Since R2022a


registerCustomLayer(processorConfigObject, 'Layer', Layer, 'Model', Model)


registerCustomLayer(processorConfigObject, 'Layer', Layer, 'Model', Model) registers a custom layer specified by the Layer argument and the Simulink® model representation of the custom layer, specified by the Model argument.

Input Arguments

expand all

Processor configuration, specified as a dlhdl.ProcessorConfig object.

Class definition of the custom layer object, specified as an nnet.layer.Layer object.

Example: Layer = hSig

Simulink model representing the custom layer, specified as a file name of the Simulink model on the MATLAB® path or absolute or relative path to the Simulink model.

Example: Model = 'myfile.slx'

Example: Model = 'C:\myfolder\myfile.slx'


expand all

  1. Create a function that represents the custom signum layer. Save the function definition as SignumLayer.m.

    classdef SignumLayer < nnet.layer.Layer
        % Example custom Signum layer.
            testPropertyValue1 single = 3;
            testPropertyValue2 single = 4;
            function layer = SignumLayer(name)
                % Set layer name.
                layer.Name = name;
                % Set layer description.
                layer.Description = "custom signum layer";
            function Z = predict(layer, X)
                % Z = predict(layer, X) forwards the input data X through the
                % layer and outputs the result Z.
                Z = sign(X) + layer.testPropertyValue1 + layer.testPropertyValue2;

  2. Create a variable hSig. Assign the custom signum layer function definition to hSig.

    hSig = SignumLayer('sLayer');

  3. Create a Simulink model that represents the custom signum layer. Save the Simulink model as SignumLayer.slx.

  4. Create a custom deep learning processor configuration object by using the dlhdl.ProcessorConfig class. Save the custom deep learning processor configuration as hPC.

    hPC = dlhdl.ProcessorConfig;

  5. Use the registerCustomLayer method to register the custom signum layer definition and Simulink model.

    % If the Simulink model is on the MATLAB path, use:
    hPC.registerCustomLayer(Layer = hSig, Model = 'SignumLayer.slx');
    % If the Simulink model is in a folder called myLayers on your C drive, use:
    %   hPC.registerCustomLayer( Layer = hSig, Model = 'C:\myLayers\SignumLayer.slx');

Version History

Introduced in R2022a