Skip to content

Commit

Permalink
Strip control inputs from graph when creating new TF functions from t…
Browse files Browse the repository at this point in the history
…ensors.
  • Loading branch information
psobot committed Jul 21, 2023
1 parent 7ab7850 commit 8954c4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion realbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.

__author__ = "Spotify"
__version__ = "1.0.2"
__version__ = "1.0.3"
__email__ = "realbook@spotify.com"
__description__ = "Python libraries for easier machine learning on audio"
__url__ = "https://github.com/spotify/realbook"
13 changes: 12 additions & 1 deletion realbook/layers/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def get_saved_model_output_tensors(saved_model_or_path: Union[tf.keras.Model, st
def create_function_from_tensors(
input_tensors: Union[tf.Tensor, List[tf.Tensor]],
output_tensors: Union[tf.Tensor, List[tf.Tensor]],
include_control_inputs: bool = False,
) -> WrappedFunction:
"""
Given two lists of tensors (input and output), this method will return a tf.function
Expand Down Expand Up @@ -269,9 +270,19 @@ def create_function_from_tensors(

graph_input_names = [t.name for t in graph.inputs]

graph_def = graph.as_graph_def()

if not include_control_inputs:
# If this graph has any control inputs in it, those inputs will
# likely not be convertible (nor do we want them in our converted model!)
for node in graph_def.node:
node.input[:] = [
tensor_name for tensor_name in node.input if not tensor_name.startswith("^")
]

try:
return _load_concrete_function_from_graph_def(
graph.as_graph_def(),
graph_def,
[t.name for t in input_tensors],
[t.name for t in output_tensors],
)
Expand Down

0 comments on commit 8954c4a

Please sign in to comment.