Skip to content

华为NPU后端构建OM模型失败:SetInputs failed: input operator size can not be 0(YOLO11n模型) #4028

@Cat-myq

Description

@Cat-myq

环境信息

  • 设备:华为Mate 40(HarmonyOS)
  • 模型:YOLO11n(导出ONNX后转MNN)
  • 后端:华为NPU(HIAI DDK版本:100.522.020.100)

复现步骤

  1. 导出ONNX模型
    yolo export model=best.pt format=onnx
  2. 转换为MNN模型
    mnnconvert -f ONNX --modelFile best.onnx --MNNModel best.mnn --bizCode biz
  3. NPU推理代码(核心片段):
    g_net = std::unique_ptr<Module>(Module::load({}, {}, model_path, g_rtmgr));
    // ... 图像预处理(resize、归一化等) ...
    auto input = _Unsqueeze(resized_var, {0});             // [1,3,640,640]
    input = _Convert(input, NC4HW4);                      // 格式转换为NC4HW4
    auto outputs = g_net->onForward({input});
    // ... 后续处理 ...

错误日志

MNNJNI         mOutputOps : 1 
HIAI_DDK_MSG   graph_impl.cpp SetInputs(56)::"SetInputs failed: input operator size can not be 0."
HIAI_DDK_MSG   graph.cpp SetInputs(44)::"SetInputs failed!"
HIAI_DDK_MSG   graph_impl.cpp SetOutputs(65)::"Build Graph failed."
HIAI_DDK_MSG   graph.cpp SetOutputs(51)::"SetOutputs failed!"
MNNJNI         [NPU] Model save failed 
AI_FMK         hiai_c_version.cpp HIAI_GetVersion_Config(16)::"AI_GetVersion_Config ERROR __system_property_get <= 0"
HIAI_DDK_MSG   hiai_ir_build.cpp CreateModelBuff(258)::"use createV2."
AI_FMK         hiai_c_mem_buffer.cpp HIAI_MemBuffer_createV2(167)::"AI_MemBuffer_create_from_size [ok]"
MNNJNI         [NPU] IR model build failed  

问题分析

  1. MNN模型结构:通过MNNConvert --JsonFile查看,模型是包含Input算子的(name: in0, dims: [1,3,640,640])。
  2. NPU后端构建OM模型时,原始Input算子未被纳入计算图链路,导致input operator size can not be 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions