W __init__: rknn-toolkit2 version: 1.6.0+81f21f4d --> Loading model W load_onnx: It is recommended onnx opset 19, but your onnx model opset is 17! W load_onnx: Model converted from pytorch, 'opset_version' should be set 19 in torch.onnx.export for successful convert! Loading : 100%|████████████████████████████████████████████████| 202/202 [00:00<00:00, 44980.33it/s] W load_onnx: The config.mean_values is None, zeros will be set for input 0! W load_onnx: The config.std_values is None, ones will be set for input 0! done -->Building model E RKNN: [09:34:02.762] REGTASK: The bit width of field value exceeds the limit, target: v2, offset: 0x5048, shift = 19, limit: 0x1fff, value: 0x2e30 E RKNN: [09:34:02.762] REGTASK: The bit width of field value exceeds the limit, target: v2, offset: 0x4038, shift = 0, limit: 0x1fff, value: 0x2e30 E RKNN: [09:34:02.762] REGTASK: The bit width of field value exceeds the limit, target: v2, offset: 0x4038, shift = 16, limit: 0x1fff, value: 0x2e30 E RKNN: [09:34:02.762] REGTASK: The bit width of field value exceeds the limit, target: v2, offset: 0x5048, shift = 19, limit: 0x1fff, value: 0x2e30 E RKNN: [09:34:02.762] REGTASK: The bit width of field value exceeds the limit, target: v2, offset: 0x4038, shift = 0, limit: 0x1fff, value: 0x2e30 E RKNN: [09:34:02.762] REGTASK: The bit width of field value exceeds the limit, target: v2, offset: 0x4038, shift = 16, limit: 0x1fff, value: 0x2e30 E RKNN: [09:34:02.762] REGTASK: The bit width of field value exceeds the limit, target: v2, offset: 0x5048, shift = 19, limit: 0x1fff, value: 0x3fe0 E RKNN: [09:34:02.762] REGTASK: The bit width of field value exceeds the limit, target: v2, offset: 0x4038, shift = 0, limit: 0x1fff, value: 0x3fe0 E RKNN: [09:34:02.762] REGTASK: The bit width of field value exceeds the limit, target: v2, offset: 0x4038, shift = 16, limit: 0x1fff, value: 0x3fe0 E RKNN: [09:34:02.765] emitCHW_C1HWC2_regtasks: align_surf overflow! E RKNN: [09:34:02.768] REGTASK: The bit width of fi
时间: 2025-03-23 20:20:14 浏览: 15
RKNN Toolkit2 中 Bit 宽度超出限制问题分析
在使用 RKNN-Toolkit2 进行模型转换的过程中,如果遇到 conversion error
提示 bit width exceeds limit
的错误消息,则可能是因为目标硬件不支持某些操作符的位宽配置。以下是对此问题的具体解析以及解决方案:
错误原因
该错误通常发生在尝试将高精度数据映射到低精度硬件时。RKNN 工具链中的量化过程会调整权重和激活值以适应目标设备的能力。然而,在某些情况下,特定层的操作可能会导致数值范围超出了目标硬件所能处理的最大位宽[^1]。
解决方案
为了有效解决此问题,可以采取以下几种方法之一或组合应用这些策略来规避错误:
降低输入张量的数据类型 如果原始模型采用的是较高精度的数据表示形式(如 float32),可以通过设置参数强制将其降至较低精度(int8 或 uint8)。这有助于减少整体计算所需的动态范围并避免溢出情况的发生。
from rknn.api import RKNN rknn = RKNN() ret = rknn.config(target_platform='rv1106', quantized_dtype='asymmetric_quantize-u8') # 设置为uint8模式
手动指定每层节点属性 对于那些容易引发上述异常的关键网络组件,可利用自定义选项逐一设定其行为特性。例如通过 JSON 文件或者 Python API 明确给出期望的行为准则。
{ "op": ["Conv"], "param": {"quantized_bit_width_limit": 8} }
更新至最新版本工具包 鉴于软件开发迭代周期较快的特点,较新发布的版本往往修复了许多已知缺陷并且增强了兼容性表现。因此建议定期检查官方仓库是否有可用升级版次可供下载安装。
git pull origin master pip install --upgrade .
调试日志审查 启用详尽的日志记录功能可以帮助定位具体哪一部分引发了冲突状况。借助这些线索进一步优化预处理脚本或是修改源码实现细节直至满足条件为止。
rknn.debug(enable=True, level="ALL")
以上措施能够显著提升成功完成转化的概率,同时改善最终部署效果的质量水平。
from rknn.api import RKNN
# 初始化实例对象
rknn = RKNN()
try:
# 加载ONNX文件
print('--> Loading model')
ret = rknn.load_onnx(model='./model.onnx')
if ret != 0:
raise Exception('Load failed!')
# 设定运行环境及相关参数
print('--> Configuring environment')
ret = rknn.config(
target_platform='rv1106',
optimization_level=3,
quantized_dtype='asymmetric_quantize-u8'
)
if ret != 0:
raise Exception('Config failed!')
# 执行实际转换动作
print('--> Building model')
ret = rknn.build(do_quantization=True)
finally:
# 清理资源释放内存空间
del rknn
相关推荐












