135 releases

0.21.7 Sep 23, 2024
0.21.6 Jul 24, 2024
0.21.5 May 11, 2024
0.21.2 Mar 29, 2024
0.1.1 Nov 2, 2018

#1168 in Machine learning

Download history 5179/week @ 2024-07-29 5601/week @ 2024-08-05 3267/week @ 2024-08-12 5305/week @ 2024-08-19 5775/week @ 2024-08-26 5412/week @ 2024-09-02 7222/week @ 2024-09-09 5854/week @ 2024-09-16 7529/week @ 2024-09-23 6917/week @ 2024-09-30 6872/week @ 2024-10-07 10668/week @ 2024-10-14 9853/week @ 2024-10-21 5472/week @ 2024-10-28 4356/week @ 2024-11-04 2478/week @ 2024-11-11

22,262 downloads per month
Used in 37 crates (9 directly)

MIT/Apache

2MB
48K SLoC

Rust 39K SLoC // 0.0% comments Templ 9K SLoC // 0.1% comments GNU Style Assembly 12 SLoC // 0.2% comments

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

~13–26MB
~393K SLoC