#tensorflow #neural-network

tract-core

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

133 releases

new 0.21.5 May 11, 2024
0.21.2 Mar 29, 2024
0.20.22 Nov 28, 2023
0.20.7 Jun 14, 2023
0.1.1 Nov 2, 2018

#913 in Machine learning

Download history 6700/week @ 2024-01-25 6411/week @ 2024-02-01 4104/week @ 2024-02-08 9173/week @ 2024-02-15 11725/week @ 2024-02-22 14025/week @ 2024-02-29 4944/week @ 2024-03-07 5694/week @ 2024-03-14 7091/week @ 2024-03-21 5458/week @ 2024-03-28 7293/week @ 2024-04-04 7280/week @ 2024-04-11 9404/week @ 2024-04-18 7652/week @ 2024-04-25 5876/week @ 2024-05-02 1973/week @ 2024-05-09

26,444 downloads per month
Used in 38 crates (8 directly)

MIT/Apache

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

~11–19MB
~345K SLoC