# 使用自訂訓練模型運行示例應用

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

先決條件

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

    有關設置 eSDK 以及下載和編譯原始碼的說明，請參見 [Qualcomm 智慧多媒體軟體開發工具包 (IM SDK) 快速入門指南](https://docs.qualcomm.com/bundle/publicresource/topics/80-70018-51/introduction.html)。
2. 有關下載原始碼和編譯自訂參考應用的說明，請參見 [開發自己的 AI/ML 應用](https://docs.qualcomm.com/doc/80-70018-15BT/topic/develop-your-own-application.html)。
3. [下載 Qualcomm 神經處理 SDK 的模型和標籤檔案](https://docs.qualcomm.com/doc/80-70018-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 運行時運行物件偵測模型，請在命令行參數中指定自訂訓練模型及其自訂標籤檔案，並運行以下命令。

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: Oct 15, 2025

[Previous Topic
使用默認模型分類對象](https://docs.qualcomm.com/bundle/publicresource/80-70018-15BT/topics/classify-objects-with-default-model.md) [Next Topic
使用 Qualcomm Device Cloud 運行示例應用程序](https://docs.qualcomm.com/bundle/publicresource/80-70018-15BT/topics/sample-app-qdc.md)