文章目录
前言
本文介绍了如何在windows使用docker-destop运行 tflite-micro 的示例项目。
一、tflite-micro是什么?
TFLite Micro 是 Google 推出的 TensorFlow Lite 的一个特殊版本,专门用于在资源受限的嵌入式设备上运行机器学习模型。它旨在提供高效的模型推理能力,适用于诸如微控制器和嵌入式系统之类的设备,这些设备通常具有较低的计算和内存资源。
TFLite Micro 提供了针对微控制器等设备的优化模型推理框架,可以在这些设备上运行小型模型,例如用于音频处理、姿态识别、简单的图像识别等任务的模型。它还提供了一套 C++ 接口,使开发者可以在这些设备上方便地集成和运行自己的机器学习模型。
总的来说,TFLite Micro 使得在资源受限的嵌入式设备上部署和运行机器学习模型变得更加容易和高效。
二、安装Docker-Desktop
下载和安装docker-desktop, 下载地址如下
https://www.docker.com/products/docker-desktop/
三、运行tflite-micro 示例项目
1. 克隆 tflite-micro 项目
在 git bash 键入
git clone https://github.com/tensorflow/tflite-micro.git
2.进入项目文件夹创建dockerfile文件
cd tflite-micro
在项目文件夹下面创建dockerfile 文件,内容如下
FROM ubuntu:22.04
WORKDIR /app
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN sed -i s@/security.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN apt-get clean
RUN apt-get update
RUN apt-get install -y python3 python3-pip && \
apt-get install patchelf
RUN apt-get install -y gcc g++ make
RUN apt-get install apt-transport-https curl gnupg -y
RUN curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-archive-keyring.gpg
RUN mv bazel-archive-keyring.gpg /usr/share/keyrings
RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list
RUN apt-get update && apt-get install -y bazel-7.0.0
3. 构建docker镜像,创建并运行容器
启动docker-destop软件
在cmd命令窗口,在项目文件夹下,运行下面的命令构建镜像
docker build -t tflite_micro_image .
在cmd命令窗口,运行下面的命令创建并运行容器容器
docker run -d -it -v %cd%:/app --name tflite_micro tflite_micro_image
4. 进入docker容器构建项目
进入容器
docker exec -it tflite_micro bash
构建micro_speech项目示例项目代码,并运行编译文件
bazel-7.0.0 build tensorflow/lite/micro/examples/micro_speech:audio_preprocessor_test
bazel-bin/tensorflow/lite/micro/examples/micro_speech/audio_preprocessor_test
补充
在项目中官方提供了一些其他的AI示例项目,可根据对应项目下的README.md文件自行探索。
总结
tflite-micro 是使用C/C++编写的AI库,包含必要的静态库。您可以在轻松的在您的C/C++嵌入式项目中整合AI模块。本文旨在介绍了如何在windows上使用docker 运行 tflite-micro 示例代码,它可以作为您精通tflite-micro第一步,希望对大家有所帮助。如果文章中存在任何问题、疏漏,或者您对文章有任何建议,请在评论区提出。