【TensorFlow系列】【六】多模型部署
2018-03-28 00:00
323 查看
TensorFlow的多模型部署,关键在于每个模型拥有一个独立的graph与session,各模型间互不干扰即可。最终直接依据各模型的结果,综合起来做决定。
import tensorflow as tf import numpy as np class Model: def __init__(self,meta_path,ckpt_path,out_tensor_name,input_tensor_name): self.graph = tf.Graph() #恢复模型 with self.graph.as_default(): self.saver = tf.train.import_meta_graph(meta_path) self.session = tf.Session(graph=self.graph) with self.session.as_default(): with self.graph.as_default(): self.saver.restore(self.session,tf.train.latest_checkpoint(ckpt_path)) #获取输入输出tensor self.out = self.graph.get_tensor_by_name(name=out_tensor_name) self.input = self.graph.get_tensor_by_name(name=input_tensor_name) #做预测 def predict(self,image): result = self.session.run(self.out,feed_dict={self.input:image}) index = np.argmax(result,1) return index[0] Age_pre = Model(meta_path='',ckpt_path='',out_tensor_name='softmax:0',input_tensor_name='input:0') Gender_pre = Model(meta_path='',ckpt_path='',out_tensor_name='softmax:0',input_tensor_name='input:0') with tf.Session() as session: image = session.run(fetches='') age = Age_pre.predict(image) gender = Gender_pre.predict(image)
相关文章推荐
- MLSQL如何支持部署SKLearn,Tensorflow,MLLib模型提供API预测服务
- tensorflow模型java部署问碰到了坑,各种坑
- TensorFlow实战系列8--滑动平均模型
- tensorflow入门8 模型部署1
- java加载tensorflow训练好的模型部署成service
- 【TensorFlow系列】【五】利用inception v3 pb模型文件做预测
- tensorflow入门9 模型部署2
- skyline(TEP,TerraGate) Fly文件的BS部署系列(3)贴图,模型等其他文件的发布
- 【TensorFlow系列】【三】冻结模型文件并做inference
- Tensorflow实战学习(二十二)【产品环境模型部署,Docker镜像,Bazel工作区,导出模型,服务器,客户端】
- 将tensorflow训练好的模型部署成sercice服务,并做预测
- TensorFlow实战系列13--LeNet-5 模型
- 走进WPF系列学习之一 如何建立、设计、执行与部署WPF应用程序
- Exchange 2010部署系列之 (一)-架构拓扑及规划
- Tensorflow学习笔记:用minst数据集训练卷积神经网络并用训练后的模型测试自己的BMP图片
- 【并发服务器系列】2 select模型
- 学习笔记TF049:TensorFlow 模型存储加载、队列线程、加载数据、自定义操作
- TensorFlow模型保存和提取方法
- zookeeper学习系列(四)zookeeper数据模型
- ADRMS部署系列之(三)—安装SQL Server