主要内容

本页采用了机器翻译。点击此处可查看英文原文。

matlab.production_server.client.PipelineClient

命名空间: matlab.production_server

部署到 MATLAB Production Server 机器学习流水线的 Python 客户端

描述

matlab.production_server.client.PipelineClient 类创建一个连接对象,该对象封装 Python® 客户端与部署到 MATLAB® Production Server™ 实例的 LearningPipeline (Statistics and Machine Learning Toolbox) 对象之间的连接。连接建立后,您可以使用 getlearnrun 方法与已部署的 LearningPipeline 对象进行交互。

构造

with PipelineClient(archive,host,port) as client 在 Python 客户端和指定的存档之间创建客户端连接,该存档已部署到在 host:port 上运行的 MATLAB Production Server

输入参量

全部展开

部署到 MATLAB Production Server 的存档,指定为字符串,表示已部署存档的基本文件名,不包含路径或文件扩展名。此参量设置客户端对象的存档属性。

数据类型: string

MATLAB Production Server 实例的主机名或地址,指定为包含 IPv4 或 IPv6 地址的字符串,或者指定为 localhost

数据类型: string

MATLAB Production Server 实例运行的端口号,指定为 165535 之间的整数。

数据类型: int

输出参量

全部展开

封装客户端与托管流水线的 MATLAB Production Server 实例之间连接的对象,指定为 PipelineClient 对象。

方法

公共方法

get

get(client,operation)

get(client,operation,url)

对已部署的流水线应用索引操作,并可选择将结果存储在 URL 中。

输入参量

  • client – 要进行索引的流水线客户端,指定为 PipelineClient 对象

  • operation – 索引操作,指定为使用 MATLAB 语法的 Python 字符串。

  • url – 存储结果的位置,指定为 Python 字符串。

learn

client.learn(nargout, input0,...inputN)

按指定顺序将输入数据传递到流水线中,从而评估与 client 关联的流水线中的所有节点。该函数学习或初始化流水线组件中的任何数据相关参数(可学习参数)。对于流水线中没有数据相关参数的组件,或者已经学习过的组件,使用 learn 等效于使用 run 对象函数。这种方法是客户端的等效方法 learn (Statistics and Machine Learning Toolbox) 流水线函数。

您可以使用返回的流水线通过 run 来对新数据进行推理。

输入参量

  • nargout – 输出参量的数量,指定为整数。

  • input0,...inputN – 已部署流水线的输入,指定为 Python 字符串。您可以将 MAT 或 CSV 文件作为 URL 字符串传递。

run

client.run(nargout, input0,...inputN)

评估相关流水线中所有需要返回输出的节点。该函数会忽略不需要返回输出的节点。该函数返回流水线的输出。这种方法是客户端的等效方法 run (Statistics and Machine Learning Toolbox) 流水线函数。

输入参量

  • nargout – 输出参量的数量,指定为整数。

  • input0,...inputN – 流水线的输入,指定为 Python 字符串。您可以将 MAT 或 CSV 文件作为 URL 字符串传递。

属性

全部展开

此 属性 为只读。

MATLAB Production Server 运行所在的主机,以包含地址的字符串形式返回,或者返回 "localhost"。

此 属性 为只读。

MATLAB Production Server 运行所用的端口号,以 165535 之间的整数形式返回。

示例: 9910

此 属性 为只读。

包含流水线的存档的名称,以字符串形式返回。

此 属性 为只读。

用于访问流水线的网络端点的名称,以 <host>:<port>/<archive> 格式的字符串返回。

示例

全部折叠

初始化客户端并训练流水线。指定主机为 "localhost",端口号为 9910,存档为 "CarOrigin"。Python 客户端需要使用 with...as 语法进行初始化,因此必须在 with 模块内调用 learn 方法。client.learn 方法返回流水线的 learn (Statistics and Machine Learning Toolbox) 函数的输出,并训练已部署的流水线。

import matlab
from production_server.pipeline_client import PipelineClient

with with PipelineClient("carOrigin", "localhost", 9910) as client:
   output = client.learn(1, "file:/input/data/carData.csv", response)

初始化客户端对象并运行流水线。指定主机为 "localhost",端口号为 9910,存档为 "CarOrigin"。Python 客户端需要使用 with...as 语法进行初始化,因此必须在 with 模块内调用 run 方法。client.run 方法返回已训练流水线的 run (Statistics and Machine Learning Toolbox) 方法的输出。

import matlab
from production_server import PipelineClient

with PipelineClient("carOrigin", "localhost", 9910) as client:
   output = client.run(1, carData, response)

初始化客户端对象,然后使用 get 方法获取其属性。如果 Python 中存在该数据的有效表示形式,则可以让 Python 返回索引数据;或者,您可以使用可选的第三个输入参量来指定存储数据的位置。

从训练好的模型中获取前 10 个支持向量。

with PipelineClient("carOrigin", "localhost", 9910) as client:
    v = get(client,"Components.SVM.TrainedModel.SupportVectors(1:10)")

从训练好的模型中获取前 10 个支持向量,并将它们存储在 URL 中,而不是将它们返回给 Python。

with PipelineClient("carOrigin", "localhost", 9910) as client:
    get(client,"Components.SVM.TrainedModel.SupportVectors(1:10)", 
        "file:/data/storage/vectors.txt")

检索整个流水线的数据,并将数据存储在 MAT 文件中。索引操作是流水线的名称。

with PipelineClient("carOrigin", "localhost", 9910) as client:
    get(client, "CarOrigin", "file:/data/storage/CarPipe.mat")

详细信息

全部展开

另请参阅

(Statistics and Machine Learning Toolbox) | (Statistics and Machine Learning Toolbox)

主题