Commit feda168b authored by 宋柯's avatar 宋柯

模型上线

parent f00d863e
...@@ -10,6 +10,8 @@ import time ...@@ -10,6 +10,8 @@ import time
with open('/Users/edz/software/Recommend/train_samples.csv', 'r') as f: with open('/Users/edz/software/Recommend/train_samples.csv', 'r') as f:
for _ in range(50):
count = 0 count = 0
examples = [] examples = []
for line in f: for line in f:
...@@ -73,11 +75,17 @@ with open('/Users/edz/software/Recommend/train_samples.csv', 'r') as f: ...@@ -73,11 +75,17 @@ with open('/Users/edz/software/Recommend/train_samples.csv', 'r') as f:
examples.append({'b64': base64.b64encode(tf_serialized)}) examples.append({'b64': base64.b64encode(tf_serialized)})
count += 1 count += 1
if count == 1000: if count == 500:
break break
start = time.time() start = time.time()
res = requests.post("http://localhost:8501/v1/models/wide_deep:predict", # res = requests.post("http://localhost:8501/v1/models/wide_deep:predict",
json={"inputs": {"examples": examples}, # json={"inputs": {"examples": examples},
"signature_name": "predict"}) # "signature_name": "predict"})
print(res.text) # res = requests.post("http://tensorserving-sk.paas-develop.env/v1/models/service:predict",
# json={"inputs": {"inputs": examples},
# "signature_name": "regression"})
res = requests.post("http://localhost:8000/v1/models/service:predict",
json={"inputs": {"inputs": examples},
"signature_name": "regression"})
# print(res.text)
print(time.time() - start) print(time.time() - start)
...@@ -17,7 +17,8 @@ from tensorflow_serving.apis import predict_pb2 ...@@ -17,7 +17,8 @@ from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2_grpc from tensorflow_serving.apis import prediction_service_pb2_grpc
import grpc import grpc
tf.app.flags.DEFINE_string('server', 'localhost:8502', 'PredictionService host:port') # tf.app.flags.DEFINE_string('server', 'localhost:8502', 'PredictionService host:port')
tf.app.flags.DEFINE_string('server', 'tensorserving-sk.paas-develop.env:8090', 'PredictionService host:port')
FLAGS = tf.app.flags.FLAGS FLAGS = tf.app.flags.FLAGS
def prediction(): def prediction():
...@@ -25,9 +26,9 @@ def prediction(): ...@@ -25,9 +26,9 @@ def prediction():
channel = grpc.insecure_channel(FLAGS.server, options = options) channel = grpc.insecure_channel(FLAGS.server, options = options)
stub = prediction_service_pb2_grpc.PredictionServiceStub(channel) stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
request = predict_pb2.PredictRequest() request = predict_pb2.PredictRequest()
request.model_spec.name = 'wide_deep' #对应上图第一个方框 request.model_spec.name = 'service' #对应上图第一个方框
request.model_spec.signature_name = 'regression' #对应上图第二个方框with open('/Users/edz/software/Recommend/train_samples.csv', 'r') as f: request.model_spec.signature_name = 'regression' #对应上图第二个方框with open('/Users/edz/software/Recommend/train_samples.csv', 'r') as f:
for _ in range(20): for _ in range(1):
with open('/Users/edz/software/Recommend/train_samples.csv', 'r') as f: with open('/Users/edz/software/Recommend/train_samples.csv', 'r') as f:
count = 0 count = 0
...@@ -92,7 +93,7 @@ def prediction(): ...@@ -92,7 +93,7 @@ def prediction():
examples.append(tf_serialized) examples.append(tf_serialized)
count += 1 count += 1
if count == 1000: if count == 1:
break break
start = time.time() start = time.time()
# request.inputs['examples'].CopyFrom(tf.make_tensor_proto(examples)) # in对应上图第三个方框,为模型的输入Name # request.inputs['examples'].CopyFrom(tf.make_tensor_proto(examples)) # in对应上图第三个方框,为模型的输入Name
......
...@@ -238,7 +238,7 @@ early_stopping = tf.estimator.experimental.stop_if_no_increase_hook(wideAndDeepM ...@@ -238,7 +238,7 @@ early_stopping = tf.estimator.experimental.stop_if_no_increase_hook(wideAndDeepM
hooks = [early_stopping] hooks = [early_stopping]
train_spec = tf.estimator.TrainSpec(input_fn = lambda: input_fn(DATA_DIR + 'train_samples.csv', 100, True, 2048), hooks = hooks) train_spec = tf.estimator.TrainSpec(input_fn = lambda: input_fn(DATA_DIR + 'train_samples.csv', 1, True, 2048), hooks = hooks)
serving_feature_spec = tf.feature_column.make_parse_example_spec( serving_feature_spec = tf.feature_column.make_parse_example_spec(
linear_feature_columns + dnn_feature_columns) linear_feature_columns + dnn_feature_columns)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment