summaryrefslogtreecommitdiff
path: root/tools/nnpackage_tool/tflite2circle/tflitejson2circlejson.py
blob: c20a0c53e07586642bd3a21f448dc58f4e4eacd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python3

import json
import os
import sys
from collections import OrderedDict


def usage():
    script = os.path.basename(os.path.basename(__file__))
    print("Usage: {} path_to_tflite_in_json".format(script))
    sys.exit(-1)


if __name__ == '__main__':
    if len(sys.argv) != 2:
        usage()

    json_path = sys.argv[1]
    with open(json_path, "r") as f:
        try:
            json_dict = json.load(f, object_pairs_hook=OrderedDict)
            for subgraph in json_dict["subgraphs"]:
                subgraph["data_format"] = "CHANNELS_LAST"
            print(json.dumps(json_dict, indent=2))
        except KeyError:
            print("subgraphs attribute does not exist.")
            sys.exit(-2)