The TensorFlow Blog 09月12日
TensorFlow Lite插件迁移至Flutter官方仓库
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

TensorFlow Lite插件已正式迁移至TensorFlow GitHub官方仓库。三年前,Google Summer of Code贡献者Amish Garg开发的插件因受欢迎而被迁移,并由Google团队直接维护。社区开发者更新了最新版TensorFlow Lite,并添加了新功能和示例应用,如通过实时摄像头进行物体检测。TensorFlow Lite支持在移动、嵌入式、网络和边缘设备上本地运行TensorFlow模型,其跨平台支持和设备端性能优化使其成为Flutter开发工具箱的绝佳补充。该插件旨在简化TensorFlow Lite模型在Flutter移动应用中的集成,桌面支持目前正在由开发者社区开发。用户可在Kaggle Models等模型仓库中找到预训练的TensorFlow Lite模型,或创建自己的自定义模型。

🔧 TensorFlow Lite插件已迁移至TensorFlow官方GitHub仓库,由Google团队直接维护,便于更新和社区支持。

📈 该插件支持在移动、嵌入式、网络和边缘设备上本地运行TensorFlow模型,优化了设备端性能,适合Flutter开发。

🚀 社区开发者更新了最新版TensorFlow Lite,添加了新功能和示例应用,如实时摄像头物体检测,增强了实用性。

📚 用户可从Kaggle Models等模型仓库获取预训练模型,或创建自定义模型,简化了模型集成过程。

🤝 Google计划推出新的MediaPipe Tasks插件,支持低代码实现图像分类、物体检测、音频分类、人脸检测和手势识别等多种任务。

Posted by Paul Ruiz, Developer Relations Engineer

We're excited to announce that the TensorFlow Lite plugin for Flutter has been officially migrated to the TensorFlow GitHub account and released!

Three years ago, Amish Garg, one of our talented Google Summer of Code contributors, wrote a widely used TensorFlow Lite plugin for Flutter. The plugin was so popular that we decided to migrate it to our official repo, making it easier to maintain directly by the Google team. We are grateful to Amish for his contributions to the TensorFlow Lite Flutter plugin.

Through the efforts of developers in the community, the plugin has been updated to the latest version of TensorFlow Lite, and a collection of new features and example apps have been added, such as object detection through a live camera feed.

So what is TensorFlow Lite? TensorFlow Lite is a way to run TensorFlow models on devices locally, supporting mobile, embedded, web, and edge devices. TensorFlow Lite’s cross-platform support and on-device performance optimizations make it a great addition to the Flutter development toolbox. Our goal with this plugin is to make it easy to integrate TensorFlow Lite models into Flutter apps across mobile platforms, with desktop support currently in development through the efforts of our developer community. Find pre-trained TensorFlow Lite models on model repos like Kaggle Models or create your own custom TensorFlow Lite models.

Let’s take a look at how you could use the Flutter TensorFlow Lite plugin for image classification:

TensorFlow Lite Image Classification with Flutter

First you will need to install the plugin from pub.dev. Once the plugin is installed, you can load a TensorFlow Lite model into your Flutter app and define the input and output tensor shapes. If you’re using the MobileNet model, then the input tensor will be a 224 by 224 RGB image, and the output will be a list of confidence scores for the trained labels.

// Load modelFuture<void> loadModel() async { final options = InterpreterOptions(); // Load model from assets interpreter = await Interpreter.fromAsset(modelPath, options: options); // Get tensor input shape [1, 224, 224, 3] inputTensor = interpreter.getInputTensors().first; // Get tensor output shape [1, 1001] outputTensor = interpreter.getOutputTensors().first;}
To make things a bit more organized, you can also load in the labels for the 1000 items that MobileNet is trained for:

// Load labels from assetsFuture<void> <span class="hljs-title function">loadLabels() async { final labelTxt = await rootBundle.loadString(labelsPath); labels = labelTxt.split('\n');}

For the sake of being succinct, let’s go ahead and skip some of the pre-processing steps, though you can find them in the repo’s image classification example here.

When you’re ready to run inference, you can create a new input and output based on the tensor shapes that you defined earlier, then call run on the interpreter to get your final results.

// Run inference Future<void> <span class="hljs-title function">runInference( List<List<List<num>>> imageMatrix, ) async { // Tensor input [1, 224, 224, 3] final input = [imageMatrix]; // Tensor output [1, 1001] final output = [List<int>.filled(1001, 0)];   // Run inference   interpreter.run(input, output);   // Get first output tensor   final result = output.first;

Now that you have your results, you can match them to your labels and use them in your app.

What’s next?

To explore what else you can do with the Flutter TensorFlow Lite plugin, check out the official GitHub repository where you can find examples for text classification, super resolution, style transfer, and more!

Additionally, we are working on a new plugin specifically for MediaPipe Tasks, a low-code tool for easily performing common on-device machine learning tasks. This includes image classification and object detection, like you’ve just learned about, as well as audio classification, face landmark detection, and gesture recognition, alongside a whole lot more.

We look forward to all the exciting things you make, so be sure to share them with @googledevs, @TensorFlow, and your developer communities!

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

TensorFlow Lite Flutter Google GitHub 机器学习 模型集成 MediaPipe Tasks
相关文章