主要内容

loadLiteRTModel

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 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
    
    

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

    You must train the model using TensorFlow 2 or Keras 3, and convert it to LiteRT format. loadLiteRTModel does not support loading:

    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