java - 如何使用图像作为 TFLite 模型的输入?
问题描述
我在 Keras 中训练了一个模型,然后将其保存并将其转换为 TFLite 文件。为了测试我的 Keras 模型,我使用以下代码将图像转换为 numpy 数组:
img_path = r'path'
img = image.load_img(img_path, color_mode="grayscale", target_size=(img_height, img_width))
img = image.img_to_array(img)
img = numpy.expand_dims(img, axis=0)
img = img.reshape(1, img_width, img_height, 1)
它将它放入形状(1、224、224、1)的 4d 数组中。我的问题是如何以相同的方式为 Android 上的 TFLite 模型准备数据?TFLite 文件是否要求数据格式相同?
解决方案
推荐阅读
- android - 在主线程中创建的处理程序就像在另一个线程上一样
- python - Tkinter 打开文件窗口,文件扩展名区分大小写
- php - 序列化如何访问私有属性
- laravel - Laravel 5.5 数据在数据库中被插入两次
- python - PyYAML 给出构造函数错误?
- grails - 第一次尝试导出excel时出错
- python - APIView的POST方法中的Django Rest Framework验证
- react-native - 通过 App 的后台服务 React Native 本地通知
- java - Spring Security:未调用自定义 UserDetailsService(使用 Auth0 身份验证)
- angular - 想要验证 Angular 表单,无论出现什么错误,按钮都会提交