2026-01-28 06:16:04 +00:00

64 lines
1.7 KiB
C++

/**
* \brief An implementation of {@see AbstractInferencer} using SNPE to do inference
* \author Yao Zou yaozou@kneron.us
* \copyright 2019 Kneron Inc. All right reserved.
*/
#ifndef PIANO_DYNASTY_FLOATING_POINT_INCLUDE_SNPE_SNPEINFERENCER_H_
#define PIANO_DYNASTY_FLOATING_POINT_INCLUDE_SNPE_SNPEINFERENCER_H_
#include <unordered_map>
#include "AbstractInferencer.h"
namespace zdl {
namespace SNPE {
class SNPE;
}
} // namespace zdl
namespace zdl {
namespace DlContainer {
class IDlContainer;
}
} // namespace zdl
namespace dynasty {
namespace inferencer {
namespace snpe {
template <typename T>
class Inferencer : public AbstractInferencer<T> {
public:
class Builder : public AbstractInferencer<T>::Builder {
friend class Inferencer;
private:
std::shared_ptr<zdl::DlContainer::IDlContainer> dl_container_;
Builder() = default;
public:
Builder *WithONNXModel(std::string const &model_file);
~Builder() override;
InferencerUniquePtr<T> Build() override;
};
private:
std::unique_ptr<zdl::SNPE::SNPE> snpe_;
explicit Inferencer(zdl::DlContainer::IDlContainer *dlContainer);
public:
static Builder* GetBuilder();
std::unordered_map<std::string, std::vector<T>> Inference(
std::unordered_map<std::string, std::string> const &preprocess_input, bool only_output_layers) override;
std::unordered_map<std::string, std::vector<T>> Inference(
std::unordered_map<std::string, std::vector<T>> const &preprocess_input,
bool only_output_layers = true) override;
~Inferencer() override = default;
};
}
}
}
#endif //PIANO_DYNASTY_FLOATING_POINT_INCLUDE_SNPE_SNPEINFERENCER_H_