Main Content

loadLiteRTModel

R2026b

Load pretrained LiteRT model file

Since R2026a

    Description

    Add-On Required: This feature requires the MATLAB Coder Support Package for PyTorch and LiteRT Models add-on.

    model = loadLiteRTModel(modelFileName) loads a pretrained LiteRT model file.

    example

    model = loadLiteRTModel(modelFileName,ExecutionMode=ExecutionMode) loads a pretrained LiteRT model file using the specified execution mode.

    example

    Examples

    collapse all

    Suppose that you have a LiteRT model named siso.tflite that takes one input and returns one output. Create a LiteRTModel object.

    myModel = loadLiteRTModel("siso.tflite")
    Loading model...
    Model loaded.
    
    myModel = 
      LiteRTModel contained in siso.tflite: 
    
                              Input Specifications                       
        _________________________________________________________________
    
        Input     Name                    Size                     Type  
        _____    _______    _________________________________    ________
                                                                         
          1      "image"    "<variable-size> x 128 x 128 x 3"    "single"
    
    
                          Output Specifications                  
        _________________________________________________________
    
        Output       Name               Size               Type  
        ______    __________    _____________________    ________
                                                                 
          1       "output_0"    "<variable-size> x 1"    "single"
    
    
        properties: 
            ModelPath                         -      Path to the model file
            FcnNames                          -      Names of the functions in the model
        methods: 
            invoke                            -      Performs forward inference by invoking a function in the model
            inputSpecifications               -      Returns the input specifications of the model or of a specific function in the model
            outputSpecifications              -      Returns the output specifications of the model or of a specific function in the model
            summary                           -      Displays the input and output specifications of the model or of a specific function in the model
    
    

    Suppose that you have a LiteRT model named mimo.tflite that takes multiple inputs and returns multiple outputs.

    Create a LiteRTModel object by using the MEX execution mode. To use the MEX execution mode, you must install a supported C compiler. For more information about setting up the C/C++ compiler, see Installing and Configuring Prerequisite Products.

    myModel = loadLiteRTModel("mimo.tflite",ExecutionMode="MEX")
    Loading model...
    Model loaded.
    
    myModel = 
      LiteRTModel contained in mimo.tflite: 
    
                           Input Specifications                    
        ___________________________________________________________
    
        Input        Name                 Size               Type  
        _____    ____________    ______________________    ________
                                                                   
          1      "features_a"    "<variable-size> x 16"    "single"
          2      "features_b"    "<variable-size> x 8"     "single"
    
    
                          Output Specifications                  
        _________________________________________________________
    
        Output       Name               Size               Type  
        ______    __________    _____________________    ________
                                                                 
          1       "output_1"    "<variable-size> x 2"    "single"
          2       "output_0"    "<variable-size> x 4"    "single"
    
    
        properties: 
            ModelPath                         -      Path to the model file
            FcnNames                          -      Names of the functions in the model
        methods: 
            invoke                            -      Performs forward inference by invoking a function in the model
            inputSpecifications               -      Returns the input specifications of the model or of a specific function in the model
            outputSpecifications              -      Returns the output specifications of the model or of a specific function in the model
            summary                           -      Displays the input and output specifications of the model or of a specific function in the model
    
    

    Input Arguments

    collapse all

    Name of the LiteRT model file, specified as a character vector or a scalar string.

    Example: "myModelName"

    Example: "myfolder/myModelName"

    Execution mode to use for MATLAB simulation behavior, specified as "JIT" or "MEX".

    JIT code is incompatible with the OpenMP application interface. JIT execution mode does not support multi-threading. If you want to parallelize for-loops, use MEX execution mode. You must install a supported C compiler to use the MEX execution mode. For more information about setting up the C/C++ compiler, see Installing and Configuring Prerequisite Products.

    Output Arguments

    collapse all

    LiteRT model, returned as a LiteRTModel object.

    Limitations

    The code generator might apply optimizations that assume the absence of NaN values, which can affect NaN propagation behavior. If model inputs contain NaN values, generated code might produce different results from the reference framework.

    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 R2026a