Tensorflow

Tensorflow

Tensorflow Filter allows running Machine Learning inference tasks on the records of data coming from input plugins or stream processor. This filter uses Tensorflow Lite as the inference engine, and requires Tensorflow Lite shared library to be present during build and at runtime.
Tensorflow Lite is a lightweight open-source deep learning framework that is used for mobile and IoT applications. Tensorflow Lite only handles inference (not training), therefore, it loads pre-trained models (.tflite files) that are converted into Tensorflow Lite format (FlatBuffer). You can read more on converting Tensorflow models here

Configuration Parameters

The plugin supports the following configuration parameters:
Key
Description
Default
input_field
Specify the name of the field in the record to apply inference on.
model_file
Path to the model file (.tflite) to be loaded by Tensorflow Lite.
include_input_fields
Include all input filed in filter's output
True
normalization_value
Divide input values to normalization_value

Creating Tensorflow Lite shared library

Clone Tensorflow repository, install bazel package manager, and run the following command in order to create the shared library:
1
$ bazel build -c opt //tensorflow/lite/c:tensorflowlite_c # see https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/c
Copied!
The script creates the shared library bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so. You need to copy the library to a location (such as /usr/lib) that can be used by Fluent Bit.

Building Fluent Bit with Tensorflow filter plugin

Tensorflow filter plugin is disabled by default. You need to build Fluent Bit with Tensorflow plugin enabled. In addition, it requires access to Tensorflow Lite header files to compile. Therefore, you also need to pass the address of the Tensorflow source code on your machine to the build script:
1
cmake -DFLB_FILTER_TENSORFLOW=On -DTensorflow_DIR=<AddressOfTensorflowSourceCode> ...
Copied!

Command line

If Tensorflow plugin initializes correctly, it reports successful creation of the interpreter, and prints a summary of model's input/output types and dimensions.
1
$ bin/fluent-bit -i mqtt -p 'tag=mqtt.data' -F tensorflow -m '*' -p 'input_field=image' -p 'model_file=/home/user/model.tflite' -p 'include_input_fields=false' -p 'normalization_value=255' -o stdout
2
[2020/08/04 20:00:00] [ info] Tensorflow Lite interpreter created!
3
[2020/08/04 20:00:00] [ info] [tensorflow] ===== input #1 =====
4
[2020/08/04 20:00:00] [ info] [tensorflow] type: FLOAT32 dimensions: {1, 224, 224, 3}
5
[2020/08/04 20:00:00] [ info] [tensorflow] ===== output #1 ====
6
[2020/08/04 20:00:00] [ info] [tensorflow] type: FLOAT32 dimensions: {1, 2}
Copied!

Configuration File

1
[SERVICE]
2
Flush 1
3
Daemon Off
4
Log_Level info
5
6
[INPUT]
7
Name mqtt
8
Tag mqtt.data
9
10
[FILTER]
11
Name tensorflow
12
Match mqtt.data
13
input_field image
14
model_file /home/m/model.tflite
15
include_input_fields false
16
normalization_value 255
17
18
[OUTPUT]
19
Name stdout
20
Match *
Copied!

Limitations

    1.
    Currently supports single-input models
    2.
    Uses Tensorflow 2.3 header files
Last modified 1yr ago