[−]Module tract_pulse::internal::tract_core
Tract
Tiny, no-nonsense, self contained, portable TensorFlow and ONNX inference.
Example
use tract_core::internal::*; // build a simple model that just add 3 to each input component let mut model = TypedModel::default(); let input_fact = TypedFact::dt_shape(f32::datum_type(), [3].as_ref()).unwrap(); let input = model.add_source("input", input_fact).unwrap(); let three = model.add_const("three".to_string(), tensor1(&[3f32])).unwrap(); let add = model.wire_node("add".to_string(), tract_core::ops::math::add::bin_typed(), [input, three].as_ref() ).unwrap(); model.auto_outputs().unwrap(); // We build an execution plan. Default inputs and outputs are inferred from // the model graph. let plan = SimplePlan::new(&model).unwrap(); // run the computation. let input = tensor1(&[1.0f32, 2.5, 5.0]); let mut outputs = plan.run(tvec![input]).unwrap(); // take the first and only output tensor let mut tensor = outputs.pop().unwrap(); assert_eq!(tensor, rctensor1(&[4.0f32, 5.5, 8.0]));
While creating a model from Rust code is useful for testing the library, real-life use-cases will usually load a TensorFlow or ONNX model using tract-tensorflow or tract-onnx crates.
Modules
| anyhow | |
| broadcast | N-way tensor broadcast |
| datum |
|
| dim | Extended dimension support |
| dyn_clone | |
| framework | Enforce consistent API between the implemented Frameworks importers. |
| internal | This prelude is meant for code extending tract (like implementing new ops). |
| macros | |
| model | Models and their lifecycle |
| ops | Ops |
| plan | |
| prelude | This prelude is meant for code using tract. |
| tensor |
|
Macros
Type Definitions
| TractError | |
| TractResult |