1#!/bin/bash
2
3# This script generate visualizations and metadata json files of the tflite models
4# Results are stored in /tmp by default
5# Prerequisites:
6# Follow the link to run the visualize.py
7# https://www.tensorflow.org/lite/guide/faq#how_do_i_inspect_a_tflite_file
8
9if [[ -z "$ANDROID_BUILD_TOP" ]]; then
10  echo ANDROID_BUILD_TOP not set, bailing out
11  echo you must run lunch before running this script
12  exit 1
13fi
14
15echo "Follow the link to set up the prerequisites for running visualize.py: \
16https://www.tensorflow.org/lite/guide/faq#how_do_i_inspect_a_tflite_file"
17read -p "Are you able to run the visualize.py script with bazel? [Y/N]" -n 1 -r
18echo
19if [[ $REPLY =~ ^[Yy]$ ]]; then
20  MODEL_DIR="$ANDROID_BUILD_TOP/test/mlts/models/assets"
21  # The .json files are always output to /tmp by the tflite visualize tool
22  HTML_DIR="${1:-/tmp}"
23  mkdir -p $HTML_DIR
24
25  set -e
26  for file in "$MODEL_DIR"/*.tflite
27  do
28    if [ -f "$file" ]; then
29      filename=`basename $file`
30      modelname=${filename%.*}
31      bazel run //tensorflow/lite/tools:visualize $file $HTML_DIR/$modelname.html
32    fi
33  done
34else
35  echo "Please set up first following https://www.tensorflow.org/lite/guide/faq#how_do_i_inspect_a_tflite_file."
36fi
37
38exit