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

using multiple inputdef #1

Open
kiminh opened this issue Nov 15, 2017 · 0 comments
Open

using multiple inputdef #1

kiminh opened this issue Nov 15, 2017 · 0 comments

Comments

@kiminh
Copy link

kiminh commented Nov 15, 2017

Hi,stormy-ua
Many thanks to the project.I've run the example successfuly. Here is my question:
I have two inputs as following python script.

import tensorflow as tf
import numpy as np

export_dir = 'tmp/saved_model_2'

builder = tf.saved_model.builder.SavedModelBuilder(export_dir=export_dir)

with tf.Graph().as_default(), tf.Session().as_default() as sess:
    x1 = tf.placeholder(shape=(2, 3), dtype=tf.float32, name='x1')
    x2 = tf.placeholder(shape=(2, 3), dtype=tf.float32, name='x2')
    y = tf.Variable(np.identity(3), dtype=tf.float32)

    z = tf.add(tf.matmul(x1, y, name='z'),tf.matmul(x2, y, name='z') )

    tf.global_variables_initializer().run()

    zval = z.eval(feed_dict={x1: np.random.randn(2, 3),x2: np.random.randn(2, 3)})

    print(zval)

    x1_proto_info = tf.saved_model.utils.build_tensor_info(x1)
    x2_proto_info = tf.saved_model.utils.build_tensor_info(x2)
    z_proto_info = tf.saved_model.utils.build_tensor_info(z)

    prediction_signature = (
        tf.saved_model.signature_def_utils.build_signature_def(
            inputs={'x1': x1_proto_info,'x2': x2_proto_info},
            outputs={'z': z_proto_info},
            method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME))

    builder.add_meta_graph_and_variables(sess, [tf.saved_model.tag_constants.SERVING],
                                         signature_def_map={
                                             tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: prediction_signature
                                         })
builder.save()

Such usage is wrong. Would you please check it? Thanks a lot.

          input1Array  <- Try { Array.range(0, 6).map(_.toFloat) }
          _           =  println(s"input1 array = ${shows(input1Array)}")

          input2Array  <- Try { Array.range(0, 6).map(_.toFloat) }
          _           =  println(s"input2 array = ${shows(input2Array)}")

          inputArray  <- Try {input1Array ++ input2Array}
          _           =  println(s"input array = ${shows(inputArray)}")

          _ <- (use(serving.tensor(inputArray.slice(0,5),shape = List(2,3))),use(serving.tensor(inputArray.slice(0,5),shape = List(2,3)))){ (input1Tensor,input2Tensor) =>
            for {
              input1Def    <- Try { signature.inputs("x1") }
              input2Def    <- Try { signature.inputs("x2") }
              output1Def   <- Try { signature.outputs("z") }

              output1Array <- serving.eval[Array[Array[Float]]](model, output1Def, Map(input1Def -> input1Tensor,input2Def->input2Tensor))
              _           =  println(s"output: ${shows(output1Array)}")

            } yield ()
          }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant