【问题标题】:Failed to apply delegate :TFlite crash in android无法应用委托:Android 中的 TFlite 崩溃
【发布时间】:2021-09-13 09:26:56
【问题描述】:

当我尝试使用 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


    【解决方案1】:

    我正在使用此代码来委托 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 语言

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-13
      • 1970-01-01
      • 2011-09-02
      • 2017-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多