Specifications for Editing a Model Configuration File
You must edit the config.json file when publishing a model. The configuration file describes the model usage, computing framework, accuracy, inference code dependency package, and model API.
Configuration File Format
The configuration file is in JSON format. Table 1 describes the parameters.
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
model_algorithm |
Yes |
String |
Model algorithm, which shows the model usage. The value must start with a letter and contain no more than 36 characters. Chinese characters and special characters (&!'\"<>=) are not allowed. Major model algorithms include image_classification, object_detection, and predict_analysis. |
model_type |
Yes |
String |
Model AI engine, which indicates the computing framework used by a model. Major AI engines and Image are supported.
|
runtime |
No |
String |
Model runtime environment. Python 2.7 is used by default. The value of runtime depends on model_type. If model_type is set to Image, you do not need to set runtime. If model_type is set to a mainstream framework, select a runtime environment matching the engine. For details about the supported runtime environments, see Supported AI Engines for ModelArts Inference. If your model must run on specified CPUs or GPUs, select the CPUs or GPUs based on the runtime suffix. If the runtime does not contain the CPU or GPU information, check the runtime description in Supported AI Engines for ModelArts Inference. |
metrics |
No |
Object |
Model precision information, including the F1 score, recall, precision, and accuracy. For details about the metrics object structure, see Table 2. The result is displayed in the model precision area on the AI application details page. |
apis |
No |
API array |
Structure data of requests received and returned by a model. It is a RESTful API array provided by a model. For details about the API structure, see Table 3. For details about the code example, see Code Example of apis Parameters.
|
dependencies |
No |
Dependency array |
Package on which the model inference code depends, which is structure data. You must provide the package name, installation method, and version constraints. The dependency package can be installed only using pip. Table 6 describes the dependency array. If the model package does not contain the customize_service.py inference code file, you do not need to set dependencies. Dependency packages cannot be installed for custom image models.
NOTE:
The dependencies parameter accepts multiple dependency arrays in a list format. It applies to scenarios where the default installation packages have dependency relationships. The top packages are installed first. The wheel package can be used for dependency installation, and it must be stored in the same directory as the model file. For details, see How Do I Edit the Installation Package Dependency Parameters in a Model Configuration File When Importing a Model? |
health |
No |
health data structure |
Health check API configuration. This parameter is mandatory only when model_type is set to Image. To ensure uninterrupted services during a rolling upgrade, ModelArts requires a health check API. For details about the health data structure, see Table 8. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
f1 |
No |
Number |
F1 score. The value is rounded to 17 decimal places. |
recall |
No |
Number |
Recall. The value is rounded to 17 decimal places. |
precision |
No |
Number |
Precision. The value is rounded to 17 decimal places. |
accuracy |
No |
Number |
Accuracy. The value is rounded to 17 decimal places. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
url |
No |
String |
Request path. The default value is a slash (/). For a custom image model (model_type is Image), set this parameter to the actual request path exposed in the image. For a non-custom image model (model_type is not Image), the URL can only be /. |
method |
No |
String |
Request method. The default value is POST. |
request |
No |
Object |
Request body. For details, see Table 4. |
response |
No |
Object |
Response body. For details, see Table 5. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
Content-type |
No for real-time services Yes for batch services |
String |
Data is sent in a specified content format. The default value is application/json. The options are as follows:
NOTE:
For machine learning models, only application/json is supported. |
data |
No for real-time services Yes for batch services |
String |
The request body is described in JSON schema. For details about the parameter description, see the official guide. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
Content-type |
No for real-time services Yes for batch services |
String |
Data is sent in a specified content format. The default value is application/json.
NOTE:
For machine learning models, only application/json is supported. |
data |
No for real-time services Yes for batch services |
String |
The response body is described in JSON schema. For details about the parameter description, see the official guide. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
installer |
Yes |
String |
Installation method. Only pip is supported. |
packages |
Yes |
package array |
Dependency package collection. For details about the package array, see Table 7. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
package_name |
Yes |
String |
Dependency package name. Chinese characters and special characters (&!'"<>=) are not allowed. |
package_version |
No |
String |
Dependency package version. Leave it blank if it is not required. Chinese characters and special characters (&!'"<>=) are not allowed. |
restraint |
No |
String |
Version restriction. This parameter is mandatory only when package_version is configured. Possible values are EXACT, ATLEAST, and ATMOST.
|
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
check_method |
Yes |
String |
Health check method. The value can be HTTP or EXEC.
|
command |
No |
String |
Health check command. This parameter is mandatory when check_method is set to EXEC. |
url |
No |
String |
Request URL of a health check API. This parameter is mandatory when check_method is set to HTTP. |
protocol |
No |
String |
Request protocol of a health check API. The default value is http. This parameter is mandatory when check_method is set to HTTP. |
initial_delay_seconds |
No |
String |
Delay for initializing the health check. |
timeout_seconds |
No |
String |
Health check timeout. |
period_seconds |
Yes |
String |
Health check period, in seconds. Enter a positive integer no more than 2147483647. |
failure_threshold |
Yes |
String |
Maximum number of health check failures. Enter a positive integer no more than 2147483647. |
Code Example of apis Parameters
[{ "url": "/", "method": "post", "request": { "Content-type": "multipart/form-data", "data": { "type": "object", "properties": { "images": { "type": "file" } } } }, "response": { "Content-type": "applicaton/json", "data": { "type": "object", "properties": { "mnist_result": { "type": "array", "item": [ { "type": "string" } ] } } } } }]
Example of an Object Detection Model Configuration File
The following code uses the TensorFlow engine as an example. You can modify the model_type parameter based on the actual engine type.
- Model input
Value: image files
- Model output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
{ "detection_classes": [ "face", "arm" ], "detection_boxes": [ [ 33.6, 42.6, 104.5, 203.4 ], [ 103.1, 92.8, 765.6, 945.7 ] ], "detection_scores": [0.99, 0.73] }
- Configuration file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
{ "model_type": "TensorFlow", "model_algorithm": "object_detection", "metrics": { "f1": 0.345294, "accuracy": 0.462963, "precision": 0.338977, "recall": 0.351852 }, "apis": [{ "url": "/", "method": "post", "request": { "Content-type": "multipart/form-data", "data": { "type": "object", "properties": { "images": { "type": "file" } } } }, "response": { "Content-type": "application/json", "data": { "type": "object", "properties": { "detection_classes": { "type": "array", "items": [{ "type": "string" }] }, "detection_boxes": { "type": "array", "items": [{ "type": "array", "minItems": 4, "maxItems": 4, "items": [{ "type": "number" }] }] }, "detection_scores": { "type": "array", "items": [{ "type": "number" }] } } } } }], "dependencies": [{ "installer": "pip", "packages": [{ "restraint": "EXACT", "package_version": "1.15.0", "package_name": "numpy" }, { "restraint": "EXACT", "package_version": "5.2.0", "package_name": "Pillow" } ] }] }
Example of an Image Classification Model Configuration File
The following code uses the TensorFlow engine as an example. You can modify the model_type parameter based on the actual engine type.
- Model input
Value: image files
- Model output
1 2 3 4 5 6 7
{ "predicted_label": "flower", "scores": [ ["rose", 0.99], ["begonia", 0.01] ] }
- Configuration file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
{ "model_type": "TensorFlow", "model_algorithm": "image_classification", "metrics": { "f1": 0.345294, "accuracy": 0.462963, "precision": 0.338977, "recall": 0.351852 }, "apis": [{ "url": "/", "method": "post", "request": { "Content-type": "multipart/form-data", "data": { "type": "object", "properties": { "images": { "type": "file" } } } }, "response": { "Content-type": "application/json", "data": { "type": "object", "properties": { "predicted_label": { "type": "string" }, "scores": { "type": "array", "items": [{ "type": "array", "minItems": 2, "maxItems": 2, "items": [ { "type": "string" }, { "type": "number" } ] }] } } } } }], "dependencies": [{ "installer": "pip", "packages": [{ "restraint": "ATLEAST", "package_version": "1.15.0", "package_name": "numpy" }, { "restraint": "", "package_version": "", "package_name": "Pillow" } ] }] }
The following code uses the MindSpore engine as an example. You can modify the model_type parameter based on the actual engine type.
- Model input
Value: image files
- Model output
1
"[[-2.404526 -3.0476532 -1.9888215 0.45013925 -1.7018927 0.40332815\n -7.1861157 11.290332 -1.5861531 5.7887416 ]]"
- Configuration file
{ "model_algorithm": "image_classification", "model_type": "MindSpore", "metrics": { "f1": 0.124555, "recall": 0.171875, "precision": 0.0023493892851938493, "accuracy": 0.00746268656716417 }, "apis": [{ "url": "/", "method": "post", "request": { "Content-type": "multipart/form-data", "data": { "type": "object", "properties": { "images": { "type": "file" } } } }, "response": { "Content-type": "applicaton/json", "data": { "type": "object", "properties": { "mnist_result": { "type": "array", "item": [{ "type": "string" }] } } } } } ], "dependencies": [] }
Example of a Predictive Analytics Model Configuration File
The following code uses the TensorFlow engine as an example. You can modify the model_type parameter based on the actual engine type.
- Model input
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
{ "data": { "req_data": [ { "buying_price": "high", "maint_price": "high", "doors": "2", "persons": "2", "lug_boot": "small", "safety": "low", "acceptability": "acc" }, { "buying_price": "high", "maint_price": "high", "doors": "2", "persons": "2", "lug_boot": "small", "safety": "low", "acceptability": "acc" } ] } }
- Model output
1 2 3 4 5 6 7 8 9 10 11 12
{ "data": { "resp_data": [ { "predict_result": "unacc" }, { "predict_result": "unacc" } ] } }
- Configuration file
In the code, the data parameter in the request and response structures is described in JSON Schema. The content in data and properties corresponds to the model input and output.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
{ "model_type": "TensorFlow", "model_algorithm": "predict_analysis", "metrics": { "f1": 0.345294, "accuracy": 0.462963, "precision": 0.338977, "recall": 0.351852 }, "apis": [ { "url": "/", "method": "post", "request": { "Content-type": "application/json", "data": { "type": "object", "properties": { "data": { "type": "object", "properties": { "req_data": { "items": [ { "type": "object", "properties": {} } ], "type": "array" } } } } } }, "response": { "Content-type": "application/json", "data": { "type": "object", "properties": { "data": { "type": "object", "properties": { "resp_data": { "type": "array", "items": [ { "type": "object", "properties": {} } ] } } } } } } } ], "dependencies": [ { "installer": "pip", "packages": [ { "restraint": "EXACT", "package_version": "1.15.0", "package_name": "numpy" }, { "restraint": "EXACT", "package_version": "5.2.0", "package_name": "Pillow" } ] } ] }
Example of a Custom Image Model Configuration File
The model input and output are similar to those in Example of an Object Detection Model Configuration File.
- Here is an example of how to make a model prediction request for image files.
To upload files, click the file upload button on the inference page.
1 2 3 4 5 6 7 8 9 10 11
{ "Content-type": "multipart/form-data", "data": { "type": "object", "properties": { "images": { "type": "file" } } } }
- Here is an example of how to make a model prediction request for JSON data.
The input parameter is of string type. To enter prediction requests, use the text box on the inference page.
1 2 3 4 5 6 7 8 9 10 11
{ "Content-type": "application/json", "data": { "type": "object", "properties": { "input": { "type": "string" } } } }
A complete request example is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
{ "model_algorithm": "image_classification", "model_type": "Image", "metrics": { "f1": 0.345294, "accuracy": 0.462963, "precision": 0.338977, "recall": 0.351852 }, "apis": [{ "url": "/", "method": "post", "request": { "Content-type": "multipart/form-data", "data": { "type": "object", "properties": { "images": { "type": "file" } } } }, "response": { "Content-type": "application/json", "data": { "type": "object", "required": [ "predicted_label", "scores" ], "properties": { "predicted_label": { "type": "string" }, "scores": { "type": "array", "items": [{ "type": "array", "minItems": 2, "maxItems": 2, "items": [{ "type": "string" }, { "type": "number" } ] }] } } } } }] } |
Example of a Machine Learning Model Configuration File
The following uses XGBoost as an example:
- Model input
{ "req_data": [ { "sepal_length": 5, "sepal_width": 3.3, "petal_length": 1.4, "petal_width": 0.2 }, { "sepal_length": 5, "sepal_width": 2, "petal_length": 3.5, "petal_width": 1 }, { "sepal_length": 6, "sepal_width": 2.2, "petal_length": 5, "petal_width": 1.5 } ] }
- Model output
{ "resp_data": [ { "predict_result": "Iris-setosa" }, { "predict_result": "Iris-versicolor" } ] }
- Configuration file
{ "model_type": "XGBoost", "model_algorithm": "xgboost_iris_test", "runtime": "python2.7", "metrics": { "f1": 0.345294, "accuracy": 0.462963, "precision": 0.338977, "recall": 0.351852 }, "apis": [ { "url": "/", "method": "post", "request": { "Content-type": "application/json", "data": { "type": "object", "properties": { "req_data": { "items": [ { "type": "object", "properties": {} } ], "type": "array" } } } }, "response": { "Content-type": "applicaton/json", "data": { "type": "object", "properties": { "resp_data": { "type": "array", "items": [ { "type": "object", "properties": { "predict_result": {} } } ] } } } } } ] }
Example of the Model Configuration File Using a Custom Dependency Package
The following example defines the NumPy 1.16.4 dependency environment.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
{ "model_algorithm": "image_classification", "model_type": "TensorFlow", "runtime": "python3.6", "apis": [ { "url": "/", "method": "post", "request": { "Content-type": "multipart/form-data", "data": { "type": "object", "properties": { "images": { "type": "file" } } } }, "response": { "Content-type": "applicaton/json", "data": { "type": "object", "properties": { "mnist_result": { "type": "array", "item": [ { "type": "string" } ] } } } } } ], "metrics": { "f1": 0.124555, "recall": 0.171875, "precision": 0.00234938928519385, "accuracy": 0.00746268656716417 }, "dependencies": [ { "installer": "pip", "packages": [ { "restraint": "EXACT", "package_version": "1.16.4", "package_name": "numpy" } ] } ] } |
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