TinyML之Hello world----基于Arduino Nano 33 BLE Sense Rev2的呼吸灯

ops/2024/10/18 23:23:22/

早期版本的Hello World

这应该是一个逼格比较高的呼吸灯了,用ML来实现呼吸灯功能,之前已经有大佬发过类似的文章:https://blog.csdn.net/weixin_45116099/article/details/126310816

当前版本的Hello World

这是一个ML的入门例程,但是随着版本的变更,现在最新的例程已经采用了新的方法:https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/examples/hello_world

说实话,我一看到里面的bazel,直接就蒙了,光搭建开发环境就可以把我们菜鸟劝退。

好在,有colab,这里不得不表扬一下人家业界巨佬的奉献精神,有了colab,好多基础环境人家Google已经帮你搭建好了。

环境搭建

其实,所谓的环境搭建,就是在colab里安装bazel,下载github工程:

!npm install -g @bazel/bazelisk
!git clone https://github.com/tensorflow/tflite-micro.git

一条代码搞定。

Run the evaluate.py script on a development machine

把目录切换到/content/tflite-micro,这里插一句,colab的目录切换用!cd好像不太好用,还是得用python

import os
path = "/content/tflite-micro"
os.chdir(path)
print(os.getcwd())

然后运行:

bazel build tensorflow/lite/micro/examples/hello_world:evaluate
bazel run tensorflow/lite/micro/examples/hello_world:evaluate
bazel run tensorflow/lite/micro/examples/hello_world:evaluate -- --use_tflite

Run the evaluate_test.py script on a development machine

bazel build tensorflow/lite/micro/examples/hello_world:evaluate_test
bazel run tensorflow/lite/micro/examples/hello_world:evaluate_test

Run the tests on a development machine

bazel run tensorflow/lite/micro/examples/hello_world:hello_world_test
make -f tensorflow/lite/micro/tools/make/Makefile test_hello_world_test

Train your own model

bazel build tensorflow/lite/micro/examples/hello_world:train
bazel-bin/tensorflow/lite/micro/examples/hello_world/train --save_tf_model 
--save_dir=/tmp/model_created/
bazel build tensorflow/lite/micro/examples/hello_world/quantization:ptq
bazel-bin/tensorflow/lite/micro/examples/hello_world/quantization/ptq  
--source_model_dir=/tmp/model_created --target_dir=/tmp/quant_model/

这样,就在/tmp/quant_model/下生成了量化后的模型参数,用下列代码转换成Arduino可以运行的模型参数:

import os
path = "/tmp/quant_model"
os.chdir(path)
print(os.getcwd())
!apt get -qq install xxd
!xxd -i hello_world_int8.tflite > hello.cc
!cat hello.cc

在Arduino Nano 33 BLE Sense Rev2上运行

在Arduino IDE里打开Harvard_TinyMLx下的hello world工程,将里面的model.cpp里面的模型替换为上面生成的模型,编译上传即可看到呼吸灯了。
打开串品绘图窗口,如下:
在这里插入图片描述


http://www.ppmy.cn/ops/25679.html

相关文章

文件分块+断点续传 实现大文件上传全栈解决方案(前端+nodejs)

1. 文件分块 将大文件切分成较小的片段(通常称为分片或块),然后逐个上传这些分片。这种方法可以提高上传的稳定性,因为如果某个分片上传失败,只需要重新上传该分片而不需要重新上传整个文件。同时,分片上传…

JSON和Python内置的数据类型对应关系

Json JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,它基于ECMAScript的一个子集,采用完全独立于语言的文本格式来存储和表示数据。Python则是一种解释型、面向对象、动态数据类型的高级程序设计语言。在Python中&…

TinyMaix在x210开发板上的移植

目录 说明 环境准备 编译代码 源程序下载 修改tm_port.文件 修改CMake文件 测试程序运行 说明 我们教学中使用的x210开发板使用S5PV210这款CPU,它是根据三星的smdkv210开发板进行裁剪设计的,这个开发板非常的老了,不过在有经费购买新…

Linux基础——Linux开发工具(上)_vim

前言:在了解完Linux基本指令和Linux权限后,我们有了足够了能力来学习后面的内容,但是在真正进入Linux之前,我们还得要学会使用Linux中的几个开发工具。而我们主要介绍的是以下几个: yum, vim, gcc / g, gdb, make / ma…

树莓派5用docker运行Ollama3

书接上回,树莓派5使用1panel安装 Ollama 点击终端就可以进入容器 输入以下代码 ollama run llama3Llama3 是市场推崇的版本。您的 树莓派5上必须至少有 4.7GB 的可用空间,因此用树莓派玩机器学习就必须配置大容量的固态硬盘。用1panel部署网络下载速度…

LinkedList与链表

文章目录 ArrayList的缺陷链表链表的概念及结构链表的实现 LinkedList的使用什么是LinkedListLinkedList具体使用 ArrayList和LinkedList的区别 ArrayList的缺陷 通过源码知道,ArrayList底层使用数组来存储元素 由于其底层是一段连续空间,当在ArrayList任…

【MySQL】A01、性能优化-参数监控分析

1、参数监控 1.1、MySQL command 查看 mysql>SHOW STATUS; (服务器状态变量,运行服务器的统计和状态指标) mysql> SHOW VARIABLES;(服务器系统变量,实际上使用的变量的值) mysql> SHOW STATUS …

数据结构––复杂度

目录 一.时间复杂度 1.1定义 1.2时间复杂度的分类 1.3时间复杂度基本计算规则 1.4例子 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.4.10 1.4.11 1.4.12 1.4.13 二.空间复杂度 2.1定义 2.2推导大O阶方法 一.时间复杂度 1.1定义 算法的时间…