Function: load_from_file

Function Usage

Loads offline model data (offline model adapted to the AI processor) from a file. The memory is managed by the system.

Returns the model ID after the model is loaded. The model ID is used for model identification in subsequent operations.

Prototype

  • C Prototype
    1
    aclError aclmdlLoadFromFile(const char *modelPath, uint32_t *modelId)
    
  • Python Function
    1
    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 the permission to access the storage path.

The offline model file is an offline model (.om file) adapted to the Ascend AI Processor.

NOTE:
  • For details about how to obtain the .om file, see Model Building.
  • If the size of the .om model file is limited and the ATC tool is used to generate the .om file with the --external_weight parameter set to 1 (1 indicates that the weights of the Const/Constant nodes in the original network are saved in a separate file, and the file is saved in the weight directory at the same level as the .om file), when this API is used to load the .om file, the weight directory must be placed in the same directory as the .om file. The system will search the weight directory for the weight file. If the weight directory is not correctly placed, the separate weight file may fail to be loaded.

Returns

Return Value

Description

model_id

Int, pointer address of the model ID generated after the system loads the model.

ret

Int, error code. 0 indicates success, and other values indicate failure.

Restrictions

  • Before loading, check whether the memory space is sufficient based on the file size. If the memory space is insufficient, the application will be abnormal.
  • Model loading, execution, and unloading must be performed in the same context. For details about how to create a context, see acl.rt.set_device and acl.rt.create_context.

Reference

For the API call sequence, see Model Loading.