# 執行含自訂訓練模型的範例應用程式

使用自訂訓練的 YoloV8 模型作為範例。

前置條件

1. 設定可擴充 SDK (eSDK) 以開發應用程式/外掛程式碼。

    請參閱 [Qualcomm 智慧多媒體軟體開發套件 (IM SDK) 快速入門指南](https://docs.qualcomm.com/bundle/publicresource/topics/80-70020-51/introduction.html) 以瞭解如何設定 eSDK 以及下載和編譯原始碼。
2. 有關下載原始程式碼及編譯自訂參考應用程式的說明，請參閱 [開發自己的 AI/ML 應用程式](https://docs.qualcomm.com/doc/80-70020-15BT/topic/develop-your-own-application.html)。
3. [下載用於 Qualcomm 神經處理 SDK 的模型及標籤檔案](https://docs.qualcomm.com/doc/80-70020-15BT/topic/classify-objects-with-default-model.html#download-model-files)。

## 使用自訂訓練的 YoloV8 LiteRT 模型

Qualcomm IM SDK 參考應用程式使用 YoloV8 模型進行物件偵測。此範例說明如何嘗試自訂訓練的 YoloV8 變體。

使用以下步驟，執行您自訂訓練的 YoloV8 模型，並搭配當前的參考應用程式。

1. 在參考應用程式中，將現有模型替換為新的自訂模型。
2. 使用自訂標籤更新標籤檔案內容。
3. 使用修改後的模型和標籤檔執行參考應用程式。

### 修改標籤

使用 Qualcomm IM SDK 及其參考應用程式時，應用程式要求特定格式的標籤。必須在此標籤檔案中更新各個標籤的 `<label_name>` 、 `<hex_value_for_label_id>` 和 `<hex_value_for_color>` 值。

每個標籤在標籤檔案中的格式應遵循以下範例模板。

(structure)"<label_name>,id=(guint)<hex_value_for_label_id>,color=(guint)<hex_value_for_color>;"
    Copy to clipboard

比如：

(structure)"person,id=(guint)0x0,color=(guint)0x00FF00FF;"
    (structure)"bicycle,id=(guint)0x1,color=(guint)0x00FF00FF;"
    (structure)"car,id=(guint)0x2,color=(guint)0x0000FFFF;"
    (structure)"motorcycle,id=(guint)0x3,color=(guint)0x00FF00FF;"
    Copy to clipboard

### 使用自訂模型執行物件偵測

使用 LiteRT runtime 執行物件偵測模型時，需在命令參數中指定自訂訓練模型及相應的標籤檔案。執行以下命令以啟動模型：

1. 複製模型至裝置中。

scp yolov8_custom.tflite root@<IP address of the target device>:/etc/models/
        Copy to clipboard
2. 複製標籤至裝置中。

scp yolov8_custom.labels root@<IP address of the target device>:/etc/labels/
        Copy to clipboard
3. 登入裝置。

ssh root@<IP address of the target device>
        Copy to clipboard
4. 修改 `/etc/configs/config_detection.json` 檔案，如圖所示。

{
        "file-path": "/etc/media/video.mp4",
        "ml-framework": "tflite",
        "yolo-model-type": "yolov8",
        "model": "/etc/models/yolov8_custom.tflite",
        "labels": "/etc/labels/yolov8_custom.labels",
        "constants": "<constants for custom YOLOv8 model>",
        "threshold": 40,
        "runtime": "dsp"
        }
        Copy to clipboard
5. 執行以下命令啟用 Weston 服務：

export XDG_RUNTIME_DIR=/dev/socket/weston && export WAYLAND_ DISPLAY=wayland-1
        Copy to clipboard
6. 執行範例應用程式。

gst-ai-object-detection --config-file=/etc/configs/config_detection.json
        Copy to clipboard

附註

- 若需查看可用的幫助選項，請運行以下命令：

gst-ai-object-detection -h
        Copy to clipboard
- 若要停止執行使用案例，請使用 <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">CTRL</kbd>+<kbd class="kbd docutils literal notranslate">C</kbd></kbd>。

Last Published: Dec 23, 2025

[Previous Topic
使用預設的模型分類物件](https://docs.qualcomm.com/bundle/publicresource/80-70020-15BT/topics/classify-objects-with-default-model.md) [Next Topic
使用 Qualcomm Device Cloud 執行範例應用程式](https://docs.qualcomm.com/bundle/publicresource/80-70020-15BT/topics/sample-app-qdc.md)