Deploy a trained model

简介: 本次教程的目的是带领大家学会用 Tensorflow serving 部署训练好的模型这里我们用到的数据集是 Fashion MNIST,所以训练出来的模型可以实现以下几个类别的分类

本次教程的目的是带领大家学会用 Tensorflow serving 部署训练好的模型

这里我们用到的数据集是 Fashion MNIST,所以训练出来的模型可以实现以下几个类别的分类

'T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'

因为这篇教程主要关注部署,所以我们直接从已经训练好的模型开始,保存的格式是 SavedModel,如上图所示

在这之前呢,我们需要先安装好 tensorflow_model_server

接下来我们可以在控制台执行以下指令,就可以启动一个 serving 服务了,我们可以通过 REST API 进行请求,并返回预测结果

import requests
headers = {"content-type": "application/json"}
json_response = requests.post('http://localhost:8501/v1/models/fashion_mnist:predict', data=data, headers=headers)

predictions = json.loads(json_response.text)["predictions"]

show(0, "The model thought this was a {} (class {}), and it was actually a {} (class {})".format(class_names[np.argmax(predictions[0])], np.argmax(predictions[0]), class_names[test_labels[0]], test_labels[0]))

上图是通过请求,然后预测得到的结果,到此,我们实现了模型的 Tensorflow serving 的部署

代码链接: https://codechina.csdn.net/csdn_codechina/enterprise_technology/-/blob/master/tensorflow_serving.ipynb

目录
相关文章
|
2月前
|
TensorFlow API 算法框架/工具
【Tensorflow】解决Inputs to eager execution function cannot be Keras symbolic tensors, but found [<tf.Te
文章讨论了在使用Tensorflow 2.3时遇到的一个错误:"Inputs to eager execution function cannot be Keras symbolic tensors...",这个问题通常与Tensorflow的eager execution(急切执行)模式有关,提供了三种解决这个问题的方法。
29 1
|
2月前
|
机器学习/深度学习 TensorFlow 算法框架/工具
【Tensorflow+keras】解决cuDNN launch failure : input shape ([32,2,8,8]) [[{{node sequential_1/batch_nor
在使用TensorFlow 2.0和Keras训练生成对抗网络(GAN)时,遇到了“cuDNN launch failure”错误,特别是在调用self.generator.predict方法时出现,输入形状为([32,2,8,8])。此问题可能源于输入数据形状与模型期望的形状不匹配或cuDNN版本不兼容。解决方案包括设置GPU内存增长、检查模型定义和输入数据形状、以及确保TensorFlow和cuDNN版本兼容。
32 1
|
4月前
|
人工智能 自然语言处理 PyTorch
CLIP(Contrastive Language-Image Pre-training)
CLIP(Contrastive Language-Image Pre-training)
179 0
|
5月前
|
机器学习/深度学习 数据采集 自然语言处理
Pre-trained Model
“【5月更文挑战第30天】”
36 0
|
自然语言处理 算法
SIFRank New Baseline for Unsupervised Keyphrase Extraction Based on Pre-Trained Language Model
在社交媒体上,面临着大量的知识和信息,一个有效的关键词抽取算法可以广泛地被应用的信息检索和自然语言处理中。传统的关键词抽取算法很难使用外部的知识信息。
151 0
SIFRank New Baseline for Unsupervised Keyphrase Extraction Based on Pre-Trained Language Model
|
5月前
|
机器学习/深度学习 自然语言处理 PyTorch
Model Inference
模型推理(Model Inference)是指使用已经训练好的机器学习模型来对新数据进行预测或分类的过程。模型推理是机器学习中的一个重要环节,其目的是利用训练好的模型对新数据进行预测或分类,从而得到结果。
254 1
|
机器学习/深度学习 并行计算 PyTorch
【PyTorch】Training Model
【PyTorch】Training Model
82 0
|
机器学习/深度学习 编解码 自然语言处理
BEIT: BERT Pre-Training of Image Transformers论文解读
本文介绍了一种自监督视觉表示模型BEIT,即图像transformer的双向编码器表示。继自然语言处理领域开发的BERT之后
565 0
|
机器学习/深度学习 传感器 编解码
Remote Sensing Images Semantic Segmentation with General Remote Sensing Vision Model via a Self-Supe
Remote Sensing Images Semantic Segmentation with General Remote Sensing Vision Model via a Self-Supe
93 0
Remote Sensing Images Semantic Segmentation with General Remote Sensing Vision Model via a Self-Supe
|
Linux PyTorch 算法框架/工具
Some weights of the model checkpoint at mypath/bert-base-chinese were not used when initializing Ber
Some weights of the model checkpoint at mypath/bert-base-chinese were not used when initializing Ber