#tensor-flow #neural-networks

tract-core

Tiny, no-nonsense, self contained, TensorFlow and ONNX inference

128 releases

new 0.20.22 Nov 28, 2023
0.20.18 Aug 30, 2023
0.20.7 Jun 14, 2023
0.19.8 Mar 27, 2023
0.1.1 Nov 2, 2018

#455 in Machine learning

Download history 4968/week @ 2023-08-08 2794/week @ 2023-08-15 3405/week @ 2023-08-22 3857/week @ 2023-08-29 3422/week @ 2023-09-05 3088/week @ 2023-09-12 3598/week @ 2023-09-19 3548/week @ 2023-09-26 3182/week @ 2023-10-03 3454/week @ 2023-10-10 3466/week @ 2023-10-17 3333/week @ 2023-10-24 2913/week @ 2023-10-31 3543/week @ 2023-11-07 3750/week @ 2023-11-14 3300/week @ 2023-11-21

14,052 downloads per month
Used in 37 crates (7 directly)

MIT/Apache

1.5MB
33K 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

~12MB
~226K SLoC