|
|
|
|
|
|
|
|
|
|
|
|
| #ifndef OPENCV_GAPI_INFER_OV_HPP
|
| #define OPENCV_GAPI_INFER_OV_HPP
|
|
|
| #include <string>
|
|
|
| #include <opencv2/gapi/util/any.hpp>
|
| #include <opencv2/gapi/own/exports.hpp>
|
| #include <opencv2/gapi/gkernel.hpp>
|
| #include <opencv2/gapi/infer.hpp>
|
|
|
| #include <map>
|
|
|
| namespace cv {
|
| namespace gapi {
|
|
|
| |
| |
| |
|
|
| namespace ov {
|
|
|
| GAPI_EXPORTS cv::gapi::GBackend backend();
|
|
|
| namespace detail {
|
|
|
| template <typename T>
|
| using AttrMap = std::map<std::string, T>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| template <typename Attr>
|
| using LayerVariantAttr = cv::util::variant< cv::util::monostate
|
| , AttrMap<Attr>
|
| , Attr>;
|
|
|
| struct ParamDesc {
|
| struct Model {
|
|
|
| Model(const std::string &model_path_,
|
| const std::string &bin_path_)
|
| : model_path(model_path_), bin_path(bin_path_) {
|
| }
|
|
|
| std::string model_path;
|
| std::string bin_path;
|
|
|
| LayerVariantAttr<std::string> input_tensor_layout;
|
| LayerVariantAttr<std::string> input_model_layout;
|
| LayerVariantAttr<std::string> output_tensor_layout;
|
| LayerVariantAttr<std::string> output_model_layout;
|
| LayerVariantAttr<int> output_tensor_precision;
|
|
|
| LayerVariantAttr<std::vector<size_t>> new_shapes;
|
|
|
| LayerVariantAttr<std::vector<float>> mean_values;
|
| LayerVariantAttr<std::vector<float>> scale_values;
|
|
|
| LayerVariantAttr<int> interpolation;
|
| };
|
|
|
| struct CompiledModel {
|
| std::string blob_path;
|
| };
|
|
|
| using Kind = cv::util::variant<Model, CompiledModel>;
|
|
|
| ParamDesc(Kind &&kind_,
|
| const std::string &device_,
|
| const bool is_generic_,
|
| const size_t num_in_,
|
| const size_t num_out_)
|
| : kind(std::move(kind_)), device(device_),
|
| is_generic(is_generic_),
|
| num_in(num_in_), num_out(num_out_) {
|
| }
|
|
|
| Kind kind;
|
|
|
| std::string device;
|
| bool is_generic;
|
|
|
| std::size_t num_in;
|
| std::size_t num_out;
|
|
|
| std::vector<std::string> input_names;
|
| std::vector<std::string> output_names;
|
|
|
| using PluginConfigT = std::map<std::string, std::string>;
|
| PluginConfigT config;
|
|
|
| size_t nireq = 1;
|
| };
|
|
|
|
|
| static detail::ParamDesc::Model&
|
| getModelToSetAttrOrThrow(detail::ParamDesc::Kind &kind,
|
| const std::string &attr_name) {
|
| if (cv::util::holds_alternative<detail::ParamDesc::CompiledModel>(kind)) {
|
| cv::util::throw_error(
|
| std::logic_error("Specifying " + attr_name + " isn't"
|
| " possible for compiled model."));
|
| }
|
| GAPI_Assert(cv::util::holds_alternative<detail::ParamDesc::Model>(kind));
|
| return cv::util::get<detail::ParamDesc::Model>(kind);
|
| }
|
|
|
| }
|
|
|
| |
| |
| |
|
|
| template<typename Net> struct Params {
|
| public:
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| Params(const std::string &model_path,
|
| const std::string &bin_path,
|
| const std::string &device)
|
| : m_desc( detail::ParamDesc::Kind{detail::ParamDesc::Model{model_path, bin_path}}
|
| , device
|
| , false
|
| , std::tuple_size<typename Net::InArgs>::value
|
| , std::tuple_size<typename Net::OutArgs>::value) {
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| Params(const std::string &blob_path,
|
| const std::string &device)
|
| : m_desc( detail::ParamDesc::Kind{detail::ParamDesc::CompiledModel{blob_path}}
|
| , device
|
| , false
|
| , std::tuple_size<typename Net::InArgs>::value
|
| , std::tuple_size<typename Net::OutArgs>::value) {
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| Params<Net>& cfgInputLayers(const std::vector<std::string> &layer_names) {
|
| m_desc.input_names = layer_names;
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| Params<Net>& cfgOutputLayers(const std::vector<std::string> &layer_names) {
|
| m_desc.output_names = layer_names;
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| Params<Net>& cfgPluginConfig(const detail::ParamDesc::PluginConfigT &config) {
|
| m_desc.config = config;
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| Params<Net>& cfgInputTensorLayout(std::string layout) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "input tensor layout")
|
| .input_tensor_layout = std::move(layout);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
|
|
| Params<Net>&
|
| cfgInputTensorLayout(detail::AttrMap<std::string> layout_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "input tensor layout")
|
| .input_tensor_layout = std::move(layout_map);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| Params<Net>& cfgInputModelLayout(std::string layout) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "input model layout")
|
| .input_model_layout = std::move(layout);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
|
|
| Params<Net>&
|
| cfgInputModelLayout(detail::AttrMap<std::string> layout_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "input model layout")
|
| .input_model_layout = std::move(layout_map);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| Params<Net>& cfgOutputTensorLayout(std::string layout) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "output tensor layout")
|
| .output_tensor_layout = std::move(layout);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
|
|
| Params<Net>&
|
| cfgOutputTensorLayout(detail::AttrMap<std::string> layout_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "output tensor layout")
|
| .output_tensor_layout = std::move(layout_map);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| Params<Net>& cfgOutputModelLayout(std::string layout) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "output model layout")
|
| .output_model_layout = std::move(layout);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
|
|
| Params<Net>&
|
| cfgOutputModelLayout(detail::AttrMap<std::string> layout_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "output model layout")
|
| .output_model_layout = std::move(layout_map);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| Params<Net>& cfgOutputTensorPrecision(int precision) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "output tensor precision")
|
| .output_tensor_precision = precision;
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
|
|
| Params<Net>&
|
| cfgOutputTensorPrecision(detail::AttrMap<int> precision_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "output tensor precision")
|
| .output_tensor_precision = std::move(precision_map);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| Params<Net>&
|
| cfgReshape(std::vector<size_t> new_shape) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "reshape")
|
| .new_shapes = std::move(new_shape);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
|
|
| Params<Net>&
|
| cfgReshape(detail::AttrMap<std::vector<size_t>> new_shape_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "reshape")
|
| .new_shapes = std::move(new_shape_map);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
|
|
| Params<Net>& cfgNumRequests(const size_t nireq) {
|
| if (nireq == 0) {
|
| cv::util::throw_error(
|
| std::logic_error("Number of inference requests"
|
| " must be greater than zero."));
|
| }
|
| m_desc.nireq = nireq;
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| Params<Net>& cfgMean(std::vector<float> mean_values) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "mean values")
|
| .mean_values = std::move(mean_values);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
|
|
| Params<Net>& cfgMean(detail::AttrMap<std::vector<float>> mean_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "mean values")
|
| .mean_values = std::move(mean_map);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| Params<Net>& cfgScale(std::vector<float> scale_values) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "scale values")
|
| .scale_values = std::move(scale_values);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
|
|
| Params<Net>& cfgScale(detail::AttrMap<std::vector<float>> scale_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "scale values")
|
| .scale_values = std::move(scale_map);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| Params<Net>& cfgResize(int interpolation) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "resize preprocessing")
|
| .interpolation = std::move(interpolation);
|
| return *this;
|
| }
|
|
|
| |
| |
| |
| |
| |
|
|
| Params<Net>& cfgResize(detail::AttrMap<int> interpolation) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "resize preprocessing")
|
| .interpolation = std::move(interpolation);
|
| return *this;
|
| }
|
|
|
|
|
| GBackend backend() const { return cv::gapi::ov::backend(); }
|
| std::string tag() const { return Net::tag(); }
|
| cv::util::any params() const { return { m_desc }; }
|
|
|
|
|
| protected:
|
| detail::ParamDesc m_desc;
|
| };
|
|
|
| |
| |
| |
| |
|
|
| template<>
|
| class Params<cv::gapi::Generic> {
|
| public:
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| Params(const std::string &tag,
|
| const std::string &model_path,
|
| const std::string &bin_path,
|
| const std::string &device)
|
| : m_tag(tag),
|
| m_desc( detail::ParamDesc::Kind{detail::ParamDesc::Model{model_path, bin_path}}
|
| , device
|
| , true
|
| , 0u
|
| , 0u) {
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| Params(const std::string &tag,
|
| const std::string &blob_path,
|
| const std::string &device)
|
| : m_tag(tag),
|
| m_desc( detail::ParamDesc::Kind{detail::ParamDesc::CompiledModel{blob_path}}
|
| , device
|
| , true
|
| , 0u
|
| , 0u) {
|
| }
|
|
|
|
|
| Params& cfgPluginConfig(const detail::ParamDesc::PluginConfigT &config) {
|
| m_desc.config = config;
|
| return *this;
|
| }
|
|
|
|
|
| Params& cfgInputTensorLayout(std::string layout) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "input tensor layout")
|
| .input_tensor_layout = std::move(layout);
|
| return *this;
|
| }
|
|
|
|
|
| Params&
|
| cfgInputTensorLayout(detail::AttrMap<std::string> layout_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "input tensor layout")
|
| .input_tensor_layout = std::move(layout_map);
|
| return *this;
|
| }
|
|
|
|
|
| Params& cfgInputModelLayout(std::string layout) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "input model layout")
|
| .input_model_layout = std::move(layout);
|
| return *this;
|
| }
|
|
|
|
|
| Params&
|
| cfgInputModelLayout(detail::AttrMap<std::string> layout_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "input model layout")
|
| .input_model_layout = std::move(layout_map);
|
| return *this;
|
| }
|
|
|
|
|
| Params& cfgOutputTensorLayout(std::string layout) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "output tensor layout")
|
| .output_tensor_layout = std::move(layout);
|
| return *this;
|
| }
|
|
|
|
|
| Params&
|
| cfgOutputTensorLayout(detail::AttrMap<std::string> layout_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "output tensor layout")
|
| .output_tensor_layout = std::move(layout_map);
|
| return *this;
|
| }
|
|
|
|
|
| Params& cfgOutputModelLayout(std::string layout) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "output model layout")
|
| .output_model_layout = std::move(layout);
|
| return *this;
|
| }
|
|
|
|
|
| Params&
|
| cfgOutputModelLayout(detail::AttrMap<std::string> layout_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "output model layout")
|
| .output_model_layout = std::move(layout_map);
|
| return *this;
|
| }
|
|
|
|
|
| Params& cfgOutputTensorPrecision(int precision) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "output tensor precision")
|
| .output_tensor_precision = precision;
|
| return *this;
|
| }
|
|
|
|
|
| Params&
|
| cfgOutputTensorPrecision(detail::AttrMap<int> precision_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "output tensor precision")
|
| .output_tensor_precision = std::move(precision_map);
|
| return *this;
|
| }
|
|
|
|
|
| Params& cfgReshape(std::vector<size_t> new_shape) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "reshape")
|
| .new_shapes = std::move(new_shape);
|
| return *this;
|
| }
|
|
|
|
|
| Params&
|
| cfgReshape(detail::AttrMap<std::vector<size_t>> new_shape_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "reshape")
|
| .new_shapes = std::move(new_shape_map);
|
| return *this;
|
| }
|
|
|
|
|
| Params& cfgNumRequests(const size_t nireq) {
|
| if (nireq == 0) {
|
| cv::util::throw_error(
|
| std::logic_error("Number of inference requests"
|
| " must be greater than zero."));
|
| }
|
| m_desc.nireq = nireq;
|
| return *this;
|
| }
|
|
|
|
|
| Params& cfgMean(std::vector<float> mean_values) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "mean values")
|
| .mean_values = std::move(mean_values);
|
| return *this;
|
| }
|
|
|
|
|
| Params& cfgMean(detail::AttrMap<std::vector<float>> mean_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "mean values")
|
| .mean_values = std::move(mean_map);
|
| return *this;
|
| }
|
|
|
|
|
| Params& cfgScale(std::vector<float> scale_values) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "scale values")
|
| .scale_values = std::move(scale_values);
|
| return *this;
|
| }
|
|
|
|
|
| Params& cfgScale(detail::AttrMap<std::vector<float>> scale_map) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "scale values")
|
| .scale_values = std::move(scale_map);
|
| return *this;
|
| }
|
|
|
|
|
| Params& cfgResize(int interpolation) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "resize preprocessing")
|
| .interpolation = std::move(interpolation);
|
| return *this;
|
| }
|
|
|
|
|
| Params& cfgResize(detail::AttrMap<int> interpolation) {
|
| detail::getModelToSetAttrOrThrow(m_desc.kind, "resize preprocessing")
|
| .interpolation = std::move(interpolation);
|
| return *this;
|
| }
|
|
|
|
|
| GBackend backend() const { return cv::gapi::ov::backend(); }
|
| std::string tag() const { return m_tag; }
|
| cv::util::any params() const { return { m_desc }; }
|
|
|
|
|
| protected:
|
| std::string m_tag;
|
| detail::ParamDesc m_desc;
|
| };
|
|
|
| }
|
|
|
| namespace wip { namespace ov {
|
| |
| |
| |
| |
| |
| |
| |
|
|
| struct benchmark_mode { };
|
|
|
| }
|
| }
|
|
|
| }
|
|
|
| namespace detail
|
| {
|
| template<> struct CompileArgTag<cv::gapi::wip::ov::benchmark_mode>
|
| {
|
| static const char* tag() { return "gapi.wip.ov.benchmark_mode"; }
|
| };
|
| }
|
|
|
| }
|
|
|
| #endif
|
|
|