{"record":{"id":"2f11942ad55b6fac","repo":"tonhowtf/omniget","slug":"n-o-li-a-sa-da-do-modelo-e","errorCode":null,"errorMessage":"não li a saída do modelo: {e}","messagePattern":"não li a saída do modelo: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/img_bg.rs","lineNumber":385,"sourceCode":"/// 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,\n    ))\n}\n","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/img_bg.rs#L367-L403","documentation":"This error wraps a failure from `outputs[0].try_extract_tensor::<f32>()` — the session output could not be read as an f32 tensor. ORT raises this when the output's element type is not f32 (e.g. int64, f16, f64) or the value cannot be viewed as a dense tensor of the requested type.","triggerScenarios":"Indexing `outputs[0]` and requesting an f32 tensor when the model's first output has a different dtype, or the output entry does not exist at index 0 (model exposes a different output order), or the output is a sequence/map rather than a tensor.","commonSituations":"Swapping in a different segmentation model whose output is f16 or uint8; an exporter that produced int64 masks; picking the wrong graph output index after a model conversion.","solutions":["Check the model's declared output dtype and extract the matching type (f16 -> half crate, i64, u8) before converting to f32","Inspect `session.outputs` to confirm index 0 is the mask tensor with f32 dtype","Export/convert the model with output cast to float32 if you control the ONNX export","Match outputs by name instead of positional index to avoid order surprises"],"exampleFix":"// before\nlet (shape, raw) = outputs[0].try_extract_tensor::<f32>()?;\n// after\nlet out = &outputs[0];\nlet (shape, raw) = out.try_extract_tensor::<f32>()\n    .or_else(|_| out.try_extract_tensor::<f64>().map(|(s, d)| (s, d.iter().map(|&v| v as f32).collect())))\n    .map_err(|e| anyhow!(\"não li a saída do modelo: {e}\"))?;","handlingStrategy":"type-guard","validationCode":"let out_ty = session.outputs[0].output_type.tensor_type();\nif out_ty != ort::tensor::TensorElementType::Float32 {\n    return Err(anyhow!(\"saída do modelo não é f32: {:?}\", out_ty));\n}","typeGuard":"fn extract_f32(out: &ort::session::builder::DynValue) -> Option<(Vec<i64>, Vec<f32>)> {\n    out.try_extract_tensor::<f32>().ok()\n}","tryCatchPattern":"match outputs[0].try_extract_tensor::<f32>() {\n    Ok((shape, raw)) => (shape, raw),\n    Err(e) => return Err(anyhow!(\"não li a saída do modelo ({:?}): {e}\", session.outputs[0].output_type)),\n}","preventionTips":["Check session.outputs dtypes when adding support for a new model","Reference outputs by name, not positional index","Cast non-f32 outputs (f16/i64) explicitly before extraction"],"tags":["onnx","dtype","ort","output"],"backgroundTag":"dtype-mismatch","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"}