Importing a Model

Function

You can use the API to import a model.

The execution code and model must be uploaded to OBS first. By default, the model generated by a training job is stored in OBS.

URI

POST /v1/{project_id}/models

Table 1 describes the required parameters.
Table 1 Parameter description

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Request Body

Table 2 describes the request parameters.
Table 2 Parameter description

Parameter

Mandatory

Type

Description

model_name

Yes

String

Model name. The value can contain 1 to 64 visible characters, including Chinese characters. Only letters, Chinese characters, digits, hyphens (-), and underscores (_) are allowed.

model_version

Yes

String

Model version in the format of Digit.Digit.Digit. The value range of the digits is [1, 99]. Note that no part of the version number can start with 0. For example, 01.01.01 is not allowed.

source_location

Yes

String

OBS path where the model is located or the template address of the SWR image

source_job_id

No

String

ID of the source training job. If the model is generated from a training job, input this parameter for source tracing. If the model is imported from a third-party meta model, leave this parameter blank. By default, this parameter is left blank.

source_job_version

No

String

Version of the source training job. If the model is generated from a training job, input this parameter for source tracing. If the model is imported from a third-party meta model, leave this parameter blank. By default, this parameter is left blank.

source_type

No

String

Model source type. Currently, the value can only be auto, which indicates ExeML models (model download is not supported). If the model is deployed by a training job, leave this parameter blank. By default, this parameter is left blank.

model_type

Yes

String

Model type. The value can be TensorFlow, MXNet, Caffe, Spark_MLlib, Scikit_Learn, XGBoost, Image, or PyTorch, which is read from the configuration file.

runtime

No

String

Model running environment. The possible values of runtime are related to model_type. For details, see Table 1 Supported AI engines and their runtime.

description

No

String

Model remarks. The value contains a maximum of 100 characters and cannot contain the following special characters and more: &!'\"<>=

model_algorithm

No

String

Model algorithm. If the algorithm is read from the configuration file, this parameter can be left blank. For example, the value can be predict_analysis, object_detection, or image_classification. The value must start with a letter and contain no more than 36 characters. Chinese characters and special characters (&!'\"<>=) are not allowed.

execution_code

No

String

OBS path for storing the execution code. By default, this parameter is left blank. The name of the execution code file is fixed to customize_service.py. The inference code file must be stored in the model directory. If this parameter is left blank, the system can automatically identify the inference code in the model directory.

input_params

No

params array

Collection of input parameters of a model. By default, this parameter is left blank. For details, see Table 3. If the collection of input parameters is read from apis in the configuration file, you only need to provide the initial_config field and do not need to set input_params. That is, input_params is optional when the initial_config field exists.

output_params

No

params array

Collection of output parameters of a model. By default, this parameter is left blank. For details, see Table 3. If the collection of output parameters is read from apis in the configuration file, you only need to provide the initial_config field and do not need to set output_params.

dependencies

No

dependency array

Package required for inference code and model. By default, this parameter is left blank. If the package is read from the configuration file, this parameter can be left blank. Table 4 shows the dependency structure.

model_metrics

No

String

Model precision, which is read from the configuration file

apis

No

String

All apis input and output parameters of the model. If the parameters are read from the configuration file, this parameter can be left blank.

initial_config

No

String

Character string converted from the final model configuration file. It is recommended that the initial_config file be used to provide information about the fields such as apis, dependencies, input_params, and output_params.

workspace_id

No

String

Workspace ID. Default value: 0

model_docs

No

doc array

List of model description documents. A maximum of three documents are supported.

install_type

No

String array

Deployment type. Only lowercase letters are supported. The value can be real-time, edge, or batch. Default value: ["real-time","edge","batch"]

Table 3 params parameters

Parameter

Mandatory

Type

Description

url

No

String

API URL

method

No

String

Request method. Possible values are post and get.

protocol

No

String

Request protocol

param_name

No

String

Parameter name. It is recommended that the parameter name contain a maximum of 64 characters.

param_type

No

String

Parameter type. The value can be int, string, float, timestamp, date, or file.

min

No

Number

This parameter is optional when param_type is set to int or float. By default, this parameter is left blank.

max

No

Number

This parameter is optional when param_type is set to int or float. By default, this parameter is left blank.

param_desc

No

String

Parameter description. It is recommended that the parameter description contain a maximum of 100 characters. By default, this parameter is left blank.

Table 4 dependency parameters

Parameter

Mandatory

Type

Description

installer

Yes

String

Installation mode. Only pip is supported.

packages

Yes

package array

Collection of dependency packages

Table 5 package parameters

Parameter

Mandatory

Type

Description

package_name

Yes

String

Name of a dependency package. Ensure that the package name is correct and exists. Chinese characters and special characters (&!'"<>=) are not allowed.

package_version

No

String

Version of a dependency package. If this parameter is left blank, the latest version is installed by default. Chinese characters and special characters (&!'"<>=) are not allowed.

restraint

No

String

Version restriction. The value can be EXACT, ATLEAST, or ATMOST. This parameter is mandatory only when package_version exists.

Table 6 metric parameters

Parameter

Mandatory

Type

Description

f1

No

Double

F1 score

recall

No

Double

Recall

precision

No

Double

Precision

accuracy

No

Double

Accuracy

Table 7 doc parameters

Parameter

Mandatory

Type

Description

doc_name

Yes

String

Document name, which consists of 1 to 48 visible characters (including Chinese characters). It must start with an uppercase or lowercase English letter, or a Chinese character. Only letters, Chinese characters, digits, hyphens (-), and underscores (_) are allowed.

doc_url

Yes

String

HTTP(S) link of the document

Response Body

Table 8 describes the response parameters.
Table 8 Parameter description

Parameter

Type

Description

model_id

String

Model ID

Samples

The following shows how to import a model whose name is mnist, version is 1.0.0, and type is TensorFlow. The model file comes from an OBS bucket.

  • Sample request
    POST    https://endpoint/v1/{project_id}/models
    {
    "model_name": "mnist",
    "model_version": "1.0.0",
    "source_location": "https://models.obs.cn-north-4.myhuaweicloud.com/mnist",
    "source_job_id": "55",
    "source_job_version": "V100",
    "model_type": "TensorFlow",
    "runtime": "python2.7",
    "description": "mnist model",
    "execution_code": "https://testmodel.obs.cn-north-4.myhuaweicloud.com/customize_service.py",
    "input_params": [
    {
      "url": "/v1/xxx/image",
      "protocol": "http",
      "method": "post",
      "param_name": "image_url",
      "param_type": "string",
      "min": 0,
      "max": 9,
      "param_desc": "http://test/test.jpeg"
    }
    ],
    "output_params": [
    {
      "url": "/v1/xxx/image",
      "protocol": "http",
      "method": "post",
      "param_name": "face_location",
      "param_type": "box",
      "param_desc": "face_location param value description"
    }
    ],
    "dependencies": [
    {
      "installer": "pip",
      "packages": [
        {
          "package_name": "numpy",
          "package_version": "1.5.0",
          "restraint": "ATLEAST"
        }
      ]
    }
    ],
    "model_algorithm": "object_detection",
    "model_metrics":"{\"f1\":0.52381,\"recall\":0.666667,\"precision\":0.466667,\"accuracy\":0.625}",
    "apis": [
    {
      "url": "/v1/xxx/image",
      "protocol": "http",
      "method": "post",
      "input_params": {
        "type": "object",
        "properties": {
          "image_url": {
            "type": "string"
          }
        }
      },
      "output_params": {
        "type": "object",
        "properties": {
          "face_location": {
            "type": "box"
          }
        }
      }
    }
    ]
    }
  • Sample response
    {
      "model_id": "10eb0091-887f-4839-9929-cbc884f1e20e"
    }

Status Code

For details about the status code, see Table 1.