# 用选定的 delegate 准备一个模型

Source: [https://docs.qualcomm.com/doc/80-70014-54Y/topic/prepare-a-model-with-a-chosen-delegate.html](https://docs.qualcomm.com/doc/80-70014-54Y/topic/prepare-a-model-with-a-chosen-delegate.html)

创建解析器并分配运行模型所需的内存后，使用选定的 delegate 准备模型。此步骤从之前加载的模型创建执行图，并使用底层库在 delegate 硬件上执行推理。

以下示例代码创建 XNNPACK Delegate，用于在 Arm CPU 上运行 TensorFlow Lite 模型。通过调用 `TfLiteXNNPackDelegateCreate(…)` API 创建 delegate。还可使用 Delegate Options API 定制 delegate。

    TfLiteDelegate *delegate = NULL;
    TfLiteXNNPackDelegateOptions xnnpack_options =
    TfLiteXNNPackDelegateOptionsDefault();
    xnnpack_options.num_threads = num_threads;
      
    TfLiteDelegate* xnnpack_delegate =
    TfLiteXNNPackDelegateCreate(&xnnpack_options);
    if (interpreter->ModifyGraphWithDelegate(xnnpack_delegate) != kTfLiteOk) {
      // Report error and fall back to another delegate, or the default backend
    }
    Copy to clipboard

**Parent Topic:** [运行推理](https://docs.qualcomm.com/doc/80-70014-54Y/topic/run-inference.html)

Last Published: Aug 06, 2024

[Previous Topic
创建 TensorFlow Lite 解析器](https://docs.qualcomm.com/bundle/publicresource/80-70014-54Y/topics/create-a-tensorflow-lite-interpreter.md) [Next Topic
准备输入/输出缓冲区](https://docs.qualcomm.com/bundle/publicresource/80-70014-54Y/topics/prepare-input-output-buffers.md)