コード例 #1
0
def _make_saved_model() -> SavedModel:
    with tf.Graph().as_default(), tf.compat.v1.Session().as_default() as session:
        input_x = tf.compat.v1.placeholder(dtype=tf.float32, shape=[None, 256])
        input_y = tf.compat.v1.placeholder(dtype=tf.float32, shape=[None, 256])
        weight = tf.Variable(initial_value=numpy.arange(256, dtype=numpy.float32), dtype=tf.float32)
        output_z = input_x + input_y + weight

        session.run(weight.initializer)

    return SavedModel(inputs=[Input(name='x', tensor=input_x, data_format=DataFormat.CHANNELS_FIRST),
                              Input(name='y', tensor=input_y, data_format=DataFormat.CHANNELS_LAST)],
                      outputs=[Output(name='z', tensor=output_z)],
                      session=session)
コード例 #2
0
def _make_saved_model() -> SavedModel:
    with tf.Graph().as_default(), tf.compat.v1.Session().as_default() as session:
        input_x = tf.compat.v1.placeholder(dtype=tf.float32, shape=[None, 2, 3, 4], name='x')
        input_y = tf.compat.v1.placeholder(dtype=tf.float32, shape=[None, 2, 3, 4], name='y')
        weight = tf.Variable(initial_value=4.2, dtype=tf.float32)
        output_z = tf.multiply(input_x + input_y, weight, name='z')

        session.run(weight.initializer)

    return SavedModel(inputs=[Input(name='x', tensor=input_x, data_format=None),
                              Input(name='y', tensor=input_y, data_format=None)],
                      outputs=[Output(name='z', tensor=output_z)],
                      session=session)
コード例 #3
0
def _make_saved_model() -> SavedModel:
    with eager_context.graph_mode(), tf.Graph().as_default(
    ), tf.compat.v1.Session().as_default() as session:
        input_x = tf.compat.v1.placeholder(dtype=tf.float32, shape=[None, 4])
        input_y = tf.compat.v1.placeholder(dtype=tf.float32, shape=[None, 4])
        weight = tf.Variable(initial_value=[2.0, 3.0, 4.0, 5.0],
                             dtype=tf.float32)
        output_z = input_x + input_y + weight

        session.run(weight.initializer)

    return SavedModel(inputs=[
        Input(name='x', tensor=input_x),
        Input(name='y', tensor=input_y)
    ],
                      outputs=[Output(name='z', tensor=output_z)],
                      session=session)