K210学习记录

我使用的是Maix bit系列K210,先在Kflash中下载固件,我刚开始使用的是with-ide的固件,刚开始还是挺好用的。

但是后来在要使用训练好的模型代码时,出现了运行内存太小的错误。所以就改用了mini-with-ide的版本固件,这个运行内存错误就解决了。本来还想用官方所给的有关内存GC代码,但是用了一样没用,后来重新换了个固件就行了。

#本程序用于使用Maixpy系列开发板进行图像数据收集
#使用方法:
#0.为Maixpy系列开发板插入一张sd卡
#1.将本程序烧入Maixpy系列开发板中,上电运行
#2.阅读用户说明后,按下BOOT按钮进行拍照,LCD屏左下角会显示当前存储目录
#3.拍照后的图片默认存储在sd卡目录./0/下面,拍摄成功后,会在LCD屏正下方显示"OK!"字样
#长按BOOT按钮可切换拍照后图片的默认存储路径(默认支持./1/~./10/,也就是十分类,如有其他需求,请修改Classes_num变量)
#4.完成所有分类的图像采集后,将sd卡中的数据移动到电脑上,并自行按需修改存储图片的文件夹名称(标签名),
#并删除没有用到的标签文件夹
#5.用DataAssitant数据集与处理软件进行处理。
#6.将得到的.zip压缩文件上传MaixHub进行训练。
#PS:
#DataAssitant数据集与处理软件下载地址:
#https://cdn.sipeed.com/donwload/12kj346465hjkv68g7c/DataAssitantV1.0.zip
#数据集收集教程:https://www.maixhub.com/index.php/index/mtrain/help.html
##################################################################################
#This program is used for image data collection using Maixpy ​​series development boards#Instructions:
# 0. Insert a sd card for Maixpy ​​series development board
# 1. Burn the program into the Maixpy ​​series development board and power on
# 2. After reading the user's instructions, press the BOOT button to take a picture,
#    the current storage directory will be displayed in the lower left corner of the LCD screen
# 3. The picture after taking the picture is stored in the sd card directory by default.
#    Long press the BOOT button to switch the default storage path of pictures after taking pictures
#    (default supports ./1/~./10/, which is very class, if you have other needs, please modify the Classes_num variable)
# 4. After completing the collection of all the classified images, move the data in the sd card to the computer,
#    and modify the folder name (tag name) where the pictures are stored as needed,
#    And delete unused tag folders# 5. Use DataAssitant dataset and processing software for processing.
# 6. Upload the obtained .zip compressed file to MaixHub for training.
#PS:
#DataAssitantDataset and processing software download address:
#https: //cdn.sipeed.com/donwload/12kj346465hjkv68g7c/DataAssitantV1.0.zip
#Dataset Collection Tutorial: https://www.maixhub.com/index.php/index/mtrain/help.html
##################################################################################
import sensor, image, time, lcd
import utime
import uos
import sys
from Maix import GPIO
from board import board_info
from fpioa_manager import fm
##################################################################################
Classes_num = 10 #十分类(10个标签文件夹)|Tier 10 (10 tag folders)
##################################################################################
bg = lcd.RED
text = lcd.WHITE
boot_press_flag = 1
start = time.ticks_ms()
end = time.ticks_ms()
ui_num = 0
image_save_path = "/sd/image/"#图片保存目录头
claass = 0#文件夹名
image_num = 0#图像文件保存名
#完整图片保存路径image_save_path+claass+"/"
image_data = image.Image()#图像
shoot_flag = 0
##################################################################################
def boot_key_irq(pin_num):#
    global ui_num
    global boot_press_flag,start,end
    global claass
    global image_num
    global shoot_flag
    #utime.sleep_ms(100)
    if(boot_press_flag == 1):
        start = time.ticks_ms()
        boot_press_flag = 0
    elif(boot_press_flag == 0):
        end = time.ticks_ms()
        boot_press_flag = 1
        time_diff = time.ticks_diff(end, start)
        if(time_diff >120 and time_diff <500):
            print("短按拍摄",time_diff)
            ui_num = 1
            if(ui_num == 1):#已进入拍摄
                image_num = image_num + 1
                #shoot_flag = 1
                image_data.save("/sd/image/"+str(claass)+"/"+str(utime.ticks_us())+str(image_num)+".jpg")
                lcd.draw_string(160, 224,"ok!"+str(image_num))
                utime.sleep_ms(500)
                #print(str(utime.ticks_us()))
        elif(time_diff >=500 and time_diff <=2000):
            print("长按切换文件夹",time_diff)
            if(ui_num == 1):#已进入拍摄
                claass = claass + 1
                if(claass >Classes_num-1):#让保存路径始终有效
                    claass = 0
        elif():
            boot_press_flag = 1
            start = 0
            end = 0
    #print("key", pin_num)
 
fm.register(board_info.BOOT_KEY, fm.fpioa.GPIOHS0, force=True)
boot_key=GPIO(GPIO.GPIOHS0, GPIO.IN, GPIO.PULL_UP)
boot_key.irq(boot_key_irq, GPIO.IRQ_BOTH, GPIO.WAKEUP_NOT_SUPPORT, 7)
##################################################################################
def draw_help_ui():#显示帮助页面
    lcd.draw_string(60, 10, "Data Collection Assistant", text, bg)
    lcd.draw_string(20, 30, "1.Press the BOOT button to take a pi-", text, bg)
    lcd.draw_string(10, 50, "cture. The current storage directory", text, bg)
    lcd.draw_string(10, 70, "will be displayed in the lower left corner of the LCD screen.", text, bg)
    lcd.draw_string(10, 90, "corner of the LCD screen.", text, bg)
 
    lcd.draw_string(20, 120, "2.Long press BOOT button to switch ", text, bg)
    lcd.draw_string(10, 140, "the default storage folder path of pi-", text, bg)
    lcd.draw_string(10, 160, "ctures after taking photos.", text, bg)
    lcd.draw_string(10, 200, "--Press the BOOT button to start shoot", text, bg)
##################################################################################
def not_found_sd():#没有找到sd卡
    lcd.clear(bg)
    lcd.draw_string(10, 90, "ERROR: ", text, bg)
    lcd.draw_string(20, 110, "No sd card found", text, bg)
    lcd.draw_string(20, 130, "The Reason:", text, bg)
    lcd.draw_string(20, 150, "1.No sd card inserted", text, bg)
    lcd.draw_string(20, 170, "2.sd card model is not supported", text, bg)
    lcd.draw_string(20, 190, "3.sd card format is not FAT", text, bg)
##################################################################################
def init():#初始化相关
    i = 0
    sensor.reset()
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    sensor.skip_frames(time = 2000)
    sensor.set_vflip(1)
    sensor.run(1)
    lcd.init(type=1, freq=15000000, color=bg)
    try:
        uos.mkdir("/sd/image")#创建image文件夹,顺路sd卡检测
        for i in range(Classes_num):
            uos.mkdir("/sd/image/"+str(i))#创建image/1-10文件夹,顺路sd卡检测
            print("/sd/image/"+str(i))
    except Exception as e:
        if(str(e) == "[Errno 17] EEXIST"):
            pass
        else:
            not_found_sd()
            sys.exit(0)
    finally:
        try:
            for i in range(Classes_num):
                uos.mkdir("/sd/image/"+str(i))#创建image/1-10文件夹,顺路sd卡检测
                #print("/sd/image/"+str(i))
                lcd.draw_string(0, 224,str(claass))
        except Exception as e:
            if(str(e) == "[Errno 17] EEXIST"):
                pass
            else:
                not_found_sd()
                sys.exit(0)
    draw_help_ui()
##################################################################################
def image_ui():
    global image_data
    image_data = sensor.snapshot()         # Take a picture and return the image.
    lcd.display(image_data,oft=(0,0))                # Display on LCD
    lcd.draw_string(0, 224,"/sd/image/"+str(claass)+"/")
##################################################################################
def main():#主函数
    init()
    while(True):
        if(ui_num == 1):
            image_ui()
 
if __name__ == '__main__':
    try:
        main()
    except Exception as e:
        print(e)
        lcd.clear(bg)
        lcd.draw_string(10, 90, "ERROR:unknown mistake", text, bg)
        lcd.draw_string(20, 110, "Please contact sipeed for help.", text, bg)

需要几个文件夹可以改动。

短按boot键进行拍摄,长按boot键进行换文件夹。

拍摄完数据集后,使用labelImg进行标注。

标注完成后可以直接用集成软件Mx-yolov3来训练数据集

19bb31475cf54ab099d4ab18cf96e729.png

 之前使用50张照片,训练次数(迭代次数)选择300轮,会导致早停机制出现(过拟合)

(差不多到100轮时模型就已经不再优化了)

选择了迭代次数为100次后,没有出现早停机制,但可能由于我是win11,训练完之后没有出现转换文件(tf),只有(h5)。所以不能将h5转换成kmodel。

50张照片对于两个模型来说数量还是太少了,虽然测试模型的准确度挺高,但是在IDE中是检测不到的,因为模型数量还是不够。

训练完后,将kmodel,anchors和classes文件复制到sd卡中。

再打开

 

925543c089a944dfa493cde3d03a0647.png

在里面的程序中找到boot代码,放到IDE中即可。

放在IDE中后,又因摄像头是反着照的,所以要加入一个水平翻转代码。

在CSDN找到一个64a85fbe03e84dcb8405b90f0deaddde.png

使用了这个之后屏幕确实正常了,但是屏幕变黑了。

所以后俩又换了一个,这个是正常的。

54bb8d52224044cab3b21749f60e8f85.png

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值