Home

Awesome

tflite2json2tflite

Convert tflite to JSON and make it editable in the IDE. It also converts the edited JSON back to tflite binary.

GitHub

<p align="center"> <img src="https://user-images.githubusercontent.com/33194443/170994316-3e3d541c-9a6d-43cb-8ea5-be0201343e03.png" /> </p>

Usage sample

1. Docker run

docker run --rm -it -v `pwd`:/home/user/workdir ghcr.io/pinto0309/tflite2json2tflite:latest

2. tflite to JSON

image

./flatc -t \
--strict-json \
--defaults-json \
-o workdir \
./schema.fbs -- workdir/model_float32.tflite

3. JSON edit

sed -i -e 's/Placeholder/input/g' workdir/model_float32.json
sed -i -e 's/fusion\/fusion_3\/BiasAdd/output/g' workdir/model_float32.json

4. JSON to tflite

./flatc \
-o workdir \
-b ./schema.fbs workdir/model_float32.json

rm workdir/model_float32.json

image

5. flatbuffers (flatc)

I have made my own modifications to the official flatbuffers(flatc) to preserve the accuracy of the quantization parameters output to JSON. For more information, please see this issue. tflite to JSON to tflite quantization error #1

https://github.com/google/flatbuffers