How does tract_onnx::tract_hir::ops::cnn::Conv
implement Op ?
#823
-
Hello ! Have been loving using the library so far. I'm currently loading up a simple single layer convolutional model, saved using pytorch. I then load up the saved model as such: let model = tract_onnx::onnx().model_for_path(path).unwrap(); I then iterate over the model nodes, call Source
Const
Const
ConvHir The first let op = node.op(); As expected if I print Conv { data_format: NCHW, kernel_fmt: OIHW, dilations: Some([1, 1]), kernel_shape: Some([5, 5]), padding: Explicit([1, 1], [1, 1], false), strides: Some([1, 1]), group: Some(1), x_scale_input: None, x_zero_point_input: None, k_input: None, k_scale_input: None, k_zero_point_input: None, y_scale_input: None, y_zero_point_input: None, bias_input: Some(2), override_output_datum_type: None } However the let conv_node: &Conv = match op.downcast_ref() {
Some(b) => b,
None => panic!("op isn't a Conv!"),
}; but get the following error: As a sanity check I also run assert!(op.is::<Conv>()); which also panics and fails. Would appreciate a pointer to which type I should be downcasting to. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Conv is defined in When you call |
Beta Was this translation helpful? Give feedback.
Conv is defined in
hir/src/ops/cnn/conv.rs
. It does not directly implements Op, it is anExpansion
instead. Defined inhir/src/ops/expandable.rs
. It is wrapped inBox<dyn Expansion>
which does implementsOp
andEvalOp
in a very inneficient way (by generic an equivalent network to eval itself).When you call
into_typed
(directly or throughinto_declutter
orinto_optimized
) the expansion expands to actualy convolution operators (most likely ConvUnary from tract-core).