Updated on 2023-06-15 GMT+08:00

Model Inference

This section describes how to input data to a model for inference. After the inference is complete, the inference result is returned.

API Calling

virtual HiLensEC hilens::Model::Infer(const InferDataVec & inputs, InferDataVec & outputs)

Parameter Description

Table 1 Parameters

Parameter

Type

Description

inputs

InferDataVector. Refer to Parameter Type for details.

Input inference data

outputs

InferDataVector. Refer to Parameter Type for details.

Inference output

Parameter Type

  • InferDataVec
    Model inference input and output
    typedef std::vector<InferData> hilens::InferDataVec
  • InferData
    struct InferData
    {
    unsigned int size; // Output size
    std::shared_ptr<unsigned char> data; // Data pointer
        /**
    * @brief: Construct an empty model for inference.
         */
        InferData() : size(0), data(nullptr) {}
    
        /**
    * @brief: Construct the InferData from a cv::Mat.
    * @param img Input images.
         */
        InferData(const cv::Mat &img);
    
        /**
    * @brief: Construct an InferData from a group of pointer data.
    * @param data: The data pointer. This constructor copies the data.
    * @param size: Data size (byte)
         */
        InferData(const unsigned char *data, unsigned int size);
    };

Return Value

If the return value is 0, the operation is successful. Otherwise, the operation fails. Refer to Error Codes for details about the failure response parameters.

If the actual inference input is different from the model input, the inference will fail. In this case, the return value of inference will be an int error code, and error information will be recorded in logs. You can locate the error based on the error information.