All-in-one 的Serving分析
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分析的更多相关文章
- Knative Serving 健康检查机制分析
作者| 阿里云智能事业群技术专家牛秋霖(冬岛) 导读:从头开发一个Serverless引擎并不是一件容易的事情,今天咱们就从Knative的健康检查说起.通过健康检查这一个点来看看Serverles ...
- YII 的源码分析(-)
做为源码分析的首秀,我就挑了yii(读作歪依依而不是歪爱爱):它的赞美之词我就不多说了,直接入正题.先准备材料,建议直从官网下载yii的源码包(1.1.15). 在demos里边有一个最简单的应用—h ...
- [源码解析]HashMap和HashTable的区别(源码分析解读)
前言: 又是一个大好的周末, 可惜今天起来有点晚, 扒开HashMap和HashTable, 看看他们到底有什么区别吧. 先来一段比较拗口的定义: Hashtable 的实例有两个参数影响其性能:初始 ...
- Apache Kafka源码分析 - kafka controller
前面已经分析过kafka server的启动过程,以及server所能处理的所有的request,即KafkaApis 剩下的,其实关键就是controller,以及partition和replica ...
- 高性能Linux服务器 第10章 基于Linux服务器的性能分析与优化
高性能Linux服务器 第10章 基于Linux服务器的性能分析与优化 作为一名Linux系统管理员,最主要的工作是优化系统配置,使应用在系统上以最优的状态运行.但硬件问题.软件问题.网络环境等 ...
- struts2源代码分析(个人觉得非常经典)
读者如果曾经学习过Struts1.x或者有过Struts1.x的开发经验,那么千万不要想当然地以为这一章可以跳过.实际上Struts1.x与Struts2并无我们想象的血缘关系.虽然Struts2的开 ...
- 【Zookeeper】源码分析之Watcher机制(一)
一.前言 前面已经分析了Zookeeper持久话相关的类,下面接着分析Zookeeper中的Watcher机制所涉及到的类. 二.总体框图 对于Watcher机制而言,主要涉及的类主要如下. 说明: ...
- Memcached源码分析之请求处理(状态机)
作者:Calix 一)上文 在上一篇线程模型的分析中,我们知道,worker线程和主线程都调用了同一个函数,conn_new进行事件监听,并返回conn结构体对象.最终有事件到达时,调用同一个函数ev ...
- 【Zookeeper】源码分析之网络通信(二)
一.前言 前面介绍了ServerCnxn,下面开始学习NIOServerCnxn. 二.NIOServerCnxn源码分析 2.1 类的继承关系 public class NIOServerCnxn ...
随机推荐
- 设计模式(二十)Flyweight模式
当使用new关键字生成类的实例时,需要给其分配足够的内存空间.当程序中需要大量对象时,如果都是用new关键字来分配内存,将会消耗大量内存空间.Flyweight模式就是尽量避免new出实例,而是通过尽 ...
- js图片随机切换
使用js做到随机切换图片 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- JavaScript基础修炼(14)——WebRTC在浏览器中如何获得指定格式的PCM数据
目录 一. PCM格式是什么 二. 浏览器中的音频采集处理 三. 需求实现 方案1--服务端FFmpeg实现编码 方案2--ScriptProcessorNode手动处理数据流 参考文献 示例代码托管 ...
- Python+requests+unittest+excel实现接口自动化测试框架(摘录)
一.框架结构: 工程目录 二.Case文件设计 三.基础包 base 3.1 封装get/post请求(runmethon.py) 1 import requests 2 import json 3 ...
- php从数据库获取数据并遍历在表格中
<?php /*连接数据库并以一个数组的形式获得数据*/ header("Content-type:text/html;charset=UTF-8"); $con = mys ...
- Spring Boot (日志篇):Log4j2整合ELK,搭建实时日志平台
一.安装JDK1.8以上版本 1.从Oracle官网上下载Linux x64版本的 下载地址: http://www.oracle.com/technetwork/java/javase/downlo ...
- 暑期集训20190730 取模(mod)
[题目描述] 给定一个长度为n的非负整数序列a,你需要支持以下操作: 1:给定l,r,输出a[l]+a[l+1]+…+a[r]. 2:给定l,r,x,将a[l],a[l+1],…,a[r]对x取模. ...
- MVC5用户控件
1. 添加一个model,用于给用户控件传递数据: 2.添加一个部分视图 . 3. 部分视图中,引入model,用于传递数据 4. 在要插入用户控件的地方,这样写 @Html.Partial(&quo ...
- Nginx篇--最初级用法web
最近很久都没有写博客了,一来主要是时间不够每天回到家都接近晚上11点了,但是以后每天还是保证一篇随笔.好用来整理总结自己的知识. web服务器很有多例如:Apache nginx tengine li ...
- jquery获取input输入框中的值
如何用javascript获取input输入框中的值,js/jq通过name.id.class获取input输入框中的value 先准备一段 HTML <input type="tex ...