主要内容

LiteRTModel

LiteRT model

Since R2026a

    Description

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

    You can use LiteRTModel objects to execute the model or to generate code in MATLAB® or Simulink®.

    Creation

    Create a LiteRTModel object by using the loadLiteRTModel function.

    Properties

    expand all

    Model path, specified as a character vector.

    Function names, specified as a cell array of character vectors.

    Object Functions

    summaryDisplay input and output specifications of PyTorch ExportedProgram or LiteRT model
    inputSpecificationsReturn input specifications for functions in PyTorch ExportedProgam or LiteRT model
    outputSpecificationsReturn output specifications for functions in PyTorch ExportedProgram or LiteRT model
    invokeRun inference on a PyTorch ExportedProgram or LiteRT model input to compute output

    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 the model. This may take a few minutes.
    
    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
    
    

    Limitations

    You cannot save the LiteRTModel object from workspace to a MAT-file.

    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