Debugging a Model
After the training is complete, create a local model, debug the model locally, and deploy the model on ModelArts.
Sample Code
In ModelArts notebook, you do not need to enter authentication parameters for session authentication. For details about session authentication of other development environments, see Session Authentication.
- Save the custom inference file and model configuration file to the directory storing the model file generated during training. If the model generated during training is stored in /home/ma-user/work/tensorflow_mlp_mnist_local_mode/train/model/, the inference file customize_service.py and model configuration file config.json are also stored in this directory.
- Create a Conda virtual environment for running models.
1 2 3 4 5 6 7
from modelarts.environment import Environment from modelarts.environment.conda_env import CondaDependencies env = Environment("tensorflow_mlp_mnist") cd = CondaDependencies.create(pip_packages=["tensorflow==1.13.1", "Pillow>=8.0.1"], conda_packages=["python=3.6.2"]) env.conda = cd
- Create a local model.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
from modelarts.session import Session from modelarts.model import Model session = Session() src_local_path = "/home/ma-user/work/tensorflow_mlp_mnist_local_mode/train/" model = Model(session, publish=False, source_location_type="LOCAL_SOURCE", # Type of the model file location source_location=src_local_path + 'model', # Location of the model file environment=env, model_version='1.0.1', model_type='TensorFlow', # AI framework used by the model model_algorithm="image_classification", model_name="tensorflow_mlp_mnist_local_infer")
After a local model is created, you can deploy it as a local service.
- Call the API to publish the model.
1
model.publish_model(obs_location=obs_location)
After the obs_location parameter is specified, the local model file is uploaded to this directory. This parameter can be omitted. See the following example:
1
model.publish_model()
The model file is uploaded to the directory whose name ends with the current timestamp in the default OBS bucket. The directory is displayed after the command is executed:
1
Successfully upload file /home/ma-user/work/tensorflow_mlp_mnist_local_mode/train/model to OBS modelarts-cn-north-4-08aae033/model-0107-224502
Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
session |
Yes |
Object |
Session object. For details about the initialization method, see Session Authentication. |
model_name |
No |
String |
Name of a model that consists of 1 to 64 characters and must start with a letter. Only letters, digits, underscores (_), and hyphens (-) are allowed. If this parameter is not specified, the system automatically generates a model name. |
model_version |
Yes |
String |
Model version in the format of Digit.Digit.Digit. The value range of the digits is [1, 99]. The version number cannot start with 0, for example, 01.01.01. |
publish |
No |
Bool |
Whether to publish a model. The options are as follows:
|
source_location_type |
No |
String |
Model location type. The options are as follows:
|
source_location |
Yes |
String |
Path (parent directory) of the model file
|
environment |
No |
Environment instance |
Environment required for normal model running, such as the Python or TensorFlow version For details, see Table 2. |
source_job_id |
No |
String |
ID of the source training job. If the model is generated from a training job, specify 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, specify 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. The value can only be auto, which indicates an ExeML model (model download is not allowed). If the model is deployed via 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, Spark_MLlib, Scikit_Learn, XGBoost, MindSpore, Image, or PyTorch. |
model_algorithm |
No |
String |
Model algorithm. If the algorithm has been configured in the model configuration file, this parameter can be left blank. Possible options are predict_analysis, object_detection, and image_classification. |
description |
No |
String |
Model description, which contains a maximum of 100 characters and cannot contain the following special characters: !<>=&'" |
execution_code |
No |
String |
OBS path to the execution script. The inference script must be stored in the model directory in the path where the model is located. For details, see the source_location parameter. The script name is fixed to customize_service.py. |
input_params |
No |
params array |
List of input parameters for model inference. By default, this parameter is left blank. If the apis information has been configured in the model configuration file, you do not need to set this parameter. The backend automatically reads the input parameters from the apis field in the configuration file. |
output_params |
No |
params array |
List of output parameters for model inference. By default, this parameter is left blank. If the apis information has been configured in the model configuration file, you do not need to set this parameter. The backend automatically reads the output parameters from the apis field in the configuration file. |
dependencies |
No |
dependency array |
Dependency package required for running the code and model. By default, this parameter is left blank. If the dependencies information has been configured in the model configuration file, you do not need to set this parameter. The backend automatically reads the dependencies to be installed from the dependencies field in the configuration file. |
apis |
No |
String |
List of inference APIs provided by a model. By default, this parameter is left blank. If the apis information has been configured in the model configuration file, you do not need to set this parameter. The backend automatically reads the configured inference API information from the apis field in the configuration file. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
Yes |
String |
Environment name |
conda |
No |
CondaDependencies |
Conda environment. For details, see Table 3. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
channels |
No |
List |
Source for downloading the Python package |
pip_packages |
No |
List |
Python package required by the Conda virtual environment, such as TensorFlow and Pillow |
conda_packages |
No |
List |
Conda package required by the Conda virtual environment, for example, a specified Python version |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
url |
Yes |
String |
Request path of a model inference API |
param_name |
Yes |
String |
Parameter name, which contains a maximum of 64 characters |
param_type |
Yes |
String |
Basic parameter types of JSON schema, including string, object, array, boolean, number, and integer |
min |
No |
Double |
This parameter is optional when param_type is set to int or float. By default, this parameter is left blank. |
max |
No |
Double |
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, which contains a maximum of 100 characters. By default, this parameter is left blank. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
installer |
Yes |
String |
Installation mode, which can only be pip |
packages |
Yes |
package array |
Collection of dependency packages |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
package_name |
Yes |
String |
Name of a dependency package |
package_version |
No |
String |
Version of a dependency package |
restraint |
No |
String |
Version filtering condition. This parameter is mandatory only when package_version is available. Options:
|
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
model |
Yes |
Model object |
Model object, which can be any of the APIs described in this chapter |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot