Introduction to Model Package Specifications
When creating an AI application on the AI application management page, make sure that any meta model imported from OBS complies with certain specifications.
- The model package specifications are used when you import one model. If you import multiple models, for example, there are multiple model files, use custom images.
- If you want to use an AI engine that is not supported by ModelArts, use a custom image.
- For details about how to create a custom image, see Custom Image Specifications for Creating AI Applications and Creating a Custom Image and Using It to Create an AI Application.
- For more examples of custom scripts, see Examples of Custom Scripts.
The model package must contain the model directory. The model directory stores the model file, model configuration file, and model inference code file.
- Model files: The requirements for model files vary according to the model package structure. For details, see Model Package Example.
- Model configuration file: The model configuration file must be available and its name is consistently to be config.json. There must be only one model configuration file. For details about how to edit a model configuration file, see Specifications for Editing a Model Configuration File.
- Model inference code file: It is mandatory. The file name is consistently to be customize_service.py. There must be only one model inference code file. For details about how to edit model inference code, see Specifications for Writing Model Inference Code.
- The .py file on which customize_service.py depends can be directly stored in the model directory. Use a relative import mode to import the custom package.
- The other files on which customize_service.py depends can be stored in the model directory. You must use absolute paths to access these files. For more details, see Obtaining an Absolute Pa....
ModelArts also provides custom script examples of common AI engines. For details, see Examples of Custom Scripts.
Model Package Example
- Structure of the TensorFlow-based model package
When publishing the model, you only need to specify the ocr directory.
OBS bucket/directory name |── ocr | ├── model (Mandatory) Name of a fixed subdirectory, which is used to store model-related files | │ ├── <<Custom Python package>> (Optional) User's Python package, which can be directly referenced in model inference code | │ ├── saved_model.pb (Mandatory) Protocol buffer file, which contains the diagram description of the model | │ ├── variables Name of a fixed sub-directory, which contains the weight and deviation rate of the model. It is mandatory for the main file of the *.pb model. | │ │ ├── variables.index Mandatory | │ │ ├── variables.data-00000-of-00001 Mandatory | │ ├──config.json (Mandatory) Model configuration file. The file name is fixed to config.json. Only one model configuration file is supported. | │ ├──customize_service.py (Mandatory) Model inference code. The file name is fixed to customize_service.py. Only one model inference code file exists. The files on which customize_service.py depends can be directly stored in the model directory.
- Structure of the Image-based model package
When publishing the model, you only need to specify the resnet directory.
OBS bucket/directory name |── resnet | ├── model (Mandatory) Name of a fixed subdirectory, which is used to store model-related files | │ ├──config.json (Mandatory) Model configuration file (the address of the SWR image must be configured). The file name is fixed to config.json. Only one model configuration file is supported.
- Structure of the PySpark-based model package
When publishing the model, you only need to specify the resnet directory.
OBS bucket/directory name |── resnet | ├── model (Mandatory) Name of a fixed subdirectory, which is used to store model-related files | │ ├── <<Custom Python package>> (Optional) User's Python package, which can be directly referenced in model inference code | │ ├── spark_model (Mandatory) Model directory, which contains the model content saved by PySpark | │ ├──config.json (Mandatory) Model configuration file. The file name is fixed to config.json. Only one model configuration file is supported. | │ ├──customize_service.py (Mandatory) Model inference code. The file name is fixed to customize_service.py. Only one model inference code file exists. The files on which customize_service.py depends can be directly stored in the model directory.
- Structure of the PyTorch-based model package
When publishing the model, you only need to specify the resnet directory.
OBS bucket/directory name |── resnet | ├── model (Mandatory) Name of a fixed subdirectory, which is used to store model-related files | │ ├── <<Custom Python package>> (Optional) User's Python package, which can be directly referenced in model inference code | │ ├── resnet50.pth (Mandatory) PyTorch model file, which contains variable and weight information and is saved as state_dict | │ ├──config.json (Mandatory) Model configuration file. The file name is fixed to config.json. Only one model configuration file is supported. | │ ├──customize_service.py (Mandatory) Model inference code. The file name is fixed to customize_service.py. Only one model inference code file exists. The files on which customize_service.py depends can be directly stored in the model directory.
- Structure of the XGBoost-based model package
When publishing the model, you only need to specify the resnet directory.
OBS bucket/directory name |── resnet | |── model (Mandatory) Name of a fixed subdirectory, which is used to store model-related files | | |── <<Custom Python package>> (Optional) User's Python package, which can be directly referenced in model inference code | | |── *.m (Mandatory): Model file whose extension name is .m | | |── config.json (Mandatory) Model configuration file. The file name is fixed to config.json. Only one model configuration file is supported. | | |── customize_service.py (Mandatory) Model inference code. The file name is fixed to customize_service.py. Only one model inference code file exists. The files on which customize_service.py depends can be directly stored in the model directory.
- Structure of the Scikit_Learn-based model package
When publishing the model, you only need to specify the resnet directory.
OBS bucket/directory name |── resnet | |── model (Mandatory) Name of a fixed subdirectory, which is used to store model-related files | | |── <<Custom Python package>> (Optional) User's Python package, which can be directly referenced in model inference code | | |── *.m (Mandatory): Model file whose extension name is .m | | |── config.json (Mandatory) Model configuration file. The file name is fixed to config.json. Only one model configuration file is supported. | | |── customize_service.py (Mandatory) Model inference code. The file name is fixed to customize_service.py. Only one model inference code file exists. The files on which customize_service.py depends can be directly stored in the model directory.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.