tract_onnx_opl/
lib.rs

1#![allow(clippy::len_zero)]
2
3use tract_nnef::internal::*;
4
5pub mod is_inf;
6pub mod is_nan;
7pub mod lrn;
8pub mod ml;
9pub mod multinomial;
10pub mod non_max_suppression;
11pub mod random;
12
13pub trait WithOnnx {
14    fn with_onnx(self) -> Self;
15    fn enable_onnx(&mut self);
16}
17
18impl WithOnnx for tract_nnef::framework::Nnef {
19    fn enable_onnx(&mut self) {
20        self.enable_tract_core();
21        self.registries.push(onnx_opl_registry());
22    }
23    fn with_onnx(mut self) -> Self {
24        self.enable_onnx();
25        self
26    }
27}
28
29pub fn onnx_opl_registry() -> Registry {
30    let mut registry: Registry = Registry::new("tract_onnx")
31        .with_doc("Extension `tract_onnx` extends NNEF for supporting some corner case ONNX operators.")
32        .with_doc("")
33        .with_doc("Add `extension tract_onnx` to `graph.nnef`");
34    ml::register(&mut registry);
35    non_max_suppression::register(&mut registry);
36    multinomial::register(&mut registry);
37    random::register(&mut registry);
38    registry.register_element_wise(
39        "tract_onnx_isinf",
40        TypeId::of::<is_inf::IsInf>(),
41        Box::new(is_inf::dump),
42        is_inf::parameters(),
43        is_inf::load,
44    );
45    registry.register_unit_element_wise("tract_onnx_is_nan", &is_nan::IsNan {});
46    registry.register_dumper(lrn::dump);
47    registry.register_primitive(
48        "tract_onnx_lrn",
49        &lrn::parameters(),
50        &[("output", TypeName::Scalar.tensor())],
51        lrn::load,
52    );
53    registry
54}