/
NNModel

NNModel

class NNModel : public NNObject { public: virtual int prepare() = 0; virtual int prepare(std::shared_ptr<NNResultListener> listener) = 0; virtual int destroy() = 0; public: virtual int addListener(std::shared_ptr<NNResultListener> listener) = 0; virtual int removeListener(std::shared_ptr<NNResultListener> listener) = 0; public: virtual int detect( std::shared_ptr<NNData> input, uint32_t timeoutInMS) = 0; virtual int detect( std::vector<std::shared_ptr<NNData>> inputs, uint32_t timeoutInMS) = 0; public: virtual std::string getModelName() = 0; virtual std::string getResultName() = 0; virtual bool compatible(std::shared_ptr<NNModel> model) = 0; };

Introduction to the class

Abstract base class for neural network models. This class provides a set of pure virtual methods that define the interface for managing and using neural network models.

Introduction to the class's methods

  1. int prepare()

    • brief: Prepares the model for inference without a result listener. This method performs any necessary initialization or loading of the model before it can be used for inference.

    • return int: An integer status code indicating success or failure.

  2. int prepare(std::shared_ptr<NNResultListener> listener)

    • brief: Prepares the model for inference with a result listener. This method performs any necessary initialization or loading of the model and attaches a result listener to receive notifications about inference results.

    • param

      • listener: A shared pointer to an `NNResultListener` object.

    • return int: An integer status code indicating success or failure.

  3. int destroy()

    • brief: Destroys the model and cleans up any resources. This method should be called when the model is no longer needed to free up any resources that were allocated during initialization or inference.

    • return int: An integer status code indicating success or failure.

  4. int addListener(std::shared_ptr<NNResultListener> listener)

    • brief: Adds a result listener to the model. This method allows you to attach a result listener to the model to receive notifications about inference results.

    • param

      • listener: A shared pointer to an `NNResultListener` object.

    • return int: An integer status code indicating success or failure.

  5. int removeListener(std::shared_ptr<NNResultListener> listener)

    • brief: Removes a result listener from the model. This method detaches a result listener from the model so that it no longer receives notifications about inference results.

    • param

      • listener: A shared pointer to an `NNResultListener` object.

    • return int: An integer status code indicating success or failure.

  6. int detect(std::shared_ptr<NNData> input, uint32_t timeoutInMS)

    • brief: Performs inference on a single input. This method runs the model with a single input and waits for the result, up to the specified timeout.

    • param

      • input: A shared pointer to an `NNData` object containing the input data.

      • timeoutInMS: The maximum time to wait for the result, in milliseconds.

    • return int: An integer status code indicating success or failure.

  7. virtual int detect(std::vector<std::shared_ptr<NNData>> inputs, uint32_t timeoutInMS)

    • brief: Performs inference on multiple inputs. This method runs the model with multiple inputs and waits for the result, up to the specified timeout.

    • param

      • inputs: A vector of shared pointers to `NNData` objects containing the input data.

      • timeoutInMS: The maximum time to wait for the result, in milliseconds.

    • return int: An integer status code indicating success or failure.

  8. std::string getModelName()

    • brief: Gets the name of the model. This method returns a string containing the name of the model.

    • return string: A string representing the model name.

  9. std::string getResultName()

    • brief: Gets the name of the result produced by the model. This method returns a string containing the name of the result produced by the model during inference.

    • return string: A string representing the result name.

  10. bool compatible(std::shared_ptr<NNModel> model)

    • brief: Checks if the model is compatible with another model. This method compares the current model with another model to determine if they are compatible for some specific operation or use case.

    • param

      • model: A shared pointer to another `NNModel` object.

    • return bool: True if the models are compatible, false otherwise..