sipeed wiki logo

wiki

  • 产品
  • 开源软件
    • MaixPy
    • MaixPy_v1
    • Lichee
    • AI 指南
  • MaixHub
  • 动态
  • FAQ 汇总
  • Translate
  • 搜索
    输入关键词,多关键词空格隔开 正在加载,请稍候。。。 下载文件失败,请刷新重试或检查网络 来自其它文档的结果 当前文档搜索结果
  • MaixPy3 是什么?能做什么?
    • 如何获取、安装、使用?
    • 安装或配置 IDE 开发工具
      • 基于 USB 开发 MaixII-Dock
      • 基于 WIFI 开发 MaixSense
    • M2DOCK (V831)上手视觉指南
    • 遇到问题怎么办?
      • 如何正确反馈问题!
      • 常见问题与解决方法
    • 相关的基础知识
      • MaixPy 和 MaixPy3 的区别
      • 收录一些国内 Python 基础教程
      • 大佬鼠の嵌入式 Python 入门教程 [1]
      • 大佬鼠の嵌入式 Python 入门教程 [2]
      • 使用必应搜索 V831 M2DOCK 的内容
      • 咸鱼菌の MaixII-Dock 上手系列教程
      • 喏呐の【攻城狮成长记】
    • 开发者更新日志
      • 【项目开发基础】项目架构介绍
      • 【底层开发基础】编译安装测试
      • 【移植适配实例】开发新的平台
      • 【图像处理开发】传统视觉算法
  • 基础功能模块
    • 图像处理
      • 背景知识
      • 基础用法
      • 传统视觉
    • 硬件外设
      • GPIO (点灯)
      • I2C (pylibi2c)
      • PWM (脉冲宽度调制)
      • UART (pyserial)
      • SPI (spidev)
      • EVENT (evdev)
      • ADC* (模/数转换器)
      • WATCHDOG* (看门狗定时器)
    • 网络功能
    • 媒体功能
      • 视频播放 (pyav)
      • 录音与播放 (pyaudio)
  • 获取 AI 算法
    • 边缘检测 (sobel)
    • 物品分类 (resnet)
    • 物体检测 (yolov2)
    • 数字识别
    • 人脸识别
    • 自学习分类
    • 车牌识别
    • 在线训练 AI 模型
    • 本地训练 AI 模型
      • 深度神经网络基础知识 (必看)
      • 本地训练环境搭建
      • 边缘检测模型搭建过程
      • 如何制作数据集
      • 训练物体分类模型
      • 训练物体检测模型
  • 核心 API 手册
    • image
    • display
    • camera
    • nn

2023-04-20
编辑本页

物品检测

更新时间 负责人 内容 备注
2021年12月2日 Rui 初次编写文档 ----
2022年12月15日 Rui 修改文档的编写方式 使用 Jupyter notebook 进行编写文档
2022年1月18日 Rui 修改文档,增加效果图 通过测试的平台有 MaixII-Dock,使用的是 MaixPy3 0.4.0
2022年3月18日 Rui 在 MaixSense 上使用测试通过 需要将 MaixPy3 更新到 0.4.5 以上
2022年3月29日 Rui 添加 MaixII-Dock Yolo-V2 20分类 模型及代码下载:Github 下载
作者:小老鼠

物品检测,即目标检测,简单的来说就是可以框选出画面中的目标物体并输出坐标位置。通过不同的数据集来实现不同的目标识别,以下分别使用人脸数据集和 Yolo 标准数据集进行训练得出的目标检测模型。

运行效果

准备

  • 使用的硬件为 MaixII-Dock 或 MaixSense
  • 获取模型文件,MaixII-Dock 可以在 MaixHub 上获取或者烧录最新版本的系统镜像;MaixSense 则是需要烧录最新的 armbian 系统镜像到内存卡上。
  • 确认 MaixPy3 版本为 0.4.3 以上
  • 插卡启动硬件

在 MaixII-Dock 上部署目标检测

2022年后系统内置了模型文件 /home/model/face/yolo2_face_awnn.*)

部署人脸目标检测网络模型

In [1]:

class Yolo:
    labels = ["person"]
    anchors = [1.19, 1.98, 2.79, 4.59, 4.53, 8.92, 8.06, 5.29, 10.32, 10.65]
    m = {
        "param": "/home/model/face/yolo2_face_awnn.param",
        "bin": "/home/model/face/yolo2_face_awnn.bin"
    }
    options = {
        "model_type":  "awnn",
        "inputs": {
            "input0": (224, 224, 3)
        },
        "outputs": {
            "output0": (7, 7, (1+4+len(labels))*5)
        },
        "mean": [127.5, 127.5, 127.5],
        "norm": [0.0078125, 0.0078125, 0.0078125],
    }
    def __init__(self):
        from maix import nn
        from maix.nn import decoder
        self.model = nn.load(self.m, opt=self.options)
        self.decoder = decoder.Yolo2(len(self.labels), self.anchors, net_in_size=(224, 224), net_out_size=(7, 7))
    def __del__(self):
        del self.model
        del self.decoder
print(Yolo)
[ rpyc-kernel ]( running at Thu Jan 20 13:46:59 2022 )
<rpyc.core.protocol.Yolo object at 0xd8d7f8>

运行网络模型,进行目标检测

上面已经将模型文件加载部署到系统中,下面只需要对模型文件进行解码,获取目标在画面中的位置并框选出来

In [ ]:
from maix import camera, display
yolo = Yolo()
print(yolo)
while True:
    img = camera.capture().resize(224, 224)
    out = yolo.model.forward(img, quantize=True, layout="hwc")
    boxes, probs = yolo.decoder.run(out, nms=0.3, threshold=0.5, img_size=(224, 224))
    if len(boxes):
        for i, box in enumerate(boxes):
            # class_id = probs[i][0]
            img.draw_rectangle(box[0], box[1], box[0]+box[2], box[1]+box[3], (255,0,0), 1)
        display.show(img)
    else:
        display.show(img)
No description has been provided for this image

在 MaixSense 上部署目标检测

可以用于识别 labels 中的物品类型。

最新版本的 Armbian 系统已经将模型内置到了 /home/model/ 中,Tina 系统目前不提供支持。

部署网络模型

In [ ]:

class Yolo:
    labels = ["aeroplane","bicycle","bird","boat","bottle","bus","car","cat","chair","cow","diningtable","dog","horse","motorbike","person","pottedplant","sheep","sofa","train","tvmonitor"]
    anchors = [0.4165, 0.693 , 0.9765, 1.6065, 1.5855, 3.122 , 2.821 , 1.8515 , 3.612 , 3.7275]
    m = {
        "bin": "/home/model/aipu_yolo_VOC2007.bin"
    }
    options = {
        "model_type":  "aipu",
        "inputs": {
            "input0": (224, 224, 3)
        },
        "outputs": {
             "output0": (7, 7, (1+4+len(labels))*5)
        },
        "mean": [127.5, 127.5, 127.5],
        "norm": [0.0078125, 0.0078125, 0.0078125],
        "scale":[8.031941],
    }
    def __init__(self):
        from maix import nn
        from maix.nn import decoder
        self.model = nn.load(self.m, opt=self.options)
        self.decoder = decoder.Yolo2(len(self.labels), self.anchors, net_in_size=(224, 224), net_out_size=(7, 7))
    def __del__(self):
        del self.model
        del self.decoder
print(Yolo)

运行网络模型,进行目标检测

上面已经将模型文件加载部署到系统中,下面只需要对模型文件进行解码,获取目标在画面中的位置并框选出来

In [ ]:
from maix import camera, display
yolo = Yolo()
print(yolo)
while True:
    img = camera.capture().resize(224,224)
    out = yolo.model.forward(img, quantize=True, layout="chw")
    boxes, probs = yolo.decoder.run(out, nms=0.5, threshold=0.5, img_size=(224, 224))
    if len(boxes):
        for i, box in enumerate(boxes):
            class_id = probs[i][0]
            prob = probs[i][1][class_id]
            disp_str = "{}:{:.2f}%".format(yolo.labels[class_id], prob*100)
            img.draw_rectangle(box[0], box[1], box[0]+box[2], box[1]+box[3], (255,0,0), 1)
            img.draw_string(box[0], box[1]+ box[3] ,disp_str, scale=0.5,color=(0, 0, 255), thickness=1)
        display.show(img)
    else:
        display.show(img)

网络模型训练

查看左边目录中的 【训练AI模型】 学习如何训练属于自己的目标检测模型

脱机运行

对于 M2Dock,前面说过开机启动代码顺序是 /root/app/main.py > /root/main.py ,所以在保存的时候自己注意下保存位置

物品分类 (resnet)
数字识别
  • 相关链接
    • Sipeed 官网
    • MaixHub
    • Sipeed 淘宝
    • 网站地图
    • 网站使用 teedoc 生成
  • 源码
    • Wiki 源码
    • 开源项目
  • 关注我们
    • twitter
    • 淘宝
    • github
    • 微信公众号
  • 联系我们
    • 电话: +86 0755-27808509
    • 商业支持: support@sipeed.com
    • 地址: 深圳市宝安区新湖路4008号蘅芳科技办公大厦A座-2101C
    • 加入我们
  • ©2018-2023 深圳矽速科技有限公司
  • 粤ICP备19015433号