在K210上运行基于yolov的口罩检测

在K210上运行基于yolov的口罩检测

勘智K210这款芯片由著名的矿机公司嘉楠科技基于RISC-V架构进行研发设计,可根据业务场景需求扩展基础指令,具备较强的可编程能力。同时,勘智K210具备机器听觉与机器视觉两种能力,可以灵活适配人脸识别、目标检测、语音唤醒及识别等场景,是国内ASIC领域为数不多保持一定通用性的芯片。

可不要以为MCU的性能就一定比不上高端SoC,至少在AI计算方面,K210的算力其实是相当可观的。根据嘉楠官方的描述,K210的KPU算力有0.8TOPS ,作为对比,拥有128个CUDA单元GPU的英伟达Jetson Nano的算力是0.47TFLOPS ;而最新的树莓派4只有不到0.1TFLOPS

话不多说,开始!

先将kmodel模型文件烧入Flash 地址为0x0x500000在这里插入图片描述
打开maixpy ide将代码上传到开发板

import sensor, image, lcd, time
import KPU as kpu

color_R = (255, 0, 0)
color_G = (0, 255, 0)
color_B = (0, 0, 255)


class_IDs = ['no_mask', 'mask']


def drawConfidenceText(image, rol, classid, value):
    text = ""
    _confidence = int(value * 100)

    if classid == 1:
        text = 'mask: ' + str(_confidence) + '%'
    else:
        text = 'no_mask: ' + str(_confidence) + '%'

    image.draw_string(rol[0], rol[1], text, color=color_R, scale=2.5)



lcd.init()
sensor.reset(dual_buff=True)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_hmirror(0)
sensor.run(1)


task = kpu.load(0x500000)


anchor = (0.1606, 0.3562, 0.4712, 0.9568, 0.9877, 1.9108, 1.8761, 3.5310, 3.4423, 5.6823)
_ = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor)
img_lcd = image.Image()

clock = time.clock()
while (True):
    clock.tick()
    img = sensor.snapshot()
    code = kpu.run_yolo2(task, img)
    if code:
        totalRes = len(code)

        for item in code:
            confidence = float(item.value())
            itemROL = item.rect()
            classID = int(item.classid())

            if confidence < 0.52:
                _ = img.draw_rectangle(itemROL, color=color_B, tickness=5)
                continue

            if classID == 1 and confidence > 0.65:
                _ = img.draw_rectangle(itemROL, color_G, tickness=5)
                if totalRes == 1:
                    drawConfidenceText(img, (0, 0), 1, confidence)
            else:
                _ = img.draw_rectangle(itemROL, color=color_R, tickness=5)
                if totalRes == 1:
                    drawConfidenceText(img, (0, 0), 0, confidence)

    _ = lcd.display(img)

    print(clock.fps())

_ = kpu.deinit(task)

摄像头有点渣,运行帧率大概在14帧左右,运行速度还是很可观的

在这里插入图片描述
模型下载:
链接:https://pan.baidu.com/s/1r5BPmkE8RDrJ1lxlJopHAA
提取码:hjob

sipeed社区:https://bbs.sipeed.com/

  • 17
    点赞
  • 92
    收藏
    觉得还不错? 一键收藏
  • 17
    评论
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值