huggingface / huggingface/candle

Tensor shape mismatch error when using candle-onnx with audio input

Open
#2,865 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
21k
Forks
1.8k
Avg merge
16h 42m
Merged PRs (30d)
25

Description

## Description
I'm encountering a tensor reshape error when trying to run inference on an audio model using `candle-onnx`. The error occurs during model evaluation despite the input tensor seemingly having the correct shape.

## Reproduction Code
```rust
let model = candle_onnx::read_file(MODEL).unwrap();
let graph = model.graph.as_ref().unwrap();
let input_tensor = Tensor::from_vec(audio[0..32000].to_vec(), (1, 32000), &Device::Cpu).unwrap();
let mut inputs: std::collections::HashMap = std::collections::HashMap::new();
inputs.insert(graph.input[0].name.to_string(), input_tensor);
let mut outputs = candle_onnx::simple_eval(&model, inputs).unwrap();
let output = outputs.remove(&graph.output[0].name).unwrap();
```

## Input Information
When printing the model input information:
```
Input dims: ValueInfoProto {
name: "input",
r#type: Some(TypeProto {
denotation: "",
value: Some(TensorType(Tensor {
elem_type: 1,
shape: Some(TensorShapeProto {
dim: [
Dimension { denotation: "", value: Some(DimValue(1)) },
Dimension { denotation: "", value: Some(DimValue(32000)) }
]
})
}))
}),
doc_string: ""
}
Input Tensor shape: Tensor[dims 1, 32000; f32]
```

## Error Message
```
thread 'main' panicked at src/main.rs:61:64:
called `Result::unwrap()` on an `Err` value: shape mismatch in reshape, lhs: [3], rhs: [1, 2]
```

## Environment
- Rust version: 1.85.1
- candle-onnx version: 0.8.4
- OS: Linux

## Additional Information
- The error happens during the `simple_eval` call, not during tensor creation
- The input tensor has the correct shape `[1, 32000]` as expected by the model
- The audio data is loaded from a WAV file
- The error seems to be from an internal reshaping operation where something is trying to reshape a tensor of shape [3] to [1, 2]

Any help or suggestions would be greatly appreciated!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.