Main Content

coder.ai.enableParameterUpdate

Enables run-time update of network parameters

Since R2025a

    Description

    updatedNet = coder.ai.enableParameterUpdate(net) enables updating learnables at run time, without the need to regenerate code. For more information, see Update Network Parameters at Run Time.

    MATLAB ignores the coder.ai.enableParameterUpdate directive outside of code generation.

    example

    Examples

    collapse all

    This example shows how to create an entry-point function named mPredict that continuously updates the learnables of a deep learning network.

    The function:

    1. Loads the trained network into a persistent dlnetwork object named dlnet by using the coder.loadDeepLearningNetwork function. A persistent variable allows you to preserve the updated learnables for subsequent function calls.

    2. Enables run-time update of learnables by using the coder.ai.enableParameterUpdate function. You must enable the learnables update of the dlnetwork object before updating the learnable parameters.

    3. Updates the learnable parameters with the variable newLearnables.

    4. Calls the predict method to predict the responses by using the updated network.

    function dlOut = mPredict(dlIn, newLearnables, matfile)
    %#codegen
    
    persistent dlnet
    
    if isempty(dlnet)
      dlnet = coder.loadDeepLearningNetwork(matfile);
    end
    
    % Enables learnables update
    dlnet = coder.ai.enableParameterUpdate(dlnet);
    
    % Update learnables
    dlnet.Learnables = newLearnables;
    
    dlOut = dlnet.predict(dlIn);
    end

    Input Arguments

    collapse all

    Input network, specified as a dlnetwork object.

    Output Arguments

    collapse all

    Updated network, specified as a dlnetwork object.

    Extended Capabilities

    expand all

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    GPU Code Generation
    Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

    Version History

    Introduced in R2025a