Skip to content

Commit 39b2d9b

Browse files
committed
add test for two tag sets
1 parent 4a114c9 commit 39b2d9b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

coremltools/test/api/test_api_examples.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,43 @@ def test_convert_from_saved_model_dir():
302302
mlmodel = ct.convert("./saved_model")
303303
mlmodel.save("./model.mlmodel")
304304

305+
@staticmethod
306+
def test_convert_from_two_tags_saved_model_dir(tmpdir):
307+
308+
import tensorflow as tf
309+
from tensorflow.compat.v1.saved_model import build_tensor_info
310+
from tensorflow.compat.v1.saved_model import signature_constants
311+
from tensorflow.compat.v1.saved_model import signature_def_utils
312+
313+
@tf.function
314+
def add(a, b):
315+
return a + b
316+
317+
c = add.get_concrete_function(tf.constant(21.0), tf.constant(21.0))
318+
319+
save_path = str(tmpdir)
320+
builder = tf.compat.v1.saved_model.Builder(save_path)
321+
322+
with tf.compat.v1.Session(graph=c.graph) as sess:
323+
tensor_info_a = build_tensor_info(c.graph.inputs[0])
324+
tensor_info_b = build_tensor_info(c.graph.inputs[1])
325+
tensor_info_y = build_tensor_info(c.graph.outputs[0])
326+
327+
prediction_signature = signature_def_utils.build_signature_def(
328+
inputs={'a': tensor_info_a, 'b': tensor_info_b},
329+
outputs={'output': tensor_info_y},
330+
method_name=signature_constants.PREDICT_METHOD_NAME)
331+
332+
builder.add_meta_graph_and_variables(sess, ["serve"],
333+
signature_def_map={
334+
signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
335+
prediction_signature,
336+
})
337+
338+
builder.add_meta_graph(["serve", "tpu"])
339+
builder.save()
340+
341+
ct.convert(save_path, source="tensorflow", tags=["serve"])
305342

306343
@staticmethod
307344
def test_keras_custom_layer_model():

0 commit comments

Comments
 (0)