Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set aggressive inlining to true #1148

Merged
merged 2 commits into from
Oct 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions tf2onnx/tf_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,26 @@ def convert_variables_to_constants_large_model(func):
except ImportError:
_not_implemented_tf_placeholder("_convert_variables_to_constants_v2_impl")()
frozen_graph_def, _ = \
_convert_variables_to_constants_v2_impl(func, lower_control_flow=False, aggressive_inlining=False)
_convert_variables_to_constants_v2_impl(func, lower_control_flow=False, aggressive_inlining=True)
return frozen_graph_def

try:
from tensorflow.python.framework.convert_to_constants import \
_FunctionConverterData, _replace_variables_by_constants # pylint: disable=protected-access
except ImportError:
_not_implemented_tf_placeholder("_replace_variables_by_constants")()
converter_data = _FunctionConverterData(func=func, lower_control_flow=False, aggressive_inlining=False)
converter_data = _FunctionConverterData(func=func, lower_control_flow=False, aggressive_inlining=True)
frozen_graph_def, _ = _replace_variables_by_constants(converter_data=converter_data)
return frozen_graph_def

def from_function(func, input_names, output_names, large_model=False):
if large_model:
return convert_variables_to_constants_large_model(func)

frozen_func = convert_variables_to_constants_v2(func, lower_control_flow=False)
if get_tf_version() < LooseVersion("2.2"):
frozen_func = convert_variables_to_constants_v2(func, lower_control_flow=False)
else:
frozen_func = convert_variables_to_constants_v2(func, lower_control_flow=False, aggressive_inlining=True)
graph_def = frozen_func.graph.as_graph_def(add_shapes=True)
# output_names = [i.name for i in frozen_func.outputs]
tf_reset_default_graph()
Expand Down