use edgefirst_tflite::{Interpreter, Library, Model};
pub const MINIMAL_MODEL: &[u8] = include_bytes!("../../../../testdata/minimal.tflite");
pub fn tflite_available() -> bool {
load_library().is_some()
}
macro_rules! require_tflite {
() => {
if !$crate::common::tflite_available() {
eprintln!(
"SKIPPED: TFLite shared library not available. \
Set TFLITE_TEST_LIB=/path/to/libtensorflowlite_c.so to enable."
);
return;
}
};
}
pub(crate) use require_tflite;
pub fn load_library() -> Option<Library> {
if let Ok(path) = std::env::var("TFLITE_TEST_LIB") {
Library::from_path(path).ok()
} else {
Library::new().ok()
}
}
pub fn load_model(lib: &Library) -> Model<'_> {
Model::from_bytes(lib, MINIMAL_MODEL).expect("failed to load minimal test model")
}
#[allow(dead_code)]
pub fn build_interpreter<'lib>(lib: &'lib Library, model: &Model<'lib>) -> Interpreter<'lib> {
Interpreter::builder(lib)
.expect("failed to create interpreter builder")
.num_threads(1)
.build(model)
.expect("failed to build interpreter")
}