認識 AI
什麼是監督式學習?
AI 會看大量標好標籤的狗和貓照片,從中學習特徵,藉此分辨這兩個類別。
AI 怎麼學會分辨狗和貓?
1. 收集範例收集大量狗和貓的照片。
2. 找出特徵比較耳朵形狀、臉部形狀等特徵。
3. 學習特徵學會有助於分辨狗和貓的特徵。
組裝
來做一隻狗和一隻貓吧!


| 指令 | 作用 |
|---|---|
| 轉動馬達:向左旋轉 | 持續向左旋轉。 |
| 轉動馬達:向右旋轉 | 持續向右旋轉。 |
| 向左旋轉 1 秒 | 在設定的時間內向左旋轉。 |
| 向右旋轉 1 秒 | 在設定的時間內向右旋轉。 |
| 關閉馬達 | 讓馬達停止。 |

| 指令 | 作用 |
|---|---|
| 播放音符 | 播放一個音符。 |
| 播放音符 0.25 拍 | 用拍數設定音符的長度。 |
| 播放音效 | 播放蜂鳴器音效。 |
| 播放音效 0.25 拍 | 用拍數設定音效的長度。 |

| 指令 | 作用 |
|---|---|
| 顯示 LED 點陣 | 畫出自訂的點陣圖案。 |
| 顯示文字:A | 在LED積木上顯示文字。 |
| 顯示數字:1 | 在LED積木上顯示數字。 |
| 顯示圖示:愛心 | 顯示內建的圖示。 |
| 清除 LED 畫面 | 把 LED 點全部關掉。 |
組裝狗和貓

教 AI 學習
打開 CuroAI
加入機器學習擴充功能
打開「Extensions」(擴充功能),選擇「Cubroid Machine Learning」。
建立三個類別
建立三個類別:狗、貓和背景。
什麼是標籤?標籤就是類別的名稱,告訴 AI 這個範例是什麼。
每個類別 15 張以上不同的範例



替三個類別命名
替每個標籤取名字,然後把每個「name label」(命名)積木各點一下來儲存。
為什麼要訓練「背景」?因為 AI 需要一個類別來代表沒有狗也沒有貓的畫面。
name label [1 v] as [狗] :: #52b98a name label [2 v] as [貓] :: #52b98a name label [3 v] as [背景] :: #52b98a
收集多樣的訓練範例
用「train label」(訓練標籤)積木,替每個類別收集 15 張以上不同的範例。記得變換角度和背景。
收集某一個類別時,別讓其他動物入鏡。
train label [1 v] :: #52b98a train label [2 v] :: #52b98a train label [3 v] :: #52b98a
積木連線(群組編號)
打開積木電源,輸入和積木貼紙一樣的號碼,然後確認。

寫程式並執行
哪個積木負責什麼?
直流馬達 1狗的尾巴
直流馬達 2貓的尾巴
LED積木貓的表情
聲音積木狗的叫聲
把預測結果連到動作
狗- 播放音效
- 讓馬達 1 向左/向右轉
- 停止馬達 1
貓- 在 LED 上顯示愛心
- 讓馬達 2 向左/向右轉
- 停止馬達 2;清除 LED
背景- 停止馬達 1
- 停止馬達 2
- 清除 LED 畫面
看看完整的程式
先把命名積木和訓練積木各點一下。之後每當 AI 認出一個類別,「when received label」積木就會自動執行。
name label [1 v] as [狗] :: #52b98a train label [1 v] :: #52b98a when received label: [1 v] :: hat #52b98a 播放音符 [效果小 v] :: sound 旋转直流电机块1 (1) [向左旋转 v] 秒 :: motion 等待 (1) 秒 :: control 旋转直流电机块1 (1) [向右旋转 v] 秒 :: motion 等待 (1) 秒 :: control 关闭直流电机块1 :: motion
name label [2 v] as [貓] :: #52b98a train label [2 v] :: #52b98a when received label: [2 v] :: hat #52b98a 显示 [♥ v] :: looks 旋转直流电机块2 (1) [向左旋转 v] 秒 :: motion 等待 (1) 秒 :: control 旋转直流电机块2 (1) [向右旋转 v] 秒 :: motion 等待 (1) 秒 :: control 关闭直流电机块2 :: motion 清空畫面 :: looks
name label [3 v] as [背景] :: #52b98a train label [3 v] :: #52b98a when received label: [3 v] :: hat #52b98a 关闭直流电机块1 :: motion 关闭直流电机块2 :: motion 清空畫面 :: looks
測試前,每個類別先訓練 15 張以上不同的範例。檢查標籤的切換、等待時間和馬達方向。
Try it out
Turn on the camera and show a dog photo, then a cat photo, to the camera. You can print the photos or show them on another device's screen. Check that the robot's movement changes with the label the AI recognises.
Show a dog photoA sound effect plays and the dog's tail (motor 1) wags left and right.
Show a cat photoA heart appears on the cat's face (LED) and the cat's tail (motor 2) wags.
Take the photo awayWith no dog or cat (background), the motors stop and the LED display clears.
If the movement doesn't change reliably, collect more example photos for that class and train again. Try a few more times at different distances and lighting.
小測驗
Q用標好標籤的範例來學習,這種學習方法叫什麼?
查看答案
監督式學習 — AI 從標有類別標籤的範例中學習。
組裝好、寫好程式,也測試過了嗎?點一下,記錄你的進度。
