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

使用SNPE的snpe-tflite-to-dlc转换.tflite至.dlc时触发TypeError

问题描述

在WSL Ubuntu 20.04的Python 3.8虚拟环境中,使用tflite 2.3.1版本,通过snpe-tflite-to-dlc工具将.tflite模型转换为.dlc格式时,触发以下错误:

2024-04-12 11:25:29,364 - 230 - ERROR - Encountered Error: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
Traceback (most recent call last):
  File "/mnt/c/Qualcomm/AIStack/SNPE/2.20.0.240223/bin/x86_64-linux-clang/snpe-tflite-to-dlc", line 51, in main
    converter = TFLiteConverterFrontend(args)
File"/mnt/c/Qualcomm/AIStack/SNPE/2.20.0.240223/lib/python/qti/aisw/converters/tflite/tflite_to_ir.py", line 23, in __init__
    super(TFLiteConverterFrontend, self).__init__(args,
  File "/mnt/c/Qualcomm/AIStack/SNPE/2.20.0.240223/lib/python/qti/aisw/converters/relay/relay_to_ir.py", line 324, in __init__
    self.importer.convert_to_relay(self.input_model_path,
  File "/mnt/c/Qualcomm/AIStack/SNPE/2.20.0.240223/lib/python/qti/aisw/converters/relay/importers/tflite_importer.py", line 115, in convert_to_relay
    self.mod, self.params = tflite_to_relay.from_tflite(tflite_model,
  File "/mnt/c/Qualcomm/AIStack/SNPE/2.20.0.240223/lib/python/qti/tvm/relay/frontend/tflite.py", line 4608, in from_tflite
    tensor = subgraph.Tensors(tensor_idx)
  File "/home/rosemol_30/PYTHON3.8_VENV_ROOT/lib/python3.8/site-packages/tflite/SubGraph.py", line 26, in Tensors
    x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

已尝试更换不同TensorFlow和tflite版本,问题仍未解决。

可能的解决方案
  • 检查.tflite模型完整性:错误来自flatbuffers解析环节,大概率是模型文件损坏或生成不完整。重新导出.tflite模型,确保导出过程无报错,并用tflite.Interpreter测试模型能否正常加载。
  • 匹配SNPE与tflite版本兼容性:SNPE 2.20.0对tflite版本有特定支持范围,不要随意混用。建议尝试tflite 2.8.0或2.10.0(这两个版本在SNPE 2.x中兼容性较好),同时确保虚拟环境中仅保留指定版本的tflite,避免版本冲突。
  • 切换到SNPE自带Python环境:当前错误显示SNPE自带的tflite解析逻辑与虚拟环境中的tflite/SubGraph.py产生冲突。尝试退出自定义虚拟环境,加载SNPE环境变量(执行source $SNPE_ROOT/bin/envsetup.sh)后直接运行转换命令。
  • 重新安装SNPE:如果是SNPE安装不完整导致的依赖缺失,重新下载官方SNPE包,按步骤重新部署,确保flatbuffers、tvm等组件正确安装。
  • 验证模型张量定义:用Netron工具打开.tflite模型,确认所有输入输出张量的名称、维度、数据类型均规范,避免存在空名称、未明确维度的张量。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 23:12:45