Skip to content

Commit c24c9c2

Browse files
committed
tf graph tool add stat
1 parent 86cb02a commit c24c9c2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tools/tf_graph_tool.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from __future__ import print_function
88

99
import argparse
10+
from collections import Counter
1011
import logging
1112
import os
1213
import sys
@@ -134,6 +135,19 @@ def get_graph_io_nodes(input_path):
134135
logging.info("\t%s inputs: %s", len(inputs), ','.join(inputs))
135136
logging.info("\t%s (possible) outputs: %s", len(inputs), ','.join(outputs))
136137

138+
@staticmethod
139+
def print_graph_stat(input_path):
140+
logging.info("load from %s", input_path)
141+
graph_def = load_graph_def_from_pb(input_path)
142+
143+
op_stat = Counter()
144+
for node in graph_def.node:
145+
op_stat[node.op] += 1
146+
147+
logging.info("graph stat:")
148+
for op, count in sorted(op_stat.items(), key=lambda x: x[0]):
149+
logging.info("\t%s = %s", op, count)
150+
137151
@staticmethod
138152
def extract_sub_graph(input_path, output_path=None, dest_nodes=None):
139153
if not output_path:
@@ -178,6 +192,11 @@ def extract_sub_graph(input_path, output_path=None, dest_nodes=None):
178192
subparser.add_argument("--input", dest="input_path", required=True, help="input pb path")
179193
subparser.set_defaults(func=main.get_graph_io_nodes)
180194

195+
# stat
196+
subparser = subparsers.add_parser("stat", help="print stat")
197+
subparser.add_argument("--input", dest="input_path", required=True, help="input pb path")
198+
subparser.set_defaults(func=main.print_graph_stat)
199+
181200
# extract
182201
subparser = subparsers.add_parser("extract", help="extract sub-graph")
183202
subparser.add_argument("--input", dest="input_path", required=True, help="input pb path")

0 commit comments

Comments
 (0)