Function: load_from_file
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Function
Loads an offline model from a file. The memory is managed by the system.
The file specified by modelPath is an offline model in the format of *.om. For details about how to obtain the OM model file, see "--mode" in the Ascend Tensor Compiler (ATC).
If the size of the OM model file is limited, this API can also load an external weight file. You need to save the weight in a separate file during model building. For example, when you use ATC to generate an .om file, set --external_weight to 1, indicating that the weight of the Const/Constant node on the original network is saved in a separate file in the weight directory. Ensure that the weight directory is at the same level as the .om file so that the API can automatically search for the weight file in the weight directory when you call this API to load the .om file. Otherwise, the weight file may fail to be loaded.
Prototype
-
C Prototype
aclError aclmdlLoadFromFile(const char *modelPath, uint32_t *modelId) -
Python Function
model_id, ret = acl.mdl.load_from_file(model_path)
Parameters
| Parameter | Description |
|---|---|
| model_path | Str, directory of an offline model file, including the file name. The user who runs the app must have enough permission to access the directory. |
Return Values
| Return Value | Description |
|---|---|
| model_id | Int, pointer address of the model ID generated after the system loads the model. |
| ret | Int, error code: 0 on success; else, failure. |
Reference
The acl.mdl.set_config_opt and acl.mdl.load_with_config APIs are also provided for model loading. The caller needs to set the attributes in the configuration object passed to the API call to decide how the model will be loaded and who will manage the memory.