Skip to content

Latest commit

 

History

History
60 lines (42 loc) · 1.87 KB

python.md

File metadata and controls

60 lines (42 loc) · 1.87 KB

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.

Using Bazel

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

Manual Setup Illustration

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
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/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