Skip to content

Commit 19f92ac

Browse files
author
wayuanho
committed
rename function and remove useless try-except
1 parent eda5dc4 commit 19f92ac

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

tf2onnx/tfonnx.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,26 +2419,17 @@ def tensorflow_onnx_mapping(g, continue_on_error, custom_op_handlers):
24192419
return mapped_op, unmapped_op
24202420

24212421

2422-
def tensorflow_onnx_rewrite(g, rewriters):
2423-
try:
2424-
ops = g.get_nodes()
2425-
for rewrite in rewriters:
2426-
ops = rewrite(g, ops)
2427-
g.set_nodes(ops)
2428-
for node in ops:
2429-
body_graphs = node.get_body_graphs()
2430-
if body_graphs:
2431-
for attr, b_g in body_graphs.items():
2432-
log.debug("start rewriting subgraph of %s's attribute %s", node.name, attr)
2433-
tensorflow_onnx_rewrite(b_g, rewriters)
2434-
except Exception as ex:
2435-
type_, value_, traceback_ = sys.exc_info()
2436-
log.error("node %s: exception %s" % (rewrite, ex))
2437-
ex_ext = traceback.format_exception(type_, value_, traceback_)
2438-
if continue_on_error:
2439-
log.info(ex_ext)
2440-
else:
2441-
raise ex
2422+
def run_pre_rewriters(g, rewriters):
2423+
ops = g.get_nodes()
2424+
for rewrite in rewriters:
2425+
ops = rewrite(g, ops)
2426+
g.set_nodes(ops)
2427+
for node in ops:
2428+
body_graphs = node.get_body_graphs()
2429+
if body_graphs:
2430+
for attr, b_g in body_graphs.items():
2431+
log.debug("start rewriting subgraph of %s's attribute %s", node.name, attr)
2432+
tensorflow_onnx_rewrite(b_g, rewriters)
24422433

24432434

24442435
def transpose_inputs(ctx, inputs_as_nchw):
@@ -2575,7 +2566,7 @@ def process_tf_graph(tf_graph, continue_on_error=False, verbose=False, target=No
25752566
if custom_rewriter is not None:
25762567
rewriters.extend(custom_rewriter)
25772568

2578-
tensorflow_onnx_rewrite(g, rewriters)
2569+
run_pre_rewriters(g, rewriters)
25792570

25802571
# some nodes may already copied into inner Graph, so remove them from main Graph.
25812572
g.delete_unused_nodes(output_names)

0 commit comments

Comments
 (0)