专栏算法工具链模型量化时reshape推断失败,导致量化退化到batch=1,速度太慢

模型量化时reshape推断失败,导致量化退化到batch=1,速度太慢

阿白-西2026-04-17
63
7

平台信息:J6M,OE版本:3.7.1

错误描述:

模型中的一个reshape节点无法转为多batch,1x1x18x10 -> 1x1x1x180;报错为The input tensor cannot be reshaped to the requested shape. Input shape:{8,1,10,18}, requested shape:{1,1,1,180}

报错信息:

26-04-17 20:17:36.609067620 [E:onnxruntime:, sequential_executor.cc:516 ExecuteKernel] Non-zero status code returned while running Reshape node. Name:'Sigmoid_1505_onnx::Concat_2881_transpose_Reshape' Status Message: /onnxruntime_src/onnxruntime/core/providers/cpu/tensor/reshape_helper.h:45 onnxruntime::ReshapeHelper::ReshapeHelper(const onnxruntime::TensorShape&, onnxruntime::TensorShapeVector&, bool) input_shape_size == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{8,1,10,18}, requested shape:{1,1,1,180}

模型截图:

错误信息:

算法工具链
技术深度解析征程6
评论2
0/600
  • YCJ
    Lv.4

    这个是工具链在校准的时候尝试8 batch校准失败报的错,对后续的量化过程没有影响。工具链在校准的时候首先会尝试8 batch校准,如果你的onnx模型不支持8 batch推理会退回到单batch校准。

    2026-04-20
    0
    4
    • 阿白-西回复YCJ:

      input_batch设置为8是可以转出模型的,只是在量化过程中会退化到单batch,有没有通用的方法能解决量化时不支持8 batch的问题,这个reshape没有升/降维的操作

      2026-04-20
      0
    • YCJ回复阿白-西:
      2026-04-20
      0
    • 阿白-西回复YCJ:

      多batch的onnx,在input_type_rt设置为nv12时会报错,无法转模型

      2026-04-21
      0
    • YCJ回复阿白-西:

      报错信息贴一下,模型方便分享不?

      2026-04-21
      0
  • DR_KAN
    Lv.5

    原因是你pytorch算法里reshape把shape写死了,如果改成动态的,比如用-1,再导出onnx,就可以避免这个问题了

    2026-04-23
    0
    1
    • 阿白-西回复DR_KAN:

      我把shape的的dim0改为-1,现象是一样的

      2026-04-28
      0