1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! # tflite-c-rs
//!
//! A small, safe Rust wrapper around the TensorFlow Lite C API that resolves
//! the shared library at *runtime* with [`libloading`] instead of linking
//! against it at build time. The crate ships no native code, no `build.rs`,
//! no `-sys` crate — it dynamically opens a TFLite shared object that you
//! (or your platform package manager) provide separately, then offers a
//! tidy, RAII-driven API on top of the resolved C symbols.
//!
//! ## Why runtime dynamic loading?
//!
//! The TensorFlow Lite C library is famously awkward to link statically:
//! its build system is Bazel-only, the released prebuilt binaries are
//! platform-specific, and cross-compilation against it tends to drag the
//! entire TensorFlow source tree along for the ride. For many real-world
//! deployments — embedded Linux, edge accelerators, vendor-shipped
//! NPU stacks — the path of least resistance is to ship the vendor's
//! prebuilt `.so`/`.dylib`/`.dll` and pick it up at runtime.
//!
//! That is exactly what this crate does. It uses `libloading` to `dlopen`
//! the TFLite C library, caches the symbols it needs, and exposes a small
//! safe surface (`Model`, `InterpreterOptions`, `Interpreter`, `Tensor`,
//! `ExternalDelegate`) on top of it.
//!
//! ## Quick start
//!
//! ```no_run
//! use tflite_c::{TfLiteLibrary, Model, InterpreterOptions, Interpreter};
//!
//! # fn run() -> Result<(), tflite_c::Error> {
//! let lib = TfLiteLibrary::load_default()?;
//! let model = Model::from_file("model.tflite", lib.clone())?;
//!
//! let mut options = InterpreterOptions::new(lib.clone());
//! options.num_threads(2);
//!
//! let mut interp = Interpreter::new(model, options)?;
//!
//! // Fill input 0 with whatever bytes your model expects.
//! interp.input_mut(0)?.data_mut()?.fill(0);
//!
//! interp.invoke()?;
//!
//! let out = interp.output(0)?;
//! let probs = out.to_vec_f32()?;
//! println!("first prob: {}", probs[0]);
//! # Ok(()) }
//! ```
//!
//! ## Threading
//!
//! [`Interpreter`] is `Send + Sync`, but TensorFlow Lite's C interpreter is
//! *not* thread-safe in itself. The standard pattern is to share via
//! `Arc<Mutex<Interpreter>>` (or `Arc<parking_lot::Mutex<Interpreter>>`) and
//! serialize every call into a given interpreter.
//!
//! ## Relationship to the upstream C API
//!
//! Type and function names that begin with `TfLite…` come from the upstream
//! header [`c_api.h`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/c/c_api.h)
//! and the external-delegate header
//! [`c_api_experimental.h`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/c/c_api_experimental.h).
//! This crate covers the minimum set required to load a model, run
//! inference, and read results — enough for v0.0.1.
pub use crate;
pub use crate;
pub use crate;
pub use crate;
pub use crateModel;
pub use crate;