https://github.com/pinto0309/tflite2json2tflite
Convert tflite to JSON and make it editable in the IDE. It also converts the edited JSON back to tflite binary.
https://github.com/pinto0309/tflite2json2tflite
docker json model-converter models tensorflow tflite
Last synced: 5 months ago
JSON representation
Convert tflite to JSON and make it editable in the IDE. It also converts the edited JSON back to tflite binary.
- Host: GitHub
- URL: https://github.com/pinto0309/tflite2json2tflite
- Owner: PINTO0309
- License: apache-2.0
- Created: 2022-05-30T10:43:05.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-21T01:38:07.000Z (over 2 years ago)
- Last Synced: 2025-02-25T13:56:15.022Z (8 months ago)
- Topics: docker, json, model-converter, models, tensorflow, tflite
- Language: Dockerfile
- Homepage:
- Size: 5.42 MB
- Stars: 27
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tflite2json2tflite
Convert tflite to JSON and make it editable in the IDE. It also converts the edited JSON back to tflite binary.
![]()
# Usage sample
## 1. Docker run
```bash
docker run --rm -it -v `pwd`:/home/user/workdir ghcr.io/pinto0309/tflite2json2tflite:latest
```
## 2. tflite to JSON
```bash
./flatc -t \
--strict-json \
--defaults-json \
-o workdir \
./schema.fbs -- workdir/model_float32.tflite
```
## 3. JSON edit
```bash
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
```bash
./flatc \
-o workdir \
-b ./schema.fbs workdir/model_float32.jsonrm workdir/model_float32.json
```
## 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/PINTO0309/tflite2json2tflite/issues/1)https://github.com/google/flatbuffers
- `flatbuffers/include/flatbuffers/util.h`
- From:
```cpp
template<> inline std::string NumToString(double t) {
return FloatToString(t, 12);
}
template<> inline std::string NumToString(float t) {
return FloatToString(t, 6);
}
```
- To:
```cpp
template<> inline std::string NumToString(double t) {
return FloatToString(t, 12);
}
template<> inline std::string NumToString(float t) {
return FloatToString(t, 17);
}
```- build
```bash
cd flatbuffers && mkdir build && cd build
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)
```