Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

  1. NNLogger:A class for controlling logging-related outputs of the nnframework.

...

  • Add and remove models.

  • Create and disconnect graphs, retrieve graph information (model chaining information).

  • Synchronous and asynchronous detection interfaces.

NNLogger

  1. Interface Definition

Code Block
languagecpp
class NNLogger
{
public:
    virtual void setDebugMode(bool enable) = 0;

    virtual void setFileLogPath(std::string logPath) = 0;
    virtual void setFileLog(bool enable) = 0;
    virtual void setSystemLog(bool enable) = 0;

    virtual void setLevel(int level) = 0;
    virtual void writeLog(int level, std::string tag, std::string content) = 0;
};

...

  • The code above enables the debug mode, outputs to the standard output, and sets the log level to INFO.

NNResultListener

  1. Interface Definition

Code Block
languagecpp
class NNResultListener
{
public:
    virtual void onDetectedError(int error) = 0;

    virtual void onDetected(std::shared_ptr<NNData> result) = 0;
    virtual void onDetected(std::vector<std::shared_ptr<NNData>> results) = 0;
};

...

  • Inherit from NNResultListener, override its methods, and implement your own logic.

  • The example code above outputs the results to stdout.

NNModel

  1. Interface Definition

Code Block
languagecpp
class NNModel
{
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<com::sunplus::nn::type::NNData> input) = 0;

    virtual int detect(
        std::shared_ptr<com::sunplus::nn::type::NNData> input,
        std::shared_ptr<com::sunplus::nn::type::NNData>& result) = 0;

    virtual int detect(
        std::shared_ptr<com::sunplus::nn::type::NNData> input,
        std::vector<std::shared_ptr<com::sunplus::nn::type::NNData>>& nnResult) = 0;

public:
    virtual std::string getModelName() = 0;
    virtual std::string getResultName() = 0;
    virtual bool compatible(std::shared_ptr<NNModel> model) = 0;
};

...

  • Create a YoloV5s model object, which implements the NNModel methods.

  • Prepare the model.

  • Determine whether to perform synchronous detection or asynchronous detection based on parameters.

  • Release the model resources.

NNSequential

  1. Interface Definition

Code Block
languagecpp
class NNSequential
{
public:
    virtual int add(std::shared_ptr<NNModel> model) = 0;
    virtual int clear() = 0;

public:
    virtual int buildGraph() = 0;
    virtual int buildGraph(std::shared_ptr<NNResultListener> listener) = 0;
    virtual int teardownGraph() = 0;
    virtual std::string getGraphInfo() = 0;

public:
    virtual int detect(
        std::shared_ptr<com::sunplus::nn::type::NNData> input) = 0;
    virtual int detect(
        std::shared_ptr<com::sunplus::nn::type::NNData> input,
        std::shared_ptr<com::sunplus::nn::type::NNData>& result) = 0;
    virtual int detect(
        std::shared_ptr<com::sunplus::nn::type::NNData> input,
        std::vector<std::shared_ptr<com::sunplus::nn::type::NNData>>& result) = 0;

public:
    static std::shared_ptr<NNLogger> getLogger();
    static std::shared_ptr<NNSequential> createSequential();
};

...