export_func.export(model, sess, signature_name=mission, version=fold + 1)
def export(model, sess, signature_name, export_path=root_path + '/all_in_one/demo/exported_models/', version=1):
# export path
export_path = os.path.join(os.path.realpath(export_path), signature_name, str(version))
print('Exporting trained model to {} ...'.format(export_path)) builder = tf.saved_model.builder.SavedModelBuilder(export_path)
# Build the signature_def_map.
classification_w = tf.saved_model.utils.build_tensor_info(model.w)
# classification_is_training = tf.saved_model.utils.build_tensor_info(model.is_training)
classification_dropout_keep_prob_mlp = tf.saved_model.utils.build_tensor_info(
model.dropout_keep_prob_mlp)
# score
classification_outputs_scores = tf.saved_model.utils.build_tensor_info(model.y) classification_signature = tf.saved_model.signature_def_utils.build_signature_def(
inputs={tf.saved_model.signature_constants.CLASSIFY_INPUTS: classification_w},
outputs={
tf.saved_model.signature_constants.CLASSIFY_OUTPUT_SCORES:
classification_outputs_scores
},
method_name=tf.saved_model.signature_constants.CLASSIFY_METHOD_NAME) # 'tensorflow/serving/classify' prediction_signature = tf.saved_model.signature_def_utils.build_signature_def(
inputs={'input_plh': classification_w, 'dropout_keep_prob_mlp':
classification_dropout_keep_prob_mlp,
# 'is_training': classification_is_training
},
outputs={'scores': classification_outputs_scores},
method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME) # 'tensorflow/serving/predict'
builder.add_meta_graph_and_variables(
sess, [tf.saved_model.tag_constants.SERVING],
signature_def_map={
signature_name: prediction_signature,
tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: classification_signature,
})
builder.save()

在signature_def_map中定义了两个,一个是自己设计的别名,一个是默认的。

定义一个解析类。

model_name 是启动服务时明确的model_name

signature_name是在signature_def_map中自己设计的别名对应的输入输出之类的。

def classify(self,  sents):
self.sents=self.sents2id(sents)
hostport = '192.168.31.186:6000'
# grpc
host, port = hostport.split(':')
channel = implementations.insecure_channel(host, int(port))
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
# build request
request = predict_pb2.PredictRequest()
request.model_spec.name = self.model_name
request.model_spec.signature_name = self.signature_name
request.inputs['input_plh'].CopyFrom(
tf.contrib.util.make_tensor_proto(self.sents, dtype=tf.int32))
request.inputs['dropout_keep_prob_mlp'].CopyFrom(
tf.contrib.util.make_tensor_proto(1.0, dtype=tf.float32))
model_result = stub.Predict(request, 60.0)
model_result = np.array(model_result.outputs['scores'].float_val)
model_result = [model_result.tolist()][0]
index, _ =max(enumerate(model_result), key=operator.itemgetter(1))
if index>0:
label = self.label_dict[index-1]
else:
label = ""
# print("index:{}\tlabel:{}".format(index, label))
if self.encode == "part" :
if label:
label=self.part[label]
else:
label = "凌晨"
if self.encode == "type" :
if label:
label=self.type[label]
else:
label = "录像"
if self.encode == "door" and label:
label = self.gate[label] return label

All-in-one 的Serving分析的更多相关文章

  1. Knative Serving 健康检查机制分析

    作者|  阿里云智能事业群技术专家牛秋霖(冬岛) 导读:从头开发一个Serverless引擎并不是一件容易的事情,今天咱们就从Knative的健康检查说起.通过健康检查这一个点来看看Serverles ...

  2. YII 的源码分析(-)

    做为源码分析的首秀,我就挑了yii(读作歪依依而不是歪爱爱):它的赞美之词我就不多说了,直接入正题.先准备材料,建议直从官网下载yii的源码包(1.1.15). 在demos里边有一个最简单的应用—h ...

  3. [源码解析]HashMap和HashTable的区别(源码分析解读)

    前言: 又是一个大好的周末, 可惜今天起来有点晚, 扒开HashMap和HashTable, 看看他们到底有什么区别吧. 先来一段比较拗口的定义: Hashtable 的实例有两个参数影响其性能:初始 ...

  4. Apache Kafka源码分析 - kafka controller

    前面已经分析过kafka server的启动过程,以及server所能处理的所有的request,即KafkaApis 剩下的,其实关键就是controller,以及partition和replica ...

  5. 高性能Linux服务器 第10章 基于Linux服务器的性能分析与优化

    高性能Linux服务器 第10章    基于Linux服务器的性能分析与优化 作为一名Linux系统管理员,最主要的工作是优化系统配置,使应用在系统上以最优的状态运行.但硬件问题.软件问题.网络环境等 ...

  6. struts2源代码分析(个人觉得非常经典)

    读者如果曾经学习过Struts1.x或者有过Struts1.x的开发经验,那么千万不要想当然地以为这一章可以跳过.实际上Struts1.x与Struts2并无我们想象的血缘关系.虽然Struts2的开 ...

  7. 【Zookeeper】源码分析之Watcher机制(一)

    一.前言 前面已经分析了Zookeeper持久话相关的类,下面接着分析Zookeeper中的Watcher机制所涉及到的类. 二.总体框图 对于Watcher机制而言,主要涉及的类主要如下. 说明: ...

  8. Memcached源码分析之请求处理(状态机)

    作者:Calix 一)上文 在上一篇线程模型的分析中,我们知道,worker线程和主线程都调用了同一个函数,conn_new进行事件监听,并返回conn结构体对象.最终有事件到达时,调用同一个函数ev ...

  9. 【Zookeeper】源码分析之网络通信(二)

    一.前言 前面介绍了ServerCnxn,下面开始学习NIOServerCnxn. 二.NIOServerCnxn源码分析 2.1 类的继承关系 public class NIOServerCnxn ...

随机推荐

  1. Mysql数据库(四)表记录的更新操作

    一.插入表记录 1.使用INSERT...VALUES语句插入新纪录 (1)插入完整数据 mysql> desc tb_manager; +-------+------------------+ ...

  2. ApplicationContextAware使用理解

    接口的作用 当一个类实现了这个接口(ApplicationContextAware)之后,Aware接口的Bean在被初始之后,可以取得一些相对应的资源,这个类可以直接获取spring 配置文件中 所 ...

  3. 【spock】单测竟然可以如此丝滑

    0. 为什么人人都讨厌写单测 在之前的关于swagger文章里提到过,程序员最讨厌的两件事,一件是别人不写文档,另一件就是自己写文档.这里如果把文档换成单元测试也同样成立. 每个开发人员都明白单元测试 ...

  4. leetcode算法小题(3)

    问题描述: 判断一个数是否为回文数 class Solution {      public boolean isPalindrome(int x) {           if(x<0)    ...

  5. plsql + instantclient 连接oracle ( 超简单)

    1.instantclient 下载并解压 instantclient 下载地址 https://www.oracle.com/technetwork/cn/database/features/ins ...

  6. IDEA上tomcat的配置

    IDEA上tomcat的配置   IDEA上集成自己的tomcat,主要就是下面这张表的配置,不累述.

  7. pymssql默认关闭自动模式开启事务行为浅析

    使用Python采集SQL Server数据库服务器磁盘信息时,遇到了一个错误"CONFIG statement cannot be used inside a user transacti ...

  8. Git学习以及使用

    最近学习了下git的使用,不得不感叹真的是甩了svn几条街 官网下载实在太慢,附加一个网站方便大家下载https://github.com/waylau/git-for-win 安装好后打开Git B ...

  9. __new__与__init__的区别和应用场景

    创建实例的时候, 先运行的_new_方法, _new_创建对象 Student object(实例)返回给 _init_ 里面的第一个参数self class Student(object): def ...

  10. 网络安全-主动信息收集篇第二章-三层网络发现之ping

    第三层网络扫描基于TCP/IP.ICMP协议. 优点:可路由.速度比较快 缺点:相对于二层网络扫描较慢,容易被边界防火墙过滤 所有扫描发现技术,都会有相应的对抗办法,所以无论是来自二层的网络扫描还是来 ...