勘智K210這款芯片由著名的礦機公司嘉楠科技基於RISC-V架構進行研發設計,可根據業務場景需求擴展基礎指令,具備較強的可編程能力。同時,勘智K210具備機器聽覺與機器視覺兩種能力,可以靈活適配人臉識別、目標檢測、語音喚醒及識別等場景,是國內ASIC領域為數不多保持一定通用性的芯片。
一、下載最新固件
kflash下載地址:https://dl.sipeed.com/shareURL/MAIX/tools/kflash_gui/kflash_gui_v1.6.5
固件下載地址:https://dl.sipeed.com/shareURL/MAIX/MaixPy/release/master
二、將訓練好的模型下載進TF卡根目錄中
注意:TF卡首次使用時請先格式化TF卡,之后再將模型下載至TF卡中
模型下載地址:http://study.arduino-esp32.cn/study/K210/yolov2.kmodel
三、下載MaixPy IDE
https://dl.sipeed.com/shareURL/MAIX/MaixPy/ide
將下方代碼復制進IDE
1 import time 2 import sensor 3 import lcd 4 import image 5 import KPU as kpu 6 7 sensor.reset() #攝像頭初始化 8 sensor.set_pixformat(sensor.RGB565) #彩色圖 9 sensor.set_framesize(sensor.QVGA) #幀大小 10 sensor.run(1) 11 sensor.skip_frames(10) #跳幀數 12 sensor.set_windowing((224,224)) #設置顯示屏窗口顯示大小 13 sensor.set_vflip(1) #攝像頭垂直鏡像 14 sensor.set_hmirror(1) #攝像頭水平鏡像 15 16 lcd.init(freq=15000000,color=0x0000) #顯示屏初始化 17 18 anchor= (1.2989, 1.5765, 2.3041, 2.7863, 3.0796, 4.4259, 4.3645, 4.3797, 5.4372, 5.8903) #錨點參數 19 KPU = kpu.load("/sd/yolov2.kmodel") #模型加載 20 kpu.init_yolo2(KPU,0.6,0.3,5,anchor) #yolo2初始化 並設置概率閾值以及錨點參數 21 22 labels= ['apple', 'banana', 'orange'] #定義模型分類 23 25 while True: 26 img = sensor.snapshot() #獲取圖像 27 code = kpu.run_yolo2(KPU,img) #運行神經網絡模型 28 if code: 29 for i in code: 30 a=img.draw_rectangle(i.rect(),(0,255,0),2) #將獲取到模型用矩形框畫出 31 xx = int((i.x()+i.w())/2) #獲取物品模型的X軸中心位置 32 yy = int((i.y()+i.h())/2) #獲取物品模型的Y軸中心位置 33 a=img.draw_cross([xx,yy],0xFFFF,30,1) 34 a = lcd.display(img) 35 for i in code: 36 lcd.draw_string(i.x()+45, i.y()-5, labels[i.classid()]+" "+'%.2f'%i.value(), lcd.WHITE,lcd.GREEN) #顯示模型ID 37 else: 38 lcd.display(img) #否則僅顯示圖像
選擇自己對應的K210板卡
點擊連接至K210板卡,並選擇對應的串口
連接成功后點擊運行即可
四、 識別模型演示