android + tflite 分类APP开发-1

使用自己的数据集训练模型进行图像分类

安装Model Maker 软件包

复制代码
sudo apt -y install libportaudio2pip install -q tflite-model-maker

准备数据集

文件夹下各类别子文件夹,图片文件

导入包

复制代码
import os

import numpy as np

import tensorflow as tf
assert tf.__version__.startswith('2')

from tflite_model_maker import model_spec
from tflite_model_maker import image_classifier
from tflite_model_maker.config import ExportFormat
from tflite_model_maker.config import QuantizationConfig
from tflite_model_maker.image_classifier import DataLoader

import matplotlib.pyplot as plt

运行

复制代码
data = DataLoader.from_folder(image_path)
train_data, test_data = data.split(0.9)

model = image_classifier.create(train_data)

loss, accuracy = model.evaluate(test_data)

model.export(export_dir='.')

导出模型即为tflite格式的文件

相关推荐
ragnwang1 天前
Notes: Python pybind11 import C++ module
开发语言·c++·python
王中阳Go1 天前
后端转 Agent 岗面试怎么答:8 个高频问题与应答口径
人工智能·后端·python·大语言模型
weixin_307779131 天前
RAG 面试陷阱——混合检索并非无条件优越:一个条件反转实验
人工智能·python·面试·职场和发展
云和数据.ChenGuang1 天前
深入解析 Python 的 dir():从用法到 CPython 源码实现
开发语言·人工智能·python·langchain
荣码1 天前
长上下文与大文档处理:200页PDF怎么喂给AI,我踩了4个坑
java·python
databook1 天前
Pandas 与 Polars:语法、性能和资源占用方面的对比
python·数据分析·pandas
威哥爱编程1 天前
Python 智能体开发实战 10:本地跑得好好的,一并发就崩?把它做成一个能上线的服务
python·agent
威哥爱编程1 天前
Python 智能体开发实战 09:改了提示词,到底是变好还是变坏?搭一套能打分的离线评测
python·agent
meiying88381 天前
多快递公司快递单号批量查询接口怎么对接?Python 聚合查询实现
java·大数据·python
Hello_Pyhx1 天前
Deep-Live-Cam 源码配置思路:环境、模型与执行后端分开排查
python