tonhowtf/omniget · error
não montei o tensor de entrada: {e}
Error message
não montei o tensor de entrada: {e} What it means
This error wraps a failure from `ort::value::Tensor::from_array` when building the NCHW input tensor (shape [1,3,side,side]) for the background-removal ONNX model. The `ort` crate rejects the shape/data combination when the element count does not exactly match the declared shape, the data is not contiguous/aligned, or the type does not match the declared tensor type. It is thrown eagerly before any inference runs.
Solutions
- Verify `normalize_input` resizes to exactly p.size x p.size and produces 3 RGB channels as f32, so data.len() == 3*side*side
- Log data.len() and the expected 3*side*side next to the error to confirm the mismatch
- Check that p.size matches the ONNX model's declared input dimensions (inspect with `onnxruntime` tools or session.inputs)
- Keep the shape Vec and data produced from the same `p` value, not from stale/other params
Example fix
// before let (data, _) = normalize_input(img, p).into_raw_vec_and_offset(); let tensor = ort::value::Tensor::from_array((vec![1, 3, side, side], data))?; // after let input = normalize_input(img, p); assert_eq!(input.len(), (3 * side * side) as usize, "input buffer/shape mismatch"); let (data, _) = input.into_raw_vec_and_offset(); let tensor = ort::value::Tensor::from_array((vec![1, 3, side, side], data))?;
Defensive patterns
Strategy: validation
Validate before calling
let expected = 3 * p.size * p.size;
let input = normalize_input(img, p);
if input.len() != expected {
return Err(anyhow!("input buffer {} != expected {} (1x3x{}x{})", input.len(), expected, p.size, p.size));
} Type guard
fn is_valid_input(buf: &[f32], side: usize) -> bool {
buf.len() == 3 * side * side && buf.iter().all(|v| v.is_finite())
} Prevention
- Keep shape and data derived from the same params value
- Assert buffer length against 3*side*side in tests for normalize_input
- Never pass 4-channel RGBA buffers as 3-channel NCHW input
When it happens
Trigger: Calling `Tensor::from_array((vec![1, 3, side, side], data))` where `normalize_input` produced a buffer whose length != 3*side*side, or `p.size` disagrees with the actual resized image dimensions, or the f32 Vec was mis-shaped.
Common situations: A model config whose `size` parameter was changed without updating `normalize_input`; switching to a model with a different input resolution; a refactor of `normalize_input` returning a different channel order or count; passing an RGBA (4-channel) buffer instead of RGB (3-channel).
Understand the failure class
Background: Tensor shape mismatch errors ("must have shape", "expected shape ... got ..."): when tensor dimensions disagree with what an op or layer was told to expect — this error's family across 6 libraries.
Related errors
- não criei o builder de sessão ONNX: {e}
- não carreguei o modelo {}: {}
- o ONNX Runtime {} ainda não está instalado. Instale pela tel
- não existe build oficial do ONNX Runtime para este sistema.
- não consegui carregar {}: {}
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/26be7d2b5258776a.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/core/tools/img_bg.rs:379
Ok(std::fs::metadata(dest).map(|m| m.len()).unwrap_or(0))
}
// ── 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,View on GitHub (pinned to 8600b91f42)