import tensorflow as tf
import numpy as np
from grpc.beta import implementations
from tensorflow_serving.apis import prediction_service_pb2, predict_pb2
channel = implementations.insecure_channel(host, port)
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
request = predict_pb2.PredictRequest()
idx = np.array(np.random.randint(0, 10000000, [dim], np.int32))
val = np.ones([dim], dtype=np.float)
sl = 50
pos = 1
request.model_spec.name = 'model'
request.model_spec.signature_name = tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY
request.inputs['input_idx'].CopyFrom(tf.contrib.util.make_tensor_proto(idx, shape=[1, dim], dtype=tf.int32)) # 矩阵
request.inputs['sl1'].CopyFrom(tf.contrib.util.make_tensor_proto(sl, shape=[1, ], dtype=tf.float32)) # 向量
request.inputs['train_phase'].CopyFrom(tf.contrib.util.make_tensor_proto(False, shape=[], dtype=tf.bool)) # 标量
res = stub.Predict(request, 3.0)
ctr_score = res.outputs['output'].float_val
if ctr_score and len(ctr_score) > 0:
return True
Tensorflow用request predict模型如何传scalar
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- var dataOrArray = [[String:AnyObject]]() //定义一个字典数组 var i...
- 前言 鉴于发布这篇博客以来已经有不少人私信问我如何去转换,我想可能是我的博客并没有写明白,于是我决定把这篇文章完善...