You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android部署.pb模型报错:无支持DT_UINT8的TensorArrayWriteV3 OpKernel

Android部署TensorFlow .pb模型报错:No OpKernel registered for TensorArrayWriteV3 with DT_UINT8

错误日志

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.lancer.photopainting, PID: 28374
    java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'TensorArrayWriteV3' with these attrs.  Registered devices: [CPU], Registered kernels:
      device='CPU'; T in [DT_BOOL]
      device='CPU'; T in [DT_FLOAT]
      device='CPU'; T in [DT_INT32]

         [[Node: map_4/while/TensorArrayWrite/TensorArrayWriteV3 = TensorArrayWriteV3[T=DT_UINT8, _class=["loc:@map_4/while/convert_image"]](map_4/while/TensorArrayWrite/TensorArrayWriteV3/Enter, map_4/while/Identity_1, map_4/while/convert_image, map_4/while/Identity_2)]]
        at org.tensorflow.Session.run(Native Method)
        at org.tensorflow.Session.access$100(Session.java:48)
        at org.tensorflow.Session$Runner.runHelper(Session.java:298)
        at org.tensorflow.Session$Runner.run(Session.java:248)
        at org.tensorflow.contrib.android.TensorFlowInferenceInterface.run(TensorFlowInferenceInterface.java:228)
        at org.tensorflow.contrib.android.TensorFlowInferenceInterface.run(TensorFlowInferenceInterface.java:197)
        at org.tensorflow.contrib.android.TensorFlowInferenceInterface.run(TensorFlowInferenceInterface.java:187)
        at com.lancer.photopainting.utils.PredictionTF.stylizeImage(PredictionTF.java:69)
        at com.lancer.photopainting.utils.PredictionTF.getPredict(PredictionTF.java:50)
        at com.lancer.photopainting.MainActivity.lambda$initActivity$3$com-lancer-photopainting-MainActivity(MainActivity.java:103)
        at com.lancer.photopainting.MainActivity$$ExternalSyntheticLambda3.onClick(Unknown Source:2)
        at android.view.View.performClick(View.java:7506)
        at android.view.View.performClickInternal(View.java:7483)
        at android.view.View.access$3600(View.java:838)
        at android.view.View$PerformClick.run(View.java:28730)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:236)
        at android.app.ActivityThread.main(ActivityThread.java:8164)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
I/Process: Sending signal. PID: 28374 SIG: 9

问题原因

当前使用的TensorFlow Android库CPU版本,仅为TensorArrayWriteV3算子注册了DT_BOOL、DT_FLOAT、DT_INT32三种数据类型的实现,但模型中使用了DT_UINT8类型,导致找不到匹配的算子执行逻辑。

解决方案

  • 转换模型数据类型:在模型训练或导出阶段,将涉及TensorArrayWriteV3的节点数据类型替换为支持的类型(优先推荐DT_FLOAT)。比如处理图像输入时,先将uint8格式的像素值归一化为0-1之间的float32数据,再传入模型。
  • 检查模型导出流程:如果用TensorFlow 1.x导出.pb模型,确认freeze_graph等工具的参数是否正确,是否无意保留了uint8类型的节点。可以用summarize_graph工具查看模型节点的类型信息,定位具体的uint8节点。
  • 升级TensorFlow依赖:尝试更新Android项目中依赖的TensorFlow库版本,较新版本的TensorFlow可能已经支持uint8类型的TensorArrayWriteV3算子。如果可以切换到TensorFlow Lite,将模型转换为.tflite格式后部署,兼容性会更好。
  • 自定义算子(不推荐新手):如果必须保留uint8类型,需要自行实现CPU版本的TensorArrayWriteV3算子,并编译进TensorFlow Android库,这个过程需要熟悉TensorFlow算子开发和NDK编译,复杂度较高。

排查步骤

  1. 在PC端用TensorFlow加载该.pb模型,运行推理测试,确认模型本身在桌面端是否能正常执行,排除模型结构损坏的可能。
  2. 使用summarize_graph --in_graph=your_model.pb命令,查看模型的输入输出节点及所有节点的数据类型,精准定位使用DT_UINT8的节点位置。

内容的提问来源于stack exchange,提问作者lancer2ooo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 15:45:23