tonhowtf/omniget · error

a inferência falhou

Error message

a inferência falhou: {e}

What it means

This error wraps a failure from `session.run(...)` — the ONNX Runtime failed to execute inference on the prepared input tensor. Typical underlying causes are input tensor metadata that does not match what the model's input signature expects (shape, dtype, or name), or an internal ORT execution failure (out of memory, provider error, corrupted model).

Solutions

  1. Validate the model file (size/checksum) and confirm it is a U2Net/ISNet-style background-removal ONNX model
  2. Compare the session's declared input shape/dtype (session.inputs) against the [1,3,side,side] f32 tensor being fed
  3. Print the full chained ORT error (`{e:#}` or `{e:?}` with anyhow context) to see the underlying ORT status
  4. Retry with the CPU execution provider to rule out GPU driver/EP issues; re-download the model if it is corrupt

Example fix

// before
let outputs = session.run(ort::inputs![tensor])?;
// after
let outputs = session
    .run(ort::inputs!["input" => tensor]) // bind by the model's actual input name
    .map_err(|e| anyhow!("a inferência falhou: {e:#}"))?;
Defensive patterns

Strategy: try-catch

Validate before calling

if !model_path.exists() || model_path.metadata()?.len() < 1024 {
    return Err(anyhow!("modelo ONNX ausente ou truncado: {}", model_path.display()));
}
let inp = &session.inputs[0];
if inp.input_type.tensor_type() != ort::tensor::TensorElementType::Float32 {
    return Err(anyhow!("modelo espera dtype diferente de f32"));
}

Try / catch

match session.run(ort::inputs![tensor]) {
    Ok(outputs) => outputs,
    Err(e) => {
        log::error!("ORT inference failed: {e:#}");
        return Err(anyhow!("a inferência falhou: {e}"));
    }
}

Prevention

When it happens

Trigger: Calling `session.run(ort::inputs![tensor])` when the [1,3,side,side] f32 tensor does not satisfy the model's declared input constraints (e.g. dynamic size the model doesn't accept, wrong dtype), or the ONNX model file is corrupt/incomplete, or the ORT execution provider fails at run time.

Common situations: Pointing the tool at an ONNX file that is not a valid background-removal model; running with a CUDA/DirectML EP whose drivers are missing; model expects a different input size than `params_for(model_id).size`; truncated model download.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/21dade9e711a5c44. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/img_bg.rs:382

// ── Execução ───────────────────────────────────────────────────────────

/// Roda a inferência num arquivo já aberto e devolve a máscara no tamanho
/// original da imagem.
fn mask_for_image(
    session: &mut ort::session::Session,
    img: &DynamicImage,
    p: &BgParams,
) -> anyhow::Result<GrayImage> {
    let side = p.size as i64;
    // O `ort` traz um `ndarray` próprio (0.17) e o crate usa o 0.16, então o
    // tensor atravessa a fronteira como forma + dados contíguos, que é o que o
    // `Tensor::from_array` aceita sem depender de versão de crate nenhuma.
    let (data, _) = normalize_input(img, p).into_raw_vec_and_offset();
    let tensor = ort::value::Tensor::from_array((vec![1, 3, side, side], data))
        .map_err(|e| anyhow!("não montei o tensor de entrada: {e}"))?;
    let outputs = session
        .run(ort::inputs![tensor])
        .map_err(|e| anyhow!("a inferência falhou: {e}"))?;
    let (shape, raw) = outputs[0]
        .try_extract_tensor::<f32>()
        .map_err(|e| anyhow!("não li a saída do modelo: {e}"))?;
    if shape.len() < 2 {
        return Err(anyhow!(
            "saída do modelo com formato inesperado: {:?}",
            &shape[..]
        ));
    }
    let h = shape[shape.len() - 2].max(0) as u32;
    let w = shape[shape.len() - 1].max(0) as u32;
    let small = mask_from_raw(raw, w, h)?;
    let (ow, oh) = (img.width(), img.height());
    Ok(image::imageops::resize(
        &small,
        ow,
        oh,
        FilterType::Lanczos3,

View on GitHub (pinned to 8600b91f42)