use tfmicro::{MicroInterpreter, Model, MutableOpResolver};
use itertools::Itertools;
use log::info;
#[test]
fn person_detection() {
env_logger::init();
info!("---- Starting tensorflow micro example: person_detection");
let model =
include_bytes!("../examples/models/person_detection_grayscale.tflite");
let no_person = include_bytes!(
"../examples/models/no_person_image_data_grayscale.data"
);
let person =
include_bytes!("../examples/models/person_image_data_grayscale.data");
let model = Model::from_buffer(&model[..]).unwrap();
const TENSOR_ARENA_SIZE: usize = 93 * 1024;
let mut tensor_arena: [u8; TENSOR_ARENA_SIZE] = [0; TENSOR_ARENA_SIZE];
let micro_op_resolver = MutableOpResolver::empty()
.depthwise_conv_2d()
.conv_2d()
.average_pool_2d();
let mut interpreter =
MicroInterpreter::new(&model, micro_op_resolver, &mut tensor_arena[..])
.unwrap();
interpreter.input(0, person).unwrap();
assert_eq!([1, 96, 96, 1], interpreter.input_info(0).dims);
info!("Created setup");
interpreter.invoke().unwrap();
let output_tensor = interpreter.output(0);
assert_eq!(
[1, 1, 1, 3],
output_tensor.info().dims,
"Dimensions of output tensor"
);
assert_eq!(
1,
output_tensor.as_data::<u8>().iter().position_max().unwrap()
);
info!("---- Person output correct!");
interpreter.input(0, no_person).unwrap();
interpreter.invoke().unwrap();
let output_tensor = interpreter.output(0);
assert_eq!(
[1, 1, 1, 3],
output_tensor.info().dims,
"Dimensions of output tensor"
);
assert_eq!(
2,
output_tensor.as_data::<u8>().iter().position_max().unwrap()
);
info!("---- No-person output correct!");
info!("---- Done");
}