Skip to content

Model Management Service- 示例

以下示例说明了如何使用提供的端点。

说明

为避免与 JSON 语法混淆,在以下示例中使用尖括号而不是大括号来表示占位符。

上传含版本元数据和二进制文件的模型

请求:

POST /api/modelmanagement/v3/models
X-XSRF-TOKEN: `<xsrf_token>`

form-datametadata键提供以下内容:

{
 "name":"Model 1",
 "description":"Model 1",
 "type":"Protobuf file",
 "lastVersion": {
 "number":1.0,
 "expirationDate":"2019-10-01T12:00:00.001",
 "dependencies": [{
 "name": "sklearn-theano",
 "type":"Python",
 "version":"2.7"
 }],
 "io": {
 "consumes":"CSV",
 "input": [{
 "name": "variablename1",
 "type": "integer",
 "description": "description for variablename1",
 "value":5
 }],
 "output": [{
 "name": "outputname1",
 "type": "integer",
 "description": "description for outputname1",
 "value":null
 }],
 "optionalParameters": {
 "freeFormParams": "for the author to use",
 "param1": "value1"
 }
 },
 "producedBy": [<existing_model_id>, <other_existing_model_id>],
 "kpi": [{
 "name": "error rate",
 "value":0.9
 }]
 }
}

form-datafile键必须包含模型二进制文件的有效载荷。

响应:

{
 "id": <new_model_id>,
 "name":"Model 1",
 "description":"Model 1",
 "type":"PDF File",
 "author": "creator@siemens.com",
 "lastVersion": {
 "id": <new_version_id>,
 "number":1.0,
 "expirationDate":"2019-10-01T12:00:00.001",
 "author": "user@siemens.com",
 "creationDate":"2018-10-01T12:00:00.001",
 "dependencies": [{
 "name": "sklearn-theano",
 "type":"Python",
 "version":"2.7"
 }],
 "io": {
 "consumes":"CSV",
 "input": [{
 "name": "variablename1",
 "type": "integer",
 "description": "description for variablename1",
 "value":5
 }],
 "output": [{
 "name": "outputname1",
 "type": "integer",
 "description": "description for outputname1",
 "value":null
 }],
 "optionalParameters": {
 "freeFormParams": "for the author to use",
 "param1":"value1"
 }
 },
 "producedBy": [<existing_model_id>, <other_existing_model_id>],
 "kpi": [{
 "name": "error rate",
 "value":0.9
 }]
 }
}

上传模型的新版本

请求:

POST /api/modelmanagement/v3/models/<model_id>/versions
X-XSRF-TOKEN: `<xsrf_token>`

form-datametadata键提供以下内容:

{
 "number":1.0,
 "expirationDate":"2019-10-01T12:00:00.001",
 "dependencies": [{
 "name": "sklearn-theano",
 "type":"Python",
 "version":"1.7"
 }],
 "io": {
 "consumes":"CSV",
 "input": [{
 "name": "variablename1",
 "type": "integer",
 "description": "description for variablename1",
 "value":5
 }],
 "output": [{
 "name": "outputname1",
 "type": "integer",
 "description": "description for outputname1",
 "value":null
 }],
 "optionalParameters": {
 "freeFormParams": "for the author to use",
 "param1":"value1"
 }
 },
 "producedBy": [<existing_model_id>, <other_existing_model_id>],
 "kpi": [{
 "name": "error rate",
 "value":0.9
 }]
}

form-datafile键必须包含模型二进制文件的有效载荷。

响应:

{
 "id": <new_version_id>,
 "number":1.0,
 "expirationDate":"2019-10-01T12:00:00.001",
 "author": "user@siemens.com",
 "creationDate":"2018-10-01T12:00:00.001",
 "dependencies": [{
 "name": "sklearn-theano",
 "type":"Python",
 "version":"1.7"
 }],
 "io": {
 "consumes":"CSV",
 "input": [{
 "name": "variablename1",
 "type": "integer",
 "description": "description for variablename1",
 "value":5
 }],
 "output": [{
 "name": "outputname1",
 "type": "integer",
 "description": "description for outputname1",
 "value":null
 }],
 "optionalParameters": {
 "freeFormParams": "for the author to use",
 "param1":"value1"
 }
 },
 "producedBy": [<existing_model_id>, <other_existing_model_id>],
 "kpi": [{
 "name": "error rate",
 "value":0.9
 }]
}

更新模型

PATCH请求用于有选择地更新模型元数据及其版本的特定属性。更新数组字段时,必须将整个数组作为输入提供,因为该服务完全替换了相应的数组。
例如,在更新 dependencies 字段时,必须提供整个项目列表。Model Management Service 使用请求中提供的项目完全替换存储的属性。这也适用于ioproduced_bykpi字段。

除了authorcreationDateid之外,模型的任何字段都可以更新,包括其版本(属性lastVersion)。

请注意,如果没有提供比存储版本更高的版本,则number属性会自动递增。

请求:

PATCH /api/modelmanagement/v3/models/<model_id>
X-XSRF-TOKEN: `<xsrf_token>`

form-datametadata键提供以下内容:

{
 "name":"new model name",
 "lastVersion":
 {
 "number":1.4,
 "io": {
 "consumes":"CSV",
 "input": [{
 "name": "variablename1",
 "type": "integer",
 "description": "description for variablename1",
 "value":5
 },
 {
 "name": "newVarName",
 "type": "string",
 "description": "description for newVarName, e.g. path",
 "value": "/usr/lib/zeppelin/some.c"
 }
 ]
 },
 }
}

form-datafile键必须包含模型二进制文件的有效载荷。

响应:

{
 "id":<model_id>,
 "name":"new model name",
 "description": "old model description",
 "author": "user@siemens.com",
 "lastVersion":
 {
 "id": <version_id>,
 "number":1.0,
 "expirationDate":"2019-10-01T12:00:00.001",
 "author": "user@siemens.com",
 "creationDate":"2018-10-01T12:00:00.001",
 "dependencies": [{
 "name": "sklearn-theano",
 "type":"Python",
 "version":"1.7"
 }],
 "io": {
 "consumes":"CSV",
 "input": [{
 "name": "variablename1",
 "type": "integer",
 "description": "description for variablename1",
 "value":5
 },
 {
 "name": "newVarName",
 "type": "string",
 "description": "description for newVarName, e.g. path",
 "value": "/usr/lib/zeppelin/some.c"
 }
 ],
 "output": [{
 "name": "outputname1",
 "type": "integer",
 "description": "description for outputname1",
 "value":null
 }],
 "optionalParameters": {
 "freeFormParams": "for the author to use",
 "param1":"value1"
 }
 },
 "producedBy": [<existing_model_id>, <other_existing_model_id>],
 "kpi": [{
 "name": "error rate",
 "value":0.9
 }]
 }
}

更新模型的最新版本

请求:

PATCH /api/modelmanagement/v3/models/<model_id>/versions/last
X-XSRF-TOKEN: <xsrf_token>

除了authorcreationDateid之外,版本的任何字段都可以更新。

form-datametadata键提供以下内容:

{
 "number":1.2,
 "expirationDate":"2019-10-01T12:00:00.001",
 "dependencies": [{
 "name": "sklearn-theano",
 "type":"Python",
 "version":"1.7"
 },
 {
 "name":numpy,
 "type":"Python",
 "version":"1.15"
 }],
 "io": {
 "consumes":"CSV",
 "input": [{
 "name": "variablename1",
 "type": "integer",
 "description": "description for variablename1",
 "value":5
 }],
 "output": [{
 "name": "outputname1",
 "type": "integer",
 "description": "description for outputname1",
 "value":null
 }],
 "optionalParameters": {
 "freeFormParams": "for the author to use",
 "param1":"value1"
 }
 },
 "producedBy": [<existing_model_id>, <other_existing_model_id>],
 "kpi": [{
 "name": "error rate",
 "value":0.9
 }]
}

form-datafile键必须包含模型二进制文件的有效载荷。

响应:

{
 "id": <version_id>,
 "number":1.2,
 "expirationDate":"2019-10-01T12:00:00.001",
 "author": "user@siemens.com",
 "creationDate":"2018-10-01T12:00:00.001",
 "dependencies": [{
 "name": "sklearn-theano",
 "type":"Python",
 "version":"1.7"
 },
 {
 "name":numpy,
 "type":"Python",
 "version":"1.15"
 }],
 "io": {
 "consumes":"CSV",
 "input": [{
 "name": "variablename1",
 "type": "integer",
 "description": "description for variablename1",
 "value":5
 }],
 "output": [{
 "name": "outputname1",
 "type": "integer",
 "description": "description for outputname1",
 "value":null
 }],
 "optionalParameters": {
 "freeFormParams": "for the author to use",
 "param1":"value1"
 }
 },
 "producedBy": [<existing_model_id>, <other_existing_model_id>],
 "kpi": [{
 "name": "error rate",
 "value":0.9
 }]
}

列出可用模型

其中列出了所有的可用模型,以及它们的最新版本。

请求:

GET /api/modelmanagement/v3/models
Accept: `application/json`

响应:

{[
 {
 "id": <model1_id>,
 "name": "some model 1",
 "description":"Some Model 1",
 "type":"PB file",
 "author": "user@siemens.com",
 "lastVersion": {
 "id": <version1_id>,
 "number":1.0,
 "expirationDate":"2019-10-01T12:00:00.001",
 "author": "user@siemens.com",
 "creationDate":"2018-10-01T12:00:00.001",
 "dependencies": [{
 "name": "sklearn-theano",
 "type":"Python",
 "version":"1.7"
 }],
 "io": {
 "consumes":"CSV",
 "input": [{
 "name": "variablename1",
 "type": "integer",
 "description": "description for variablename1",
 "value":5
 }],
 "output": [{
 "name": "outputname1",
 "type": "integer",
 "description": "description for outputname1",
 "value":null
 }],
 "optionalParameters": {
 "freeFormParams": "for the author to use",
 "param1":"value1"
 }
 },
 "producedBy": [<existing_model_id>, <other_existing_model_id>],
 "kpi": [{
 "name": "error rate",
 "value":0.9
 }]
 }
 },
 {
 "id": <model2_id>,
 "name": "some model 2",
 "description":"Some Model 2",
 "type":"JSON file",
 "author": "user@siemens.com",
 "lastVersion": {
 "id": <version1_id>,
 "number":1.0,
 "expirationDate":"2019-11-01T12:00:00.001",
 "author": "user@siemens.com",
 "creationDate":"2018-10-01T12:00:00.001",
 "dependencies": [{
 "name": "sklearn-theano",
 "type":"Python",
 "version":"1.7"
 }],
 "io": {
 "consumes":"CSV",
 "input": [{
 "name": "variablename1",
 "type": "integer",
 "description": "description for variablename1",
 "value":5
 }],
 "output": [{
 "name": "outputname1",
 "type": "integer",
 "description": "description for outputname1",
 "value":null
 }],
 "optionalParameters": {
 "freeFormParams": "for the author to use",
 "param1":"value1"
 }
 },
 "producedBy": [<yet_another_existing_model_id>, <and_another_existing_model_id>],
 "kpi": [{
 "name": "error rate",
 "value":0.9
 }]
 }
 }],
 "page": {
 "number":0,
 "size":14,
 "totalPages":1,
 "totalElements":14
 }
}

获取模型的元数据

请求:

GET /api/modelmanagemen/v3/models/<model_id>`

响应:

{
 "id": <model_id>,
 "name": "some_model",
 "description":"Model 1",
 "type":"PDF File",
 "author": "creator@siemens.com",
 "lastVersion": {
 "id": <version_id>,
 "number":1.0,
 "expirationDate":"2019-10-01T12:00:00.001",
 "author": "user@siemens.com",
 "creationDate":"2018-10-01T12:00:00.001",
 "dependencies": [{
 "name": "sklearn-theano",
 "type":"Python",
 "version":"1.7"
 }],
 "io": {
 "consumes":"CSV",
 "input": [{
 "name": "variablename1",
 "type": "integer",
 "description": "description for variablename1",
 "value":5
 }],
 "output": [{
 "name": "outputname1",
 "type": "integer",
 "description": "description for outputname1",
 "value":null
 }],
 "optionalParameters": {
 "freeFormParams": "for the author to use",
 "param1":"value1"
 }
 },
 "producedBy": [<existing_model_id>, <other_existing_model_id>],
 "kpi": [{
 "name": "error rate",
 "value":0.9
 }]
 }
}

下载模型的元数据或最新版本的有效载荷

此请求可用于根据“Content-Type”消息头下载最新版本的元数据或有效载荷。如果Content-Type被指定为application/octet-stream,则服务返回最新版本的有效载荷。 在此示例中,Content-Type 被指定为application/json,为其返回最新版本的元数据:

GET /api/modelmanagement/v3/<model_id>/versions/<version_id> HTTP/1.1
X-XSRF-TOKEN: `<x-xsrf-token>`
Content-Type: `application/json`

响应:

{
 "id": <version_id>,
 "number":1.0,
 "expirationDate":"2019-10-01T12:00:00.001",
 "author": "user@siemens.com",
 "creationDate":"2018-10-01T12:00:00.001",
 "dependencies": [{
 "name": "sklearn-theano",
 "type":"Python",
 "version":"1.7"
 }],
 "io": {
 "consumes":"CSV",
 "input": [{
 "name": "variablename1",
 "type": "integer",
 "description": "description for variablename1",
 "value":5
 }],
 "output": [{
 "name": "outputname1",
 "type": "integer",
 "description": "description for outputname1",
 "value":null
 }],
 "optionalParameters": {
 "freeFormParams": "for the author to use",
 "param1":"value1"
 }
 },
 "producedBy": [<existing_model_id>, <other_existing_model_id>],
 "kpi": [{
 "name": "error rate",
 "value":0.9
 }]
}

获取模型特定版本的元数据或有效载荷

此请求可用于下载模型特定版本的元数据或有效载荷。如果Content-Type消息头被指定为application/octet-stream,则服务返回指定版本的有效载荷。 在此示例中,Content-Type被指定为application/json,服务将为其返回模型指定版本的元数据。

GET /api/modelmanagement/v3/models/<model_id>/versions/<version_id> HTTP/1.1
Content-Type: `application/json`
X-XSRF-TOKEN: `<token>`

响应:

{
 "id": <version_id>,
 "number":1.0,
 "expirationDate":"2019-10-01T12:00:00.001",
 "author": "user@siemens.com",
 "creationDate":"2018-10-01T12:00:00.001",
 "dependencies": [{
 "name": "sklearn-theano",
 "type":"Python",
 "version":"1.7"
 }],
 "io": {
 "consumes":"CSV",
 "input": [{
 "name": "variablename1",
 "type": "integer",
 "description": "description for variablename1",
 "value":5
 }],
 "output": [{
 "name": "outputname1",
 "type": "integer",
 "description": "description for outputname1",
 "value":null
 }],
 "optionalParameters": {
 "freeFormParams": "for the author to use",
 "param1":"value1"
 }
 },
 "producedBy": [<existing_model_id>, <other_existing_model_id>],
 "kpi": [{
 "name": "error rate",
 "value":0.9
 }]
}

删除模型

删除模型时,将依次删除其所有相关版本。 按从最小版本号到最大版本号的顺序删除版本。 在删除所有关联的元数据和有效载荷文件后,将删除模型本身。

DELETE /api/modelmanagement/v3/models/<model_id>`
X-XSRF-TOKEN: `<xsrf-token>`

响应:

Status:204 - No content

删除模型的最新版本

DELETE /api/modelmanagement/v3/models/<model_id>/versions/last
X-XSRF-TOKEN: `<xsrf-token>`

响应:

Status:204 - No content

删除模型的特定版本

必须为此服务指定模型 ID 和版本 ID。

DELETE /api/modelmanagement/v3/models/<model_id>/versions/<version_id>
X-XSRF-TOKEN: `<xsrf-token>`

响应:

Status:204 - No content

还有问题?

向社区提问


除非另行声明,该网站内容遵循MindSphere开发许可协议.


Last update: June 26, 2019