客户端软件python(客户端软件通常称为web什么)

菲律宾亚星公司 23 5

  云栖君导读:本系列将介绍如何在阿里云容器服务上运行Kubeflow, 本文介绍如何使用TensorFlow Serving加载训练模型并且进行模型预测。

  第一篇:阿里云上使用JupyterHub

  https://click.aliyun.com/m/1000003285/

  第二篇:阿里云上小试TFJob

  https://click.aliyun.com/m/1000003286/

  第三篇:利用TFJob运行分布式TensorFlow

  https://click.aliyun.com/m/1000003287/

客户端软件python(客户端软件通常称为web什么)-第1张图片-亚星国际官网

  第四篇:利用TFJob导出分布式TensorFlow模型

  https://click.aliyun.com/m/1000003288/

  第五篇:利用TensorFlow Serving进行模型预测(本文)

  TensorFlow Serving简介

  TensorFlow Serving是Google开源的一个灵活的、高性能的机器学习模型服务系统,能够简化并加速从模型到生产应用的过程。它除了原生支持TensorFlow模型,还可以扩展支持其他类型的机器学习模型。

  

  在前面的文章中,已经介绍了如何进行单机和分布式的模型训练,并且可以将训练的导出模型放置到分布式存储上。在本文中,会介绍模型如何被发布到TensorFlow Serving系统服务器端。并通过gRPC客户端提交请求,由服务端返回预测结果。

  在分布式存储查看训练的模型

  在前一篇文章中,我们已经将训练的模型导出到NAS上,可以先查看一下导出的模型。在serving的文件夹指定了模型的,即mnist名称;而mnist的下一层是模型的版本。

  

  在模型导出的章节中,已经在这个NAS存储上创建了对应的pv: tf-serving-pv和pvc: tf-serving-pvc, 而TensorFlow Serving将从pvc中加载模型。

  

  利用Kubeflow启动TensorFlow Serving

  

  

  

  

客户端软件python(客户端软件通常称为web什么)-第1张图片-亚星国际官网

  部署完成后可以通过kubectl get deploy查询到TensorFlow Serving运行状态

  

  查看TensorFlow Serving运行日志,发现模型已经加载

客户端软件python(客户端软件通常称为web什么)-第1张图片-亚星国际官网

  2018-06-19 06:50:19.185785:

客户端软件python(客户端软件通常称为web什么)-第1张图片-亚星国际官网

  I external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA

  2018-06-19 06:50:19.202907:

  I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:161] Restoring SavedModel bundle.

  2018-06-19 06:50:19.418625: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:196] Running LegacyInitOp on SavedModel bundle.

  2018-06-19 06:50:19.425357:

  I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:291] SavedModel load for tags { serve }; Status: success. Took 550707 microseconds.

  2018-06-19 06:50:19.430435:

  I tensorflow_serving/core/loader_harness.cc:86] Successfully loaded servable version {name: mnist version: 1}

  以及对外的暴露的服务ip和端口

  

  这里可以看到gRPC对外服务ip为xx.xx.xx.xx,对外服务的端口为9000

  使用gRPC客户端访问TensorFlow Serving

  通过kubectl run运行gRPC客户端, 并且点击回车,登录到Pod里

客户端软件python(客户端软件通常称为web什么)-第1张图片-亚星国际官网

  kubectl run -i --tty mnist-client --image=registry.cn-hangzhou.aliyuncs.com/tensorflow-samples/tf-mnist-client-demo --restart=Never --command -- /bin/bash

  If you don't see a command prompt, try pressing enter.

  运行客户端python代码:

客户端软件python(客户端软件通常称为web什么)-第1张图片-亚星国际官网

  # export TF_MNIST_IMAGE_PATH=1.png

  # export TF_MODEL_SERVER_HOST=172.19.4.241

  # python mnist_client.py

  /usr/local/lib/python2.7/dist-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.

  from ._conv import register_converters as _register_converters

  

  

  这样我们训练导出的模型,就可以直接通过gRPC的客户端访问了,从而实现在线预测。结合前面的文章,我们已经介绍了从深度学习的模型训练,模型导出到模型部署上线的全路径通路。

  删除TensorFlow Serving

  总结

  这个例子介绍了如何通过Kubeflow部署TensorFlow Serving, 并且加载阿里云NAS上存储的模型,并且提供模型预测服务。

  Kubeflow部署机器学习应用非常简单,但是只有应用层的简便是不够的;云端基础设施的自动化集成也是非常重要的,比如GPU/NAS/OSS以及负载均衡的无缝调用,而这方面使用阿里云Kubernetes容器服务可以大幅度降低数据科学家的模型交付难度。

标签: 客户端软件python

发表评论 (已有5条评论)

评论列表

2025-04-20 02:10:04

外服务的端口为9000  使用gRPC客户端访问TensorFlow Serving  通过kubectl run运行gRPC客户端, 并且点击回车,登录到Pod里  kubectl run -i --tty mnist-client --image=re

2025-04-20 10:51:59

atform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary wa

2025-04-20 11:36:34

  云栖君导读:本系列将介绍如何在阿里云容器服务上运行Kubeflow, 本文介绍如何使用TensorFlow Serving加载训练模型并且进行模型预测。  第一篇:阿里云上使用JupyterHub  https://click.aliyun.com/m/1000003285/  第

2025-04-20 11:02:24

务系统,能够简化并加速从模型到生产应用的过程。它除了原生支持TensorFlow模型,还可以扩展支持其他类型的机器学习模型。    在前面的文章中,已经介绍了如何进行单机和分布式的模型训练,并且可以将训练的导出模型放置到

2025-04-20 00:19:50

  云栖君导读:本系列将介绍如何在阿里云容器服务上运行Kubeflow, 本文介绍如何使用TensorFlow Serving加载训练模型并且进行模型预测。  第一篇:阿里云上使用JupyterHub  https://click.aliyun.