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
//! Port of tinymind (C++) `examples/tflite_streaming_int8`: a streaming int8
//! CNN that detects a bearing fault in a machine's vibration, trained in Keras
//! and converted to an int8 TensorFlow Lite model by TFLiteConverter, run from
//! two Rust modules that `tools/import_tflite` generated from the `.tflite` file
//! that example commits:
//!
//! - `forward` over a whole window of 32 frames (0.64 s), and
//! - `step`, which takes one new 20 ms frame and keeps, in a caller-owned
//! state, the frames each layer still needs, so it computes one frame per
//! layer instead of rerunning the whole window.
//!
//! The program feeds a 16-second test recording frame by frame to `step`, runs
//! `forward` over the window ending at each frame as well, and requires both to
//! give, for every window, the two int8 outputs TensorFlow Lite for
//! Microcontrollers computed for it. It writes the same files the C++ example
//! writes, byte for byte:
//!
//! - stdout: how many outputs differ from TFLite Micro's (none), false alarms
//! and detections, the first alarm, and the memory each form needs
//! - `tflite_streaming_int8.csv`: per frame, the time, the fault's severity,
//! the streamed fault probability (per 256) and the frame's 16 bands
//! - `tflite_streaming_int8_summary.csv`: the figures above as CSV
//!
//! It exits with status 1 if any output differs from TFLite Micro's, as the
//! C++ example does.
//!
//! Run: `cargo run --release --example tflite_streaming_int8 -- [output_dir]`
//! (default `output`). The generated modules use an arena, which needs Rust
//! 1.88.
use fs;
use ;
use PathBuf;