tonhowtf/omniget · error
saída do modelo com formato inesperado
Error message
saída do modelo com formato inesperado: {:?} What it means
A hand-written validation error: the model's output tensor has fewer than 2 dimensions, so the code cannot take the last two dims as mask height/width. This indicates the selected ONNX file is not the expected image-matting model (which should emit an NCHW or at least [.., H, W] mask), or its output was misidentified.
Solutions
- Verify the model_id maps to the correct segmentation ONNX file and that outputs[0] is the mask output
- Check the model's output shapes offline (netron or session.outputs) — expect rank 4 like [1,1,H,W]
- If the model emits [N, C] logits, reshape/normalize before treating it as a spatial mask
- Re-download the correct model if the file was replaced or partially overwritten
Example fix
// before
if shape.len() < 2 {
return Err(anyhow!("saída do modelo com formato inesperado: {:?}", &shape[..]));
}
// after
if shape.len() < 4 || shape[1] != 1 {
return Err(anyhow!("saída do modelo com formato inesperado: {:?} — esperado [N,1,H,W]", &shape[..]));
} Defensive patterns
Strategy: validation
Validate before calling
let out_shape = session.outputs[0].output_type.tensor_shape();
if out_shape.rank() < 2 {
return Err(anyhow!("modelo incompatível: saída tem rank {}, esperado >= 2", out_shape.rank()));
} Type guard
fn is_spatial_mask(shape: &[i64]) -> bool {
shape.len() >= 2 && shape[shape.len() - 1] > 0 && shape[shape.len() - 2] > 0
} Try / catch
if !is_spatial_mask(&shape) {
return Err(anyhow!("saída do modelo com formato inesperado: {:?} — verifique se o model_id aponta para um modelo de segmentação", &shape[..]));
} Prevention
- Validate model output rank/shape when registering a new model_id in params_for
- Inspect new ONNX files with Netron before wiring them in
- Fail fast with a startup smoke test that checks output shape on a dummy input
When it happens
Trigger: `shape.len() < 2` after extracting outputs[0] — e.g. a model that returns a scalar, a 1-D class-probability vector, or when the wrong output index was picked.
Common situations: Using a classification model instead of a segmentation model; a model export that collapsed/omitted spatial dimensions; accidentally pointing `session_for` at a different ONNX file (wrong model_id to file mapping).
Related errors
- não parece a biblioteca do ONNX Runtime deste sistema…
- o modelo não serve para remover fundo
- No valid cookies found in file (expected Netscape format)
- Extension playlist is
- escolha a pasta de destino para organizar
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/b2b46361fefbd056.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/core/tools/img_bg.rs:387
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,
))
}
fn run_blocking(
opts: &BgOptions,View on GitHub (pinned to 8600b91f42)