应用委托失败:TFlite 在 android 中崩溃

问题描述 投票:0回答:2

当我尝试使用

tflite GPU
时,我的应用程序崩溃了。我正在使用此处的
MoveNet
模型 click。我在 CPU 中运行这个模型没有出现错误。

这是我的解释器初始化代码。

            val compatList = CompatibilityList()


            val options = Interpreter.Options().apply{
                if(compatList.isDelegateSupportedOnThisDevice){
                    // if the device has a supported GPU, add the GPU delegate
                    val delegateOptions = compatList.bestOptionsForThisDevice
                    this.addDelegate(GpuDelegate(delegateOptions))
                } else {
                    // if the GPU is not supported, run on 4 threads
                    this.setNumThreads(8)
                }
            }
           interpreter = Interpreter(loadTFFile(),options)

gradle(模块):

implementation 'org.tensorflow:tensorflow-lite:2.3.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.3.0'
implementation 'org.tensorflow:tensorflow-lite-support:0.1.0'

错误:

java.lang.IllegalArgumentException: Internal error: Failed to apply delegate: Following operations are not supported by GPU delegate:
    ARG_MAX: Operation is not supported.
    CAST: Operation is not supported.
    CONCATENATION: OP is supported, but tensor type isn't matched!
    DEQUANTIZE: 
    FLOOR_DIV: Operation is not supported.
    GATHER_ND: Operation is not supported.
    MUL: OP is supported, but tensor type isn't matched!
    PACK: Operation is not supported.
    RESHAPE: OP is supported, but tensor type isn't matched!
    SUB: OP is supported, but tensor type isn't.

我正在 Android 8.1 上测试此功能

android tensorflow-lite
2个回答
0
投票

我正在使用此代码来委托 tflite 模型,并且它正在工作。

tfliteModel = FileUtil.loadMappedFile(activity, this.getModelPath())
    tfliteOptions.setNumThreads(numThreads)
    tflite =
        try {
            val options = Interpreter.Options()
            options.addDelegate(NnApiDelegate())
            Interpreter(tfliteModel, options)
        } catch (e: Exception) {
            e.printStackTrace()
            try {
                val options = Interpreter.Options()
                options.addDelegate(GpuDelegate())
                Interpreter(tfliteModel, options)
            } catch (e: Exception) {
                val options = Interpreter.Options()
                try {
                    Interpreter(tfliteModel, options)
                } catch (e: Exception) {
                    e.printStackTrace()
                    null
                }
            }
        }

这是 kotlin 语言


0
投票

发生在我身上,因为我没有将以下内容添加到 Andorid Manifest:

<uses-feature android:glEsVersion="0x00020000" android:required="true" />
© www.soinside.com 2019 - 2024. All rights reserved.