-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtf_client_local.py
More file actions
53 lines (46 loc) · 1.52 KB
/
tf_client_local.py
File metadata and controls
53 lines (46 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 14 14:24:39 2019
@author: zjy
"""
import random
import tensorflow as tf
from tensorflow.contrib import predictor
import os
tf.app.flags.DEFINE_string('export_dir', "export_dir",
help="Use half floats instead of full floats if True.")
tf.app.flags.DEFINE_string('model_version', "1",
help="the export model version")
# TODO: model version trail
FLAGS = tf.app.flags.FLAGS
if __name__ == '__main__':
# Send data by POST method
""" review of model input/output information (showed by saved_model_cli in run_server.sh)
The given SavedModel SignatureDef contains the following input(s):
inputs['x'] tensor_info:
dtype: DT_FLOAT
shape: (-1)
name: x:0
inputs['y'] tensor_info:
dtype: DT_FLOAT
shape: (-1)
name: y:0
The given SavedModel SignatureDef contains the following output(s):
outputs['sum'] tensor_info:
dtype: DT_FLOAT
shape: (-1)
name: add:0
"""
model_full_path = os.path.join(FLAGS.export_dir, FLAGS.model_version)
server = predictor.from_saved_model(model_full_path)
# sample data
sample_data = {"x": [random.random() for i in range(4)],
"y": [random.random() for i in range(4)]}
# get addition result
result = server(sample_data)
print("inputs:")
print(sample_data)
print()
print("outputs:")
print(result)