{"record":{"id":"21dade9e711a5c44","repo":"tonhowtf/omniget","slug":"a-infer-ncia-falhou-e","errorCode":null,"errorMessage":"a inferência falhou: {e}","messagePattern":"a inferência falhou: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/img_bg.rs","lineNumber":382,"sourceCode":"// ── Execução ───────────────────────────────────────────────────────────\n\n/// Roda a inferência num arquivo já aberto e devolve a máscara no tamanho\n/// original da imagem.\nfn mask_for_image(\n    session: &mut ort::session::Session,\n    img: &DynamicImage,\n    p: &BgParams,\n) -> anyhow::Result<GrayImage> {\n    let side = p.size as i64;\n    // O `ort` traz um `ndarray` próprio (0.17) e o crate usa o 0.16, então o\n    // tensor atravessa a fronteira como forma + dados contíguos, que é o que o\n    // `Tensor::from_array` aceita sem depender de versão de crate nenhuma.\n    let (data, _) = normalize_input(img, p).into_raw_vec_and_offset();\n    let tensor = ort::value::Tensor::from_array((vec![1, 3, side, side], data))\n        .map_err(|e| anyhow!(\"não montei o tensor de entrada: {e}\"))?;\n    let outputs = session\n        .run(ort::inputs![tensor])\n        .map_err(|e| anyhow!(\"a inferência falhou: {e}\"))?;\n    let (shape, raw) = outputs[0]\n        .try_extract_tensor::<f32>()\n        .map_err(|e| anyhow!(\"não li a saída do modelo: {e}\"))?;\n    if shape.len() < 2 {\n        return Err(anyhow!(\n            \"saída do modelo com formato inesperado: {:?}\",\n            &shape[..]\n        ));\n    }\n    let h = shape[shape.len() - 2].max(0) as u32;\n    let w = shape[shape.len() - 1].max(0) as u32;\n    let small = mask_from_raw(raw, w, h)?;\n    let (ow, oh) = (img.width(), img.height());\n    Ok(image::imageops::resize(\n        &small,\n        ow,\n        oh,\n        FilterType::Lanczos3,","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/img_bg.rs#L364-L400","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Validate the model file (size/checksum) and confirm it is a U2Net/ISNet-style background-removal ONNX model","Compare the session's declared input shape/dtype (session.inputs) against the [1,3,side,side] f32 tensor being fed","Print the full chained ORT error (`{e:#}` or `{e:?}` with anyhow context) to see the underlying ORT status","Retry with the CPU execution provider to rule out GPU driver/EP issues; re-download the model if it is corrupt"],"exampleFix":"// before\nlet outputs = session.run(ort::inputs![tensor])?;\n// after\nlet outputs = session\n    .run(ort::inputs![\"input\" => tensor]) // bind by the model's actual input name\n    .map_err(|e| anyhow!(\"a inferência falhou: {e:#}\"))?;","handlingStrategy":"try-catch","validationCode":"if !model_path.exists() || model_path.metadata()?.len() < 1024 {\n    return Err(anyhow!(\"modelo ONNX ausente ou truncado: {}\", model_path.display()));\n}\nlet inp = &session.inputs[0];\nif inp.input_type.tensor_type() != ort::tensor::TensorElementType::Float32 {\n    return Err(anyhow!(\"modelo espera dtype diferente de f32\"));\n}","typeGuard":null,"tryCatchPattern":"match session.run(ort::inputs![tensor]) {\n    Ok(outputs) => outputs,\n    Err(e) => {\n        log::error!(\"ORT inference failed: {e:#}\");\n        return Err(anyhow!(\"a inferência falhou: {e}\"));\n    }\n}","preventionTips":["Verify session.inputs shape/dtype against the tensor you build","Download models with checksum verification to avoid truncated files","Test inference once at startup with a tiny dummy image to fail fast"],"tags":["onnx","inference","ort","runtime"],"backgroundTag":"api-error-response","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}