# KOI 2 x Teachable Machine 模型訓練方法

KOI 2已經新增支援Teachable Machine圖像分類模型的功能，有興趣的用家可以參考以下教程。

## 示範短片

{% embed url="<https://youtu.be/f_h8oTreSnc>" %}

## 詳細玩法教學

### 1. 更新KOI 2固件

首先確認KOI 2的固件版本，固件版本必須為4.2.0或以上。

如何檢查固件版本或更新的詳情可以參考：

{% content-ref url="/pages/OJ7vd5czxqLP6okLvN5O" %}
[KOI (KOI 1 & 2) 固件升級](/airelated/koi2/firmwareupdate.md)
{% endcontent-ref %}

### 2. 在Kittenblock完成圖像分類模型訓練

前往Kittenblock.

<https://kblock.kittenbot.cc/>

打開插件頁，加入機器學習插件。

{% content-ref url="/pages/nRWqIiOG63U8UDdqXds6" %}
[在線版KittenBlock](/programmingplatforms/kittenblock/online.md)
{% endcontent-ref %}

<figure><img src="/files/cJfl7Paiv64F5oSszGSP" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/HMrzQbaLmVUyXxQkYUhk" alt=""><figcaption></figcaption></figure>

打開訓練工具，選擇圖像分類

<figure><img src="/files/mjJkiRLxCo82USLxe2IR" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/p3SFWWEpx0goxzTsa1k8" alt=""><figcaption></figcaption></figure>

選擇嵌入式圖片模型

<figure><img src="/files/QTuwMBQ2ULFDo7PcqsRv" alt=""><figcaption></figcaption></figure>

可以使用webcam、上傳圖片或KOI 2作為圖像數據來源。

由於使用Webcam和上傳圖片和基本的圖像分類教學重疊，以下會集中以KOI2作為數據來源作範例。

使用Webcam和上傳圖片的教學請參考:

{% content-ref url="/pages/lKrqcjkXc2bch6jS2Uum" %}
[Kittenbot機器學習](/programmingplatforms/kittenblock/online/aifunctions/ml.md)
{% endcontent-ref %}

首先將KOI2用USB線連接至電腦按『裝置』

<figure><img src="/files/NYmry6D6VdPsTNEBXHRI" alt=""><figcaption></figcaption></figure>

按連接裝置

<figure><img src="/files/EKvehgqAd2XxGSYBW3cX" alt=""><figcaption></figcaption></figure>

在彈出式清單中選擇JTAG Serial Debug Unit

{% hint style="info" %}
注意: COM的數字不一定一樣
{% endhint %}

<figure><img src="/files/mgQWMynboZT7iwZYVeaB" alt=""><figcaption></figcaption></figure>

成功的話，KOI 2會顯示"Camera Mode"，然後頁面會顯示KOI的鏡頭畫面。

此時就可以使用KOI作為數據來源，錄入圖片數據。

<figure><img src="/files/kn6oqzXA1AgmPjgtjD68" alt=""><figcaption></figcaption></figure>

### 3. 錄入數據及訓練模型

錄入數據及訓練模型的教學已經詳細寫在以下篇章，本篇章將會略過。

{% content-ref url="/pages/lKrqcjkXc2bch6jS2Uum" %}
[Kittenbot機器學習](/programmingplatforms/kittenblock/online/aifunctions/ml.md)
{% endcontent-ref %}

### 4. 將模型上傳到KOI 2

訓練好模型後按下載模型

<figure><img src="/files/VsJmev2fvD0njVp68Qhm" alt=""><figcaption></figcaption></figure>

下載時可以選擇匯出模型或直接上傳到KOI2

匯出模型：模型需要放在SD卡，好處是可以儲存多個模型檔案，壞處是必須使用SD卡(Class10 或以上)

上傳到設備：模型會直接輸送到KOI內部，好處是比較方便，編程時不用指定載入模型名稱，壞處是同時間只能夠儲存一個模型

<figure><img src="/files/8TAl1SMnzKofvkTG9vEO" alt=""><figcaption></figcaption></figure>

#### 匯出模型

下載kmodel模型後，將kmodel檔案放在SD卡上然後將SD卡插入KOI即可

<figure><img src="/files/p31pfkYm1U6E9LcoLtvD" alt=""><figcaption></figcaption></figure>

#### 上傳到設備

{% hint style="info" %}
上傳前可能需要拔除KOI再連接電腦
{% endhint %}

按上傳到設備，模型就會直接傳輸到KOI

在傳輸過程中切勿拔除KOI

<figure><img src="/files/a4jBRo8htmenGUYQKzt2" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/qUJAr5UKUhPL0DOHLKTC" alt=""><figcaption></figcaption></figure>

等待模型傳輸完成後就可以拔除KOI

<figure><img src="/files/nNOtNC8JYSooHq0sFHQ6" alt=""><figcaption></figcaption></figure>

## 編程教學

此功能暫時可以在Microbit和Lite AI上使用，編程教學可以參考以下頁面:

### Micro:bit 編程教學

{% content-ref url="/pages/MAd6TXBhq4p9tNQiJltk" %}
[KOI2 x Teachable Machine Micro:bit 編程教學](/airelated/koi2/koi2makecode/koi2-x-teachable-machine-microbit-bian-cheng-jiao-xue.md)
{% endcontent-ref %}

### Futureboard Lite AI 編程教學

{% content-ref url="/pages/ye69MK3oRyjcigS0PxWD" %}
[KOI2 x Teachable Machine Lite AI 編程教學](/mcu/liteai/kittenblock/koi2/koi2-x-teachable-machine-lite-ai-bian-cheng-jiao-xue.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sharinghub.kittenbot.hk/airelated/koi2/teachablemachine.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
