Convert tflite to JSON and make it editable in the IDE. It also converts the edited JSON back to tflite binary.
docker run --rm -it -v `pwd`:/home/user/workdir ghcr.io/pinto0309/tflite2json2tflite:latest
./flatc -t \
--strict-json \
--defaults-json \
-o workdir \
./schema.fbs -- workdir/model_float32.tflite
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
./flatc \
-o workdir \
-b ./schema.fbs workdir/model_float32.json
rm workdir/model_float32.json
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
-
flatbuffers/include/flatbuffers/util.h
- From:
template<> inline std::string NumToString<double>(double t) { return FloatToString(t, 12); } template<> inline std::string NumToString<float>(float t) { return FloatToString(t, 6); }
- To:
template<> inline std::string NumToString<double>(double t) { return FloatToString(t, 12); } template<> inline std::string NumToString<float>(float t) { return FloatToString(t, 17); }
- From:
-
build
cd flatbuffers && mkdir build && cd build cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release .. make -j$(nproc)