134 releases

0.21.6 Jul 24, 2024
0.21.4 Apr 23, 2024
0.21.2 Mar 29, 2024
0.20.22 Nov 28, 2023
0.1.1 Nov 2, 2018

#1051 in Machine learning

Download history 6143/week @ 2024-05-24 6459/week @ 2024-05-31 8921/week @ 2024-06-07 6474/week @ 2024-06-14 8905/week @ 2024-06-21 5058/week @ 2024-06-28 9190/week @ 2024-07-05 5520/week @ 2024-07-12 11197/week @ 2024-07-19 6648/week @ 2024-07-26 4965/week @ 2024-08-02 4809/week @ 2024-08-09 4246/week @ 2024-08-16 6043/week @ 2024-08-23 5092/week @ 2024-08-30 5449/week @ 2024-09-06

21,104 downloads per month
Used in 38 crates (8 directly)

MIT/Apache

1.5MB
39K SLoC

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 = f32::fact(&[3]);
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(),
    [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.into()]).unwrap();

// take the first and only output tensor
let mut tensor = outputs.pop().unwrap();

assert_eq!(tensor, tensor1(&[4.0f32, 5.5, 8.0]).into());

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.

Dependencies

~12–20MB
~374K SLoC