Saved Model
@@ -148,6 +247,34 @@ public Session session() {
return session;
}
+ /**
+ * Returns the {@link SignatureToNodeName} translator for the model.
+ *
+ * @return SignatureToNodeName translator
+ */
+ public SignatureToNodeName getSignatureToNodeName() {
+ if (this.sigToNodeName == null) {
+ // no need to lock, ok to create multiple instances
+ this.sigToNodeName = new SignatureToNodeName(this);
+ }
+ return this.sigToNodeName;
+ }
+
+ /**
+ * Return a {@link TfFunction} corresponding to the function signature.
+ *
+ * {@code
+ * TfFunction myFunction = savedModelBundle.function("myFunctionSignatureName");
+ * Map> outputTensorMap = myFunction.call(inputTensorMap);
+ * }
+ *
+ * @param functionSignatureName name of the {@code SignatureDef} in the saved model.
+ * @return TfFunction object that can be used to make calls to the tf.function
+ */
+ public TfFunction function(String functionSignatureName) {
+ return new TfFunction(functionSignatureName, this.getSignatureToNodeName(), this.session);
+ }
+
/**
* Releases resources (the {@link Graph} and {@link Session}) associated with the saved model
* bundle.
@@ -161,6 +288,7 @@ public void close() {
private final Graph graph;
private final Session session;
private final MetaGraphDef metaGraphDef;
+ private SignatureToNodeName sigToNodeName;
private SavedModelBundle(Graph graph, Session session, MetaGraphDef metaGraphDef) {
this.graph = graph;
diff --git a/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/TfFunction.java b/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/TfFunction.java
new file mode 100644
index 00000000000..5dc5a128898
--- /dev/null
+++ b/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/TfFunction.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2020 The TensorFlow Authors. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.tensorflow;
+
+import com.google.protobuf.InvalidProtocolBufferException;
+
+import java.util.List;
+import java.util.ListIterator;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Invoke