#tensorflow #neural-network

tract-core

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

131 releases

0.21.3 Apr 3, 2024
0.21.2 Mar 29, 2024
0.21.1 Feb 8, 2024
0.20.22 Nov 28, 2023
0.1.1 Nov 2, 2018

#904 in Machine learning

Download history 721/week @ 2023-12-23 853/week @ 2023-12-30 2182/week @ 2024-01-06 4990/week @ 2024-01-13 5041/week @ 2024-01-20 6367/week @ 2024-01-27 6357/week @ 2024-02-03 6377/week @ 2024-02-10 9139/week @ 2024-02-17 16274/week @ 2024-02-24 7316/week @ 2024-03-02 5836/week @ 2024-03-09 4442/week @ 2024-03-16 7901/week @ 2024-03-23 5285/week @ 2024-03-30 6674/week @ 2024-04-06

26,171 downloads per month
Used in 39 crates (8 directly)

MIT/Apache

1.5MB
35K 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
~344K SLoC