MCU單晶片韌體設計

2021年12月13日 星期一

[Linux 核心] Linux 核心功能的配置選單

 

 開啓Linux 核心功能的配置選單, 

Step1: 得先安裝ncurses 套件, 才能產生選單畫面


>> sudo apt-get install libncurses5-dev libncursesw5-dev 
若以上無法成功安裝, 則先下這個指令後再安裝套件, 應該就能順利安裝 >> sudo apt-get update --allow-releaseinfo-change  
Step2: 進入到核心原始碼的資料匣, 執行 make menuconfig 

    >> cd linux-raspberrypi-kernel_1.20190401-1/
    >>  make menuconfig






2021年11月10日 星期三

How to save and load fine-tuned model?



 如何儲存Fine-tune BERT model 的網路權重及架構?

Custom mask layers require a config and must override get_config  ...........


1. ) 若pre-trained bert model 只是用來作為sentence embedding 的話,. 那就只儲存後面自己接的網路架構..不用整個儲存(即不必含BERT model), 因此可忽略載入pre-trained bert model . 那就回到原本傳統的model.save() , load_models('xxxx.h5')


2.) pre-trained bert model 串接自己網路架構, 一起訓練, 如果是這種的, 就用方法2

只存weight (model.save_weights), 用原本model 架構去產生一個空的new_model, 然後new_model.load_weights

model.save_weights('my_model_weights.h5')
...
new_model = <build your model with your model building code>

new_model.load_weights('my_model_weights.h5')








2021年10月21日 星期四

[JavaScript] ES7的async/await 非同步



前端瀏覽器執行JavaScript ,都是採"同步" (即函式執行完,才會往下執行它的下一行程式碼)。



若要採用非同步(Asynchronous)方式執行,可以在函數前面加入async 關鍵詞,如 async init () ,可以使函式init() 具有非同步的處理能力,即init()函內可以包含有需要等待的工作敍述,對需要等待的工作可以在該敍述前,加上await 關鍵字。





<case 左方程式區塊 >
程式呼叫了init()函式, 而在init()函式內因為遇到了await a() 這一行,故init() 會直接返回,去執行console.log('3'), 而原本await a() 的下一行, 會一直等到  a() 函式執行結束後才會開始執行。

因為await, 所以await a() 的下一行 是在未來某個時間點才又繼續執行,這就是非同步函數呼叫的概念。


<case 右方程式區塊 >

雖然 async init()  是一個可以允許非同步執行的函數,但這種寫法then()=> { },會使得console.log(3), 會在init()函式執行完才會執行。 



<!DOCTYPE html>
<html>
<body>

<h2>JavaScript async / await</h2>

<h1 id="demo"></h1>

<script>

async function myDisplay() {

      console.log('1')
    console.log('2')

  console.log('3')
}

myDisplay();
console.log('4')
console.log('5')
</script>

</body>
</html>

輸出為 ==> 1 2 3 4 5


<script>

async function myDisplay() {

      console.log('1')
       await console.log('2')

        console.log('3')
}


</script>

輸出為 ==> 1 2 4 5 3


<script>

async function myDisplay() {

await console.log('1')
await console.log('2')

  console.log('3')
}

myDisplay();
console.log('4')
console.log('5')
</script>

</body>
</html>

輸出為 ==> 1 4 5 2 3

2021年8月28日 星期六

mAP@threshold

 

mAP (mean Average Precision) for Object Detection

mAP@0.5 . 0.5 bounding box對Grond Truth 的IoU, 須達到的threshold才認定為物件。該物件為某一類旳預測機率稱為confidence。進行PR-curve 的計算。  

對每一個類別都用 PR-Curve 決定其效能, PR-Curve 底下所圍成的積即為 Average Precision,
  • 針對此類別的所有的bounding box ,計算 Recall 及 Precision
  • 在不同的recall 下(由0到1), 所對應的precision 所形成的面積,即為此類別的Average Precision,面積為 0~1 .
接著將所有類別的Average Precision值加總取平均, 即是mAP ,  此即為模型在預測各種類別的平均能力





2021年5月3日 星期一

實施線上同步或錄製數位教學影片的工具準備


1.) 準備好WebCam 和 麥克風 , 進行線上同步課程會使用到
2.) 因為不能寫板書,所以我們使用wacom數位板, PowerPoint 播放時可以清楚寫字

下載並安裝wacom driver 

https://drive.google.com/drive/folders/1fXPbY3cqNh8vPpvjJj2LdIFp2uv-_L6Z?usp=sharing

試著熟悉數位筆的使用感覺, 同時熟悉幾個常用的快速鍵,會讓你的講課流暢度不會因為數位筆的關係,而不斷停頓,


3.) 有時可能需要寫字在電腦螢幕上, 如軟體操作畫面, 則可以使用Pointofix 這類的軟體.

安裝Pointofix , 預設是德文, 中文化方法==> 將 pointofix_translation.ini 複製到 C:\Program Files (x86)\Pointofix . 更多 Pointofix 使用說明 https://briian.com/6545/

即可. 




在使用Pointofix  時,會發現在書寫螢幕時,使用wacom 筆寫得不是很順暢時, 無法寫得很小字時, 請記進入到 Wacom 數位板內容, "取消使用Windows Ink".  (要先裝wacom Driver才會有這個介面)



 


4.) 實體投影機

 如果課程會有手作的動作, 則可以使用實體投影機 或使用預錄操作影片教學

*實體投影機: 即時方便如下影片所示



*預錄操作影片教學: 教學相對輕鬆可以暫停或播放. 以後可以做成線上錄影教材.



5.) ScreenShot 分享 

若在螢幕上用Pointofix 所寫的內容很多很重要,那麼也可以按下F7 擷最畫面存成.PNG檔, 順便幫同學做個筆記. 之後再利用HFS或 Google drive 分享給同學.

若是使用Google drive 建立一個目錄來分享檔案, 分享的網址可以建立短網址 (https://reurl.cc/main/tw)  , 此網址於課程的第一堂課就可以給同學, 後續若有新增其他檔案, 同學也都可以在同一個地方下載或者想回家練習仍可以再次下載. 



另外, 此分享目錄最好也能有結構的分類




|--code
|-- doucment
|-- scrrenshot
        |-- scrrenshot_20200908
|       |-- scrrenshot_20200915








6.) 熟悉一下PowerPoint的快速鍵

記住 PowerPoint 在播放投影片的快速鍵. 可以增加講課的流暢度. 
可以試著按F8 ,可以直接切換成畫筆模式, 且不斷按下F8 還可以切換筆的顏色


老師的用心是決定課程品質的關鍵! 我們也得換位思考, 若我們是坐在底下的學生. 我們

一定也會期待這門課能獲得什麼, 而不是坐在那裡浪費生命







6.) 其他

* 使用Evercam 方便錄製課程. https://tw.formosasoft.com/cpage/download/
        
        錄音品質調最高, 畫格調成30fps 

*SnowBall 高品質的收音







2021年2月28日 星期日

物件偵測 (#1/5): MS COCO的資料集格式




在進行AI圖像上, 常會看到MS COCO的資料集,

COCO 的圖片資料集,提供3種標注檔:object instances(用於物件偵測), person keypoints(人的關鍵點,用於姿態識別)以及 image captions(圖像標題, 5 captions per image) , 每種標注類型都有相應的json 檔。標注檔也分好了訓練集、驗證集。


with open(annotation_file, "r") as f:
    data = json.load(f)
    annotations=data["annotations"]
    images=data["images"]
    categories=data["categories"]
    
    
    
print(f"Number of images: {len(annotations)}")
print(f"Number of images: {len(images)}")
print(f"Number of images: {len(categories)}")

The COCO dataset has been downloaded and extracted successfully.
Number of images: 36781
Number of images: 5000
Number of images: 80

images[60] => 取出index 60 這張圖的資訊

{'license': 1,
 'file_name': '000000360661.jpg',
 'coco_url': 'http://images.cocodataset.org/val2017/000000360661.jpg',
 'height': 480,
 'width': 640,
 'date_captured': '2013-11-18 21:33:43',
 'flickr_url': 'http://farm4.staticflickr.com/3670/9709793032_f9ee4f0aa2_z.jpg',
 'id': 360661}

annotations[60] => 取出index 60 annotations資訊

{'segmentation': [[267.51,
   222.31,
   292.15,
   222.31,
   291.05,
   237.02,
   265.67,
   237.02]],
 'area': 367.89710000000014,
 'iscrowd': 0,
 'image_id': 525083,
 'bbox': [265.67, 222.31, 26.48, 14.71],
 'category_id': 72,
 'id': 34096}


annotation{
    "id": int,    
    "image_id": int,
    "category_id": int,
    "segmentation": RLE or [polygon],
    "area": float,
    "bbox": [x,y,width,height],
    "iscrowd": 0 or 1,
}


每一張圖片會有一個image_id, 而一張圖可能包含一個以上的單一物件或群物件. 針對每一個物件,
不論是單一物件或群物件, 都會用一個annotation來表現物件內容.. 一張圖會有多個annotation, 即多個物件







annotation{
 "id": int, ==> 物件id
 "image_id": int, ==> 所屬的圖片
 "category_id": int, ==>此物件的類別id
 "segmentation": RLE or [polygon], ==> 單一物件或一群物件的區域描述
 "area": float, ==> 物件區域的Pixel總數
 "bbox": [x,y,width,height], ==> bounding box的座標
 "iscrowd": 0 or 1, ==> 0: 單一物件, 1: 一群物件 (如:一群觀眾) 
}


其中"segmentation": 若為單一物件, 則是以一個多邊形的座標點 [X1,Y1,X2,Y2, ....] 來描述此物件的區塊位置.
若是一群物件的區域描述, 如要描述一群蘋果,則會用Mask的方式來描述,如下圖所示。






一群物件的區域描述, 即iscrowd=1, 則segmentation的內容為

{'counts': [671, 10, 2, 2, 4, 22, 6, 31, 1, 11, 1, 10, 379, 16, 1, 25, 5, 55, 378, 43, 4, 55, 378, 44, 3, 55, 378, 44, 3, 55, 378, 44, 3, 55, 378, 44, 3, 55, 378, 44, 4, 54, 379, 29, 1, 16, 1, 54, 380, 28, 2, 15, 2, 53, 382, 23, 6, 15, 1, 8, 21, 1, 3, 3, 5, 12, 384, 20, 8, 16, 40, 12, 384, 16, 14, 15, 40, 10, 386, 10, 21, 14, 40, 8, 388, 8, 22, 15, 41, 3, 393, 3, 25, 15, 465, 15, 465, 15, 466, 14, 467, 13, 468, 12, 469, 10, 471, 8, 474, 3, 983, 7, 472, 9, 470, 11, 454, 6, 1, 20, 452, 28, 451, 30, 449, 31, 448, 33, 447, 34, 446, 35, 445, 35, 445, 35, 445, 35, 445, 36, 445, 36, 445, 35, 447, 33, 450, 30, 450, 30, 450, 12, 1, 17, 451, 10, 3, 16, 452, 8, 6, 13, 455, 4, 12, 8, 474, 3, 50865, 6, 459, 6, 8, 11, 454, 27, 452, 29, 450, 31, 448, 32, 448, 32, 448, 32, 448, 32, 448, 32, 448, 32, 448, 31, 450, 29, 452, 20, 2, 4, 456, 7, 1, 3, 1, 4, 7174, 6, 2, 6, 4, 14, 447, 34, 445, 36, 443, 38, 442, 38, 442, 38, 442, 38, 442, 38, 442, 38, 442, 38, 443, 36, 445, 34, 446, 6, 19, 6, 450, 3, 478, 1, 42714, 6, 473, 8, 471, 10, 469, 15, 465, 18, 462, 19, 461, 21, 459, 22, 458, 24, 456, 26, 455, 25, 456, 24, 458, 22, 461, 18, 463, 16, 466, 3, 5, 3, 3840, 7, 463, 20, 459, 22, 457, 27, 448, 33, 446, 35, 437, 44, 435, 46, 433, 47, 432, 48, 432, 48, 432, 48, 432, 48, 432, 30, 4, 14, 432, 29, 7, 12, 432, 29, 8, 10, 433, 29, 9, 8, 435, 13, 1, 1, 2, 10, 12, 3, 439, 12, 6, 7, 456, 10, 471, 3, 3, 2, 474, 1, 478, 2, 477, 3, 476, 4, 476, 9, 470, 11, 469, 12, 468, 13, 467, 14, 7, 1, 458, 23, 457, 23, 457, 23, 458, 22, 459, 21, 461, 19, 463, 18, 462, 19, 461, 20, 1, 9, 450, 33, 447, 34, 446, 36, 444, 37, 443, 38, 443, 38, 443, 37, 445, 35, 450, 7, 2, 21, 459, 21, 460, 20, 461, 19, 463, 3, 3, 10, 471, 8, 474, 3, 18209, 1, 479, 2, 478, 3, 477, 4, 476, 5, 475, 6, 474, 7, 474, 10, 471, 8, 474, 4, 5302, 7, 447, 4, 26, 4, 445, 6, 1, 15, 11, 3, 443, 29, 6, 3, 442, 32, 4, 2, 442, 38, 442, 38, 442, 38, 442, 38, 442, 38, 442, 37, 444, 16, 1, 18, 446, 8, 1, 3, 6, 3, 4, 8, 449, 3, 22, 4, 46076, 6, 468, 13, 466, 15, 461, 20, 459, 21, 458, 22, 457, 23, 457, 23, 457, 23, 457, 23, 457, 22, 458, 21, 459, 20, 460, 20, 461, 19, 462, 18, 463, 17, 462, 18, 461, 19, 460, 19, 461, 19, 461, 19, 461, 19, 461, 19, 461, 19, 461, 19, 461, 18, 463, 16, 465, 8, 1, 3, 470, 4, 31194, 12, 9, 6, 452, 29, 445, 36, 443, 38, 441, 39, 435, 45, 434, 46, 427, 53, 426, 54, 425, 55, 424, 55, 425, 54, 426, 53, 427, 51, 429, 25, 1, 24, 430, 22, 5, 22, 210], 'size': [480, 640]}






References:




尚有其他訓練影像的標記格式, 如PASCAL VOC 以XML格式儲存, TensorFlow Object Detection 以.csv 儲存, 而Darknet (Yolo) 以.txt 儲存

2021年2月7日 星期日

RP2040 與 Raspberry Pi Pico


Raspberry Pi 基金會也切入MCU 領域--Raspberry Pi Pico。Raspberry Pi 基金會還開了一個自己的晶片RP2040. 雙核的ARM Cortex-M0+ (133MHz), 內建264KB SRAM, 還外掛一個 16MB的 Flash。Pico 內部帶有boot loader,不過沒有作業系統 (不像Pi 或Pi zero 有Linux作業系統), 但Pico有提供C/C++ SDK及MicorPython SDK供使用者快速開發.   GPIO 輸出是 3.3V . 不過目前晶片還沒有對外銷售, 只有提供給幾家廠商,如Sparkfun開發板子. 重點是支援 TensorFlow Lite 框架, 可以開發輕量級Deep Learning 的應用


 
7 × 7 mm QFN-56 package 



RP2040 Chip features:

  • Dual ARM Cortex-M0+ @ 133MHz
  • 264kB on-chip SRAM in six independent banks
  • Support for up to 16MB of off-chip Flash memory via dedicated QSPI bus
  • DMA controller
  • Fully-connected AHB crossbar
  • Interpolator and integer divider peripherals
  • On-chip programmable LDO to generate core voltage
  • 2 on-chip PLLs to generate USB and core clocks
  • 30 GPIO pins, 4 of which can be used as analog inputs
  • Peripherals
    • 2 UARTs
    • 2 SPI controllers
    • 2 I2C controllers
    • 16 PWM channels
    • USB 1.1 controller and PHY, with host and device support
    • 8 PIO state machines

RP2040的晶片架構圖

Raspberry Pi Pico



而底下是由台灣程式教育協進會所開發出的 Pico 擴充卡, 可應用在物聯網及AI Edge 應用 (Tensor flow  lite), 而且可以使用MicroPython 撰寫程式。

Pico 擴充卡規格: 

1.) UART-to-USB (PL2303) 可連接PC

2.) UART座 for ESP-01 (可連接ESP8266 WiFi)

3.) SPI pin x1  

4.) SPI 腳座for SPI ArduCAM

5.) I2C 針腳 x1  

6.) I2C 座for OLED

7.) G-sensor (LIS3DH)

8.) PWMx8

9). ADCx1

10.) LEDx2

11.) Micro phonex1

12.) Buttonx1

13.) 電源輸出座-(5V,3V輸出)

14.) Power LED indicator



pico W 使用MQTT publish