【问题标题】:Data type input to tflite model does not match输入到 tflite 模型的数据类型不匹配
【发布时间】:2019-03-30 16:12:17
【问题描述】:

我用 python 制作了以下 SimpleRNN 模型。

python
#Omit
Xtest = np.zeros((1, 10, 1102))
#Omit
pred = model.predict(Xtest, verbose=0)[0]

如你所见,我使用了一个整数的三维数组作为模型的输入。

然后,我将此模型移植到 android 为 .tflite。 在下面的代码中,名为tfliteModel的部分是对应的。

kotlin
Interpreter(tfliteModel!!).use { interpreter ->
    val input_onehot = Array(1) { Array(10) {Array<Int>(1102) {0} } }
    val output = Array(1) {Array<Float>(1102) { 0F } }
    //some operation like making it a one hot vector
    interpreter.run(input_onehot, output)
}

但是 Android Studio 抛出了这样的错误:

Caused by: java.lang.IllegalArgumentException: DataType error: cannot resolve DataType of [[[Ljava.lang.Integer;

为什么会出现这个错误? 如何将整数数组加载到模型中?

我使用this site 作为参考。 但是,这是指图像而不是 NLP···

【问题讨论】:

    标签: android tensorflow kotlin


    【解决方案1】:

    我不知道为什么,但我通过读取为 float 而不是 int 解决了这个问题。 我用 np.int32··· 也许 numpy 的 int32 和 kotlin 的 Int32 可能不兼容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-18
      • 2020-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      相关资源
      最近更新 更多