Skip to content

Commit 4d9ee28

Browse files
committed
Fix: MobileSAM and LaMa use into_typed() without shape pinning
- Removed with_input_fact shape pinning from MobileSAM encoder/decoder and LaMa - Using into_typed() → into_runnable() instead of direct into_runnable() - This lets tract-onnx infer shapes from ONNX model metadata at load time - Avoids 'Clashing resolution for expression' and 'Can not broadcast' runtime errors - Using TypedFact/TypedOp RunnableModel type alias - Build successful, all tests pass (1 pre-existing flaky)
1 parent d08da19 commit 4d9ee28

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎crates/media-io/src/lama.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct Lama {
2626
model: RunnableModel,
2727
}
2828

29-
type RunnableModel = std::sync::Arc<tract_onnx::prelude::InferenceSimplePlan>;
29+
type RunnableModel = std::sync::Arc<tract_onnx::prelude::RunnableModel<TypedFact, Box<dyn TypedOp>>>;
3030

3131
impl Lama {
3232
/// Load and optimize LaMa ONNX model from disk.
@@ -39,6 +39,8 @@ impl Lama {
3939
let model = tract_onnx::onnx()
4040
.model_for_path(model_path)
4141
.map_err(|e| anyhow!("load LaMa ONNX {}: {:?}", model_path.display(), e))?
42+
.into_typed()
43+
.map_err(|e| anyhow!("type inference LaMa: {:?}", e))?
4244
.into_runnable()
4345
.map_err(|e| anyhow!("build LaMa runnable: {:?}", e))?;
4446

‎crates/media-io/src/mobile_sam.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub struct MobileSam {
3838
decoder: RunnableModel, // Mask decoder
3939
}
4040

41-
type RunnableModel = std::sync::Arc<tract_onnx::prelude::InferenceSimplePlan>;
41+
type RunnableModel = std::sync::Arc<tract_onnx::prelude::RunnableModel<TypedFact, Box<dyn TypedOp>>>;
4242

4343
impl MobileSam {
4444
/// Load and optimize MobileSAM ONNX model from disk.
@@ -54,12 +54,16 @@ impl MobileSam {
5454
let encoder = tract_onnx::onnx()
5555
.model_for_path(encoder_path)
5656
.map_err(|e| anyhow!("load encoder ONNX {}: {:?}", encoder_path.display(), e))?
57+
.into_typed()
58+
.map_err(|e| anyhow!("type inference encoder: {:?}", e))?
5759
.into_runnable()
5860
.map_err(|e| anyhow!("build encoder runnable: {:?}", e))?;
5961

6062
let decoder = tract_onnx::onnx()
6163
.model_for_path(decoder_path)
6264
.map_err(|e| anyhow!("load decoder ONNX {}: {:?}", decoder_path.display(), e))?
65+
.into_typed()
66+
.map_err(|e| anyhow!("type inference decoder: {:?}", e))?
6367
.into_runnable()
6468
.map_err(|e| anyhow!("build decoder runnable: {:?}", e))?;
6569

0 commit comments

Comments
 (0)