Updated on 2022-03-13 GMT+08:00

AIModelManager::Init

Initializes the model manager to load a model.

Syntax

virtual AIStatus AIModelManager::Init(const AIConfig &config, const std::vector<AIModelDescription> &model_descs = {}) override;

Parameter Description

Parameter

Description

Value Range

config

Configuration information

For details about the syntax of the AIConfig data type, see AIConfig.

-

model_descs

Model description list. A model can be loaded from the memory (prior) or file.

For details about the syntax of the AIModelDescription data type, see AIModelDescription.

-

Return Value

SUCCESS indicates that initialization succeeds, while FAILED indicates that initialization fails.

Calling Example

Note that the value of MODEL_NAME can contain only uppercase letters, lowercase letters, digits, underscores (_), and dots (.). The value of MODEL_PATH can contain only uppercase letters, lowercase letters, digits, and underscores (_).

  • Load a model from a file:
        AIModelManager model_mngr;
        AIModelDescription model_desc;
        AIConfig config;
       /* Check whether the input file path is valid.
           Path: The value can contain uppercase letters, lowercase letters, digits, and underscores (_).
           File name: The value can contain uppercase letters, lowercase letters, digits, underscores (_), and dots (.). */
        model_desc.set_path(MODEL_PATH);
        model_desc.set_name(MODEL_NAME);
        model_desc.set_type(0);
        vector<AIModelDescription> model_descs;
        model_descs.push_back(model_desc);
        // AIModelManager Init
        AIStatus ret = model_mngr.Init(config, model_descs);
        if (SUCCESS != ret)
        {
            printf("AIModelManager Init failed. ret = %d\n", ret);
            return -1;
        }
  • Load a model from memory:
        AIModelManager model_mngr;
        AIModelDescription model_desc;
        vector<AIModelDescription> model_descs;
        AIConfig config;
        model_desc.set_name(MODEL_NAME);
        model_desc.set_type(0);
        char *model_data = nullptr;
        uint32_t model_size = 0;
        ASSERT_EQ(true, Utils::ReadFile(MODEL_PATH.c_str(), model_data, model_size));
        model_desc.set_data(model_data,model_size);
        model_desc.set_size(model_size);
        AIStatus ret = model_mngr.Init(config, model_descs);
        if (SUCCESS != ret)
        {
            printf("AIModelManager Init failed. ret = %d\n", ret);
            return -1;
        }
    }

    The value of model_size must be the same as the actual size of the model.