tensorflow_serving/batching/test_util/matrix_half_plus_two_saved_model.py
def _generate_saved_model_for_matrix_half_plus_two(export_dir):
  """Creates SavedModel for half plus two model that accepts batches of
       3*3 matrices.
       The model divides all elements in each matrix by 2 and adds 2 to them.
       So, for one input matrix [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
       the result will be [[2.5, 3, 3.5], [4, 4.5, 5], [5.5, 6, 6.5]].
    Args:
      export_dir: The directory where to write SavedModel files.
    """
  builder = tf.saved_model.builder.SavedModelBuilder(export_dir)
  with tf.Session() as session:
    x = tf.placeholder(tf.float32, shape=[None, 3, 3], name="x")
    a = tf.constant(0.5)
    b = tf.constant(2.0)
    y = tf.add(tf.multiply(a, x), b, name="y")
    predict_signature_def = (
        tf.saved_model.signature_def_utils.predict_signature_def({
            "x": x
        }, {"y": y}))
    signature_def_map = {
        tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
            predict_signature_def
    }
    session.run(tf.global_variables_initializer())
    builder.add_meta_graph_and_variables(
        session, [tf.saved_model.tag_constants.SERVING],
        signature_def_map=signature_def_map)
    builder.save()
Creates SavedModel for half plus two model that accepts batches of
       3*3 matrices.
       The model divides all elements in each matrix by 2 and adds 2 to them.
       So, for one input matrix [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
       the result will be [[2.5, 3, 3.5], [4, 4.5, 5], [5.5, 6, 6.5]].
    Args:
      export_dir: The directory where to write SavedModel files.
    
Creates SavedModel for half plus two model that accepts batches of
3*3 matrices.
The model divides all elements in each matrix by 2 and adds 2 to them.
Creates SavedModel for half plus two model that accepts batches of 3 * 3 matrices . The model divides all elements in each matrix by 2 and adds 2 to them .
def _generate_saved_model_for_matrix_half_plus_two(export_dir):
  builder = tf.saved_model.builder.SavedModelBuilder(export_dir)
  with tf.Session() as session:
    x = tf.placeholder(tf.float32, shape=[None, 3, 3], name="x")
    a = tf.constant(0.5)
    b = tf.constant(2.0)
    y = tf.add(tf.multiply(a, x), b, name="y")
    predict_signature_def = (
        tf.saved_model.signature_def_utils.predict_signature_def({
            "x": x
        }, {"y": y}))
    signature_def_map = {
        tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
            predict_signature_def
    }
    session.run(tf.global_variables_initializer())
    builder.add_meta_graph_and_variables(
        session, [tf.saved_model.tag_constants.SERVING],
        signature_def_map=signature_def_map)
    builder.save()
def _generate_saved_model_for_matrix_half_plus_two ( export_dir ) : builder = tf . saved_model . builder . SavedModelBuilder ( export_dir ) with tf . Session ( ) as session : x = tf . placeholder ( tf . float32 , shape = [ None , 3 , 3 ] , name = "x" ) a = tf . constant ( 0.5 ) b = tf . constant ( 2.0 ) y = tf . add ( tf . multiply ( a , x ) , b , name = "y" ) predict_signature_def = ( tf . saved_model . signature_def_utils . predict_signature_def ( { "x" : x } , { "y" : y } ) ) signature_def_map = { tf . saved_model . signature_constants . DEFAULT_SERVING_SIGNATURE_DEF_KEY : predict_signature_def } session . run ( tf . global_variables_initializer ( ) ) builder . add_meta_graph_and_variables ( session , [ tf . saved_model . tag_constants . SERVING ] , signature_def_map = signature_def_map ) builder . save ( )
Creates SavedModel for half plus two model that accepts batches of
3*3 matrices.
Creates SavedModel for half plus two model that accepts batches of 3 * 3 matrices .
"""Creates SavedModel for half plus two model that accepts batches of
       3*3 matrices.
       The model divides all elements in each matrix by 2 and adds 2 to them.
       So, for one input matrix [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
       the result will be [[2.5, 3, 3.5], [4, 4.5, 5], [5.5, 6, 6.5]].
    Args:
      export_dir: The directory where to write SavedModel files.
    """
export_dir
The directory where to write SavedModel files.
The directory where to write SavedModel files .