Writing and using Python scripts from the TFLM repository is currently in the prototyping stage. As such, the instructions below are somewhat sparse and subject to change.
We use Bazel as our default build system for Python and the continuous integration infrastrucutre only runs the Python unit tests via Bazel.
When using Bazel with Python, all the environment setup is handled as part of the build.
Some example commands:
bazel test tensorflow/lite/tools:flatbuffer_utils_test
bazel build tensorflow/lite/tools:visualize
bazel-bin/tensorflow/lite/tools/visualize tensorflow/lite/micro/models/person_detect.tflite tensorflow/lite/micro/models/person_detect.tflite.html
For advanced users that would like to use the Python code in the TFLM repository independent of bazel, here is one approach.
Please note that this setup is unsupported and will need users to debug various issues on their own. It is described here for illustrative purposes only.
# The cloned tflite-micro folder needs to be renamed to tflite_micro
mv tflite-micro tflite_micro
# To set up a specific Python version, make sure `python` is pointed to the
# desired version. For example, call `python3.11 -m venv tflite_micro/venv`.
python -m venv tflite_micro/venv
echo "export PYTHONPATH=\${PYTHONPATH}:${PWD}" >> tflite_micro/venv/bin/activate
cd tflite_micro
source venv/bin/activate
pip install --upgrade pip
pip install -r third_party/python_requirements.txt
# (Optional)
pip install ipython
Run some tests and binaries:
python tensorflow/lite/tools/flatbuffer_utils_test.py
python tensorflow/lite/tools/visualize.py tensorflow/lite/micro/models/person_detect.tflite tensorflow/lite/micro/models/person_detect.tflite.html