首页 > 解决方案 > 如何使用图像作为 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 文件是否要求数据格式相同?

标签: javaandroidtensorflowkerasdeep-learning

解决方案


推荐阅读