ie.hpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2019-2023 Intel Corporation
  6. #ifndef OPENCV_GAPI_INFER_IE_HPP
  7. #define OPENCV_GAPI_INFER_IE_HPP
  8. #include <unordered_map>
  9. #include <unordered_set>
  10. #include <string>
  11. #include <array>
  12. #include <tuple> // tuple, tuple_size
  13. #include <map>
  14. #include <opencv2/gapi/opencv_includes.hpp>
  15. #include <opencv2/gapi/util/any.hpp>
  16. #include <opencv2/core/cvdef.h> // GAPI_EXPORTS
  17. #include <opencv2/gapi/gkernel.hpp> // GKernelPackage
  18. #include <opencv2/gapi/infer.hpp> // Generic
  19. #include <opencv2/gapi/streaming/onevpl/accel_types.hpp> // Preproc Dev & Ctx
  20. namespace cv {
  21. namespace gapi {
  22. // FIXME: introduce a new sub-namespace for NN?
  23. /**
  24. * @brief This namespace contains G-API OpenVINO backend functions,
  25. * structures, and symbols.
  26. */
  27. namespace ie {
  28. GAPI_EXPORTS cv::gapi::GBackend backend();
  29. /**
  30. * Specifies how G-API and IE should trait input data
  31. *
  32. * In OpenCV, the same cv::Mat is used to represent both
  33. * image and tensor data. Sometimes those are hardly distinguishable,
  34. * so this extra parameter is used to give G-API a hint.
  35. *
  36. * This hint controls how G-API reinterprets the data when converting
  37. * it to IE Blob format (and which layout/etc is assigned to this data).
  38. */
  39. enum class TraitAs: int
  40. {
  41. TENSOR, //!< G-API traits an associated cv::Mat as a raw tensor and passes dimensions as-is
  42. IMAGE //!< G-API traits an associated cv::Mat as an image so creates an "image" blob (NCHW/NHWC, etc)
  43. };
  44. using IEConfig = std::map<std::string, std::string>;
  45. enum InferMode {Sync, Async};
  46. namespace detail {
  47. template <typename T>
  48. using AttrMap = std::map<std::string, T>;
  49. // NB: This type is used to hold in/out layers
  50. // attributes such as precision, layout, shape etc.
  51. //
  52. // User can provide attributes either:
  53. // 1. cv::util::monostate - No value specified explicitly.
  54. // 2. Attr - value specified explicitly that should be broadcasted to all layers.
  55. // 3. AttrMap[str->T] - map specifies value for particular layer.
  56. template <typename Attr>
  57. using LayerVariantAttr = cv::util::variant< cv::util::monostate
  58. , AttrMap<Attr>
  59. , Attr>;
  60. struct ParamDesc {
  61. std::string model_path;
  62. std::string weights_path;
  63. std::string device_id;
  64. std::vector<std::string> input_names;
  65. std::vector<std::string> output_names;
  66. using ConstInput = std::pair<cv::Mat, TraitAs>;
  67. std::unordered_map<std::string, ConstInput> const_inputs;
  68. std::size_t num_in;
  69. std::size_t num_out;
  70. enum class Kind {Load, Import};
  71. Kind kind;
  72. bool is_generic;
  73. IEConfig config;
  74. std::map<std::string, std::vector<std::size_t>> reshape_table;
  75. std::unordered_set<std::string> layer_names_to_reshape;
  76. // NB: Number of asyncrhonious infer requests
  77. size_t nireq;
  78. // NB: An optional config to setup RemoteContext for IE
  79. cv::util::any context_config;
  80. // NB: batch_size can't be equal to 1 by default, because some of models
  81. // have 2D (Layout::NC) input and if the first dimension not equal to 1
  82. // net.setBatchSize(1) will overwrite it.
  83. cv::optional<size_t> batch_size;
  84. cv::optional<cv::gapi::wip::onevpl::Device> vpl_preproc_device;
  85. cv::optional<cv::gapi::wip::onevpl::Context> vpl_preproc_ctx;
  86. InferMode mode;
  87. using PrecisionT = int;
  88. using PrecisionMapT = std::unordered_map<std::string, PrecisionT>;
  89. // NB: This parameter can contain:
  90. // 1. cv::util::monostate - Don't specify precision, but use default from IR/Blob.
  91. // 2. PrecisionT (CV_8U, CV_32F, ...) - Specifies precision for all output layers.
  92. // 3. PrecisionMapT ({{"layer0", CV_32F}, {"layer1", CV_16F}} - Specifies precision for certain output layer.
  93. // cv::util::monostate is default value that means precision wasn't specified.
  94. using PrecisionVariantT = cv::util::variant<cv::util::monostate,
  95. PrecisionT,
  96. PrecisionMapT>;
  97. PrecisionVariantT output_precision;
  98. LayerVariantAttr<std::string> input_layout;
  99. LayerVariantAttr<std::string> output_layout;
  100. LayerVariantAttr<int> interpolation;
  101. };
  102. } // namespace detail
  103. // FIXME: this is probably a shared (reusable) thing
  104. template<typename Net>
  105. struct PortCfg {
  106. using In = std::array
  107. < std::string
  108. , std::tuple_size<typename Net::InArgs>::value >;
  109. using Out = std::array
  110. < std::string
  111. , std::tuple_size<typename Net::OutArgs>::value >;
  112. };
  113. /**
  114. * @brief This structure provides functions
  115. * that fill inference parameters for "OpenVINO Toolkit" model.
  116. */
  117. template<typename Net> class Params {
  118. public:
  119. /** @brief Class constructor.
  120. Constructs Params based on model information and specifies default values for other
  121. inference description parameters. Model is loaded and compiled using "OpenVINO Toolkit".
  122. @param model Path to topology IR (.xml file).
  123. @param weights Path to weights (.bin file).
  124. @param device target device to use.
  125. */
  126. Params(const std::string &model,
  127. const std::string &weights,
  128. const std::string &device)
  129. : desc{ model, weights, device, {}, {}, {}
  130. , std::tuple_size<typename Net::InArgs>::value // num_in
  131. , std::tuple_size<typename Net::OutArgs>::value // num_out
  132. , detail::ParamDesc::Kind::Load
  133. , false
  134. , {}
  135. , {}
  136. , {}
  137. , 1u
  138. , {}
  139. , {}
  140. , {}
  141. , {}
  142. , InferMode::Async
  143. , {}
  144. , {}
  145. , {}
  146. , {} } {
  147. }
  148. /** @overload
  149. Use this constructor to work with pre-compiled network.
  150. Model is imported from a pre-compiled blob.
  151. @param model Path to model.
  152. @param device target device to use.
  153. */
  154. Params(const std::string &model,
  155. const std::string &device)
  156. : desc{ model, {}, device, {}, {}, {}
  157. , std::tuple_size<typename Net::InArgs>::value // num_in
  158. , std::tuple_size<typename Net::OutArgs>::value // num_out
  159. , detail::ParamDesc::Kind::Import
  160. , false
  161. , {}
  162. , {}
  163. , {}
  164. , 1u
  165. , {}
  166. , {}
  167. , {}
  168. , {}
  169. , InferMode::Async
  170. , {}
  171. , {}
  172. , {}
  173. , {} } {
  174. }
  175. /** @brief Specifies sequence of network input layers names for inference.
  176. The function is used to associate cv::gapi::infer<> inputs with the model inputs.
  177. Number of names has to match the number of network inputs as defined in G_API_NET().
  178. In case a network has only single input layer, there is no need to specify name manually.
  179. @param layer_names std::array<std::string, N> where N is the number of inputs
  180. as defined in the @ref G_API_NET. Contains names of input layers.
  181. @return reference to this parameter structure.
  182. */
  183. Params<Net>& cfgInputLayers(const typename PortCfg<Net>::In &layer_names) {
  184. desc.input_names.clear();
  185. desc.input_names.reserve(layer_names.size());
  186. std::copy(layer_names.begin(), layer_names.end(),
  187. std::back_inserter(desc.input_names));
  188. return *this;
  189. }
  190. /** @brief Specifies sequence of network output layers names for inference.
  191. The function is used to associate cv::gapi::infer<> outputs with the model outputs.
  192. Number of names has to match the number of network outputs as defined in G_API_NET().
  193. In case a network has only single output layer, there is no need to specify name manually.
  194. @param layer_names std::array<std::string, N> where N is the number of outputs
  195. as defined in the @ref G_API_NET. Contains names of output layers.
  196. @return reference to this parameter structure.
  197. */
  198. Params<Net>& cfgOutputLayers(const typename PortCfg<Net>::Out &layer_names) {
  199. desc.output_names.clear();
  200. desc.output_names.reserve(layer_names.size());
  201. std::copy(layer_names.begin(), layer_names.end(),
  202. std::back_inserter(desc.output_names));
  203. return *this;
  204. }
  205. /** @brief Specifies a constant input.
  206. The function is used to set a constant input. This input has to be
  207. a preprocessed tensor if its type is TENSOR. Need to provide name of the
  208. network layer which will receive provided data.
  209. @param layer_name Name of network layer.
  210. @param data cv::Mat that contains data which will be associated with network layer.
  211. @param hint Input type @sa cv::gapi::ie::TraitAs.
  212. @return reference to this parameter structure.
  213. */
  214. Params<Net>& constInput(const std::string &layer_name,
  215. const cv::Mat &data,
  216. TraitAs hint = TraitAs::TENSOR) {
  217. desc.const_inputs[layer_name] = {data, hint};
  218. return *this;
  219. }
  220. /** @brief Specifies OpenVINO plugin configuration.
  221. The function is used to set configuration for OpenVINO plugin. Some parameters
  222. can be different for each plugin. Please follow https://docs.openvinotoolkit.org/latest/index.html
  223. to check information about specific plugin.
  224. @param cfg Map of pairs: (config parameter name, config parameter value).
  225. @return reference to this parameter structure.
  226. */
  227. Params& pluginConfig(const IEConfig& cfg) {
  228. desc.config = cfg;
  229. return *this;
  230. }
  231. /** @overload
  232. Function with a rvalue parameter.
  233. @param cfg rvalue map of pairs: (config parameter name, config parameter value).
  234. @return reference to this parameter structure.
  235. */
  236. Params& pluginConfig(IEConfig&& cfg) {
  237. desc.config = std::move(cfg);
  238. return *this;
  239. }
  240. /** @brief Specifies configuration for RemoteContext in InferenceEngine.
  241. When RemoteContext is configured the backend imports the networks using the context.
  242. It also expects cv::MediaFrames to be actually remote, to operate with blobs via the context.
  243. @param ctx_cfg cv::util::any value which holds InferenceEngine::ParamMap.
  244. @return reference to this parameter structure.
  245. */
  246. Params& cfgContextParams(const cv::util::any& ctx_cfg) {
  247. desc.context_config = ctx_cfg;
  248. return *this;
  249. }
  250. /** @overload
  251. Function with an rvalue parameter.
  252. @param ctx_cfg cv::util::any value which holds InferenceEngine::ParamMap.
  253. @return reference to this parameter structure.
  254. */
  255. Params& cfgContextParams(cv::util::any&& ctx_cfg) {
  256. desc.context_config = std::move(ctx_cfg);
  257. return *this;
  258. }
  259. /** @brief Specifies number of asynchronous inference requests.
  260. @param nireq Number of inference asynchronous requests.
  261. @return reference to this parameter structure.
  262. */
  263. Params& cfgNumRequests(size_t nireq) {
  264. GAPI_Assert(nireq > 0 && "Number of infer requests must be greater than zero!");
  265. desc.nireq = nireq;
  266. return *this;
  267. }
  268. /** @brief Specifies new input shapes for the network inputs.
  269. The function is used to specify new input shapes for the network inputs.
  270. Follow https://docs.openvinotoolkit.org/latest/classInferenceEngine_1_1networkNetwork.html
  271. for additional information.
  272. @param reshape_table Map of pairs: name of corresponding data and its dimension.
  273. @return reference to this parameter structure.
  274. */
  275. Params<Net>& cfgInputReshape(const std::map<std::string, std::vector<std::size_t>>& reshape_table) {
  276. desc.reshape_table = reshape_table;
  277. return *this;
  278. }
  279. /** @overload */
  280. Params<Net>& cfgInputReshape(std::map<std::string, std::vector<std::size_t>>&& reshape_table) {
  281. desc.reshape_table = std::move(reshape_table);
  282. return *this;
  283. }
  284. /** @overload
  285. @param layer_name Name of layer.
  286. @param layer_dims New dimensions for this layer.
  287. @return reference to this parameter structure.
  288. */
  289. Params<Net>& cfgInputReshape(const std::string& layer_name, const std::vector<size_t>& layer_dims) {
  290. desc.reshape_table.emplace(layer_name, layer_dims);
  291. return *this;
  292. }
  293. /** @overload */
  294. Params<Net>& cfgInputReshape(std::string&& layer_name, std::vector<size_t>&& layer_dims) {
  295. desc.reshape_table.emplace(layer_name, layer_dims);
  296. return *this;
  297. }
  298. /** @overload
  299. @param layer_names set of names of network layers that will be used for network reshape.
  300. @return reference to this parameter structure.
  301. */
  302. Params<Net>& cfgInputReshape(const std::unordered_set<std::string>& layer_names) {
  303. desc.layer_names_to_reshape = layer_names;
  304. return *this;
  305. }
  306. /** @overload
  307. @param layer_names rvalue set of the selected layers will be reshaped automatically
  308. its input image size.
  309. @return reference to this parameter structure.
  310. */
  311. Params<Net>& cfgInputReshape(std::unordered_set<std::string>&& layer_names) {
  312. desc.layer_names_to_reshape = std::move(layer_names);
  313. return *this;
  314. }
  315. /** @brief Specifies the inference batch size.
  316. The function is used to specify inference batch size.
  317. Follow https://docs.openvinotoolkit.org/latest/classInferenceEngine_1_1CNNNetwork.html#a8e9d19270a48aab50cb5b1c43eecb8e9 for additional information
  318. @param size batch size which will be used.
  319. @return reference to this parameter structure.
  320. */
  321. Params<Net>& cfgBatchSize(const size_t size) {
  322. desc.batch_size = cv::util::make_optional(size);
  323. return *this;
  324. }
  325. Params<Net>& cfgPreprocessingParams(const cv::gapi::wip::onevpl::Device &device,
  326. const cv::gapi::wip::onevpl::Context &ctx) {
  327. desc.vpl_preproc_device = cv::util::make_optional(device);
  328. desc.vpl_preproc_ctx = cv::util::make_optional(ctx);
  329. return *this;
  330. }
  331. /** @brief Specifies which api will be used to run inference.
  332. The function is used to specify mode for OpenVINO inference.
  333. OpenVINO has two options to run inference:
  334. 1. Asynchronous (using StartAsync: https://docs.openvino.ai/latest/classInferenceEngine_1_1InferRequest.html#doxid-class-inference-engine-1-1-infer-request-1a405293e8423d82a5b45f642a3bef0d24)
  335. 2. Synchronous (using Infer: https://docs.openvino.ai/latest/classInferenceEngine_1_1InferRequest.html#doxid-class-inference-engine-1-1-infer-request-1a3391ce30894abde730523e9ca9371ce8)
  336. By default asynchronous mode is used.
  337. @param mode Inference mode which will be used.
  338. @return reference to this parameter structure.
  339. */
  340. Params<Net>& cfgInferMode(InferMode mode) {
  341. desc.mode = mode;
  342. return *this;
  343. }
  344. /** @brief Specifies the output precision for model.
  345. The function is used to set an output precision for model.
  346. @param precision Precision in OpenCV format (CV_8U, CV_32F, ...)
  347. will be applied to all output layers.
  348. @return reference to this parameter structure.
  349. */
  350. Params<Net>& cfgOutputPrecision(detail::ParamDesc::PrecisionT precision) {
  351. desc.output_precision = precision;
  352. return *this;
  353. }
  354. /** @overload
  355. @param precision_map Map of pairs: name of corresponding output layer
  356. and its precision in OpenCV format (CV_8U, CV_32F, ...)
  357. @return reference to this parameter structure.
  358. */
  359. Params<Net>&
  360. cfgOutputPrecision(detail::ParamDesc::PrecisionMapT precision_map) {
  361. desc.output_precision = precision_map;
  362. return *this;
  363. }
  364. /** @brief Specifies the input layout for model.
  365. The function is used to set an input layout for model.
  366. @param layout Layout in string representation ("NCHW", "NHWC", etc)
  367. will be applied to all input layers.
  368. @return reference to this parameter structure.
  369. */
  370. Params<Net>& cfgInputLayout(std::string layout) {
  371. desc.input_layout = std::move(layout);
  372. return *this;
  373. }
  374. /** @overload
  375. @param layout_map Map of pairs: name of corresponding input layer
  376. and its layout in string representation ("NCHW", "NHWC", etc)
  377. @return reference to this parameter structure.
  378. */
  379. Params<Net>&
  380. cfgInputLayout(detail::AttrMap<std::string> layout_map) {
  381. desc.input_layout = std::move(layout_map);
  382. return *this;
  383. }
  384. /** @brief Specifies the output layout for model.
  385. The function is used to set an output layout for model.
  386. @param layout Layout in string representation ("NCHW", "NHWC", etc)
  387. will be applied to all output layers.
  388. @return reference to this parameter structure.
  389. */
  390. Params<Net>& cfgOutputLayout(std::string layout) {
  391. desc.output_layout = std::move(layout);
  392. return *this;
  393. }
  394. /** @overload
  395. @param layout_map Map of pairs: name of corresponding output layer
  396. and its layout in string representation ("NCHW", "NHWC", etc)
  397. @return reference to this parameter structure.
  398. */
  399. Params<Net>&
  400. cfgOutputLayout(detail::AttrMap<std::string> layout_map) {
  401. desc.output_layout = std::move(layout_map);
  402. return *this;
  403. }
  404. /** @brief Specifies resize interpolation algorithm.
  405. *
  406. The function is used to configure resize preprocessing for input layer.
  407. @param interpolation Resize interpolation algorithm.
  408. Supported algorithms: #INTER_LINEAR, #INTER_AREA.
  409. @return reference to this parameter structure.
  410. */
  411. Params<Net>& cfgResize(int interpolation) {
  412. desc.interpolation = interpolation;
  413. return *this;
  414. }
  415. /** @overload
  416. @param interpolation Map of pairs: name of corresponding input layer
  417. and its resize algorithm.
  418. @return reference to this parameter structure.
  419. */
  420. Params<Net>& cfgResize(detail::AttrMap<int> interpolation) {
  421. desc.interpolation = std::move(interpolation);
  422. return *this;
  423. }
  424. // BEGIN(G-API's network parametrization API)
  425. GBackend backend() const { return cv::gapi::ie::backend(); }
  426. std::string tag() const { return Net::tag(); }
  427. cv::util::any params() const { return { desc }; }
  428. // END(G-API's network parametrization API)
  429. protected:
  430. detail::ParamDesc desc;
  431. };
  432. /*
  433. * @brief This structure provides functions for generic network type that
  434. * fill inference parameters.
  435. * @see struct Generic
  436. */
  437. template<>
  438. class Params<cv::gapi::Generic> {
  439. public:
  440. /** @brief Class constructor.
  441. Constructs Params based on model information and sets default values for other
  442. inference description parameters. Model is loaded and compiled using OpenVINO Toolkit.
  443. @param tag string tag of the network for which these parameters are intended.
  444. @param model path to topology IR (.xml file).
  445. @param weights path to weights (.bin file).
  446. @param device target device to use.
  447. */
  448. Params(const std::string &tag,
  449. const std::string &model,
  450. const std::string &weights,
  451. const std::string &device)
  452. : desc{ model, weights, device, {}, {}, {}, 0u, 0u,
  453. detail::ParamDesc::Kind::Load, true, {}, {}, {}, 1u,
  454. {}, {}, {}, {}, InferMode::Async, {}, {}, {}, {} },
  455. m_tag(tag) {
  456. }
  457. /** @overload
  458. This constructor for pre-compiled networks. Model is imported from pre-compiled
  459. blob.
  460. @param tag string tag of the network for which these parameters are intended.
  461. @param model path to model.
  462. @param device target device to use.
  463. */
  464. Params(const std::string &tag,
  465. const std::string &model,
  466. const std::string &device)
  467. : desc{ model, {}, device, {}, {}, {}, 0u, 0u,
  468. detail::ParamDesc::Kind::Import, true, {}, {}, {}, 1u,
  469. {}, {}, {}, {}, InferMode::Async, {}, {}, {}, {} },
  470. m_tag(tag) {
  471. }
  472. /** @see ie::Params::pluginConfig. */
  473. Params& pluginConfig(const IEConfig& cfg) {
  474. desc.config = cfg;
  475. return *this;
  476. }
  477. /** @overload */
  478. Params& pluginConfig(IEConfig&& cfg) {
  479. desc.config = std::move(cfg);
  480. return *this;
  481. }
  482. /** @see ie::Params::constInput. */
  483. Params& constInput(const std::string &layer_name,
  484. const cv::Mat &data,
  485. TraitAs hint = TraitAs::TENSOR) {
  486. desc.const_inputs[layer_name] = {data, hint};
  487. return *this;
  488. }
  489. /** @see ie::Params::cfgNumRequests. */
  490. Params& cfgNumRequests(size_t nireq) {
  491. GAPI_Assert(nireq > 0 && "Number of infer requests must be greater than zero!");
  492. desc.nireq = nireq;
  493. return *this;
  494. }
  495. /** @see ie::Params::cfgInputReshape */
  496. Params& cfgInputReshape(const std::map<std::string, std::vector<std::size_t>>&reshape_table) {
  497. desc.reshape_table = reshape_table;
  498. return *this;
  499. }
  500. /** @overload */
  501. Params& cfgInputReshape(std::map<std::string, std::vector<std::size_t>> && reshape_table) {
  502. desc.reshape_table = std::move(reshape_table);
  503. return *this;
  504. }
  505. /** @overload */
  506. Params& cfgInputReshape(std::string && layer_name, std::vector<size_t> && layer_dims) {
  507. desc.reshape_table.emplace(layer_name, layer_dims);
  508. return *this;
  509. }
  510. /** @overload */
  511. Params& cfgInputReshape(const std::string & layer_name, const std::vector<size_t>&layer_dims) {
  512. desc.reshape_table.emplace(layer_name, layer_dims);
  513. return *this;
  514. }
  515. /** @overload */
  516. Params& cfgInputReshape(std::unordered_set<std::string> && layer_names) {
  517. desc.layer_names_to_reshape = std::move(layer_names);
  518. return *this;
  519. }
  520. /** @overload */
  521. Params& cfgInputReshape(const std::unordered_set<std::string>&layer_names) {
  522. desc.layer_names_to_reshape = layer_names;
  523. return *this;
  524. }
  525. /** @see ie::Params::cfgBatchSize */
  526. Params& cfgBatchSize(const size_t size) {
  527. desc.batch_size = cv::util::make_optional(size);
  528. return *this;
  529. }
  530. /** @see ie::Params::cfgInferAPI */
  531. Params& cfgInferMode(InferMode mode) {
  532. desc.mode = mode;
  533. return *this;
  534. }
  535. /** @see ie::Params::cfgOutputPrecision */
  536. Params& cfgOutputPrecision(detail::ParamDesc::PrecisionT precision) {
  537. desc.output_precision = precision;
  538. return *this;
  539. }
  540. /** @overload */
  541. Params&
  542. cfgOutputPrecision(detail::ParamDesc::PrecisionMapT precision_map) {
  543. desc.output_precision = precision_map;
  544. return *this;
  545. }
  546. /** @see ie::Params::cfgInputLayout */
  547. Params& cfgInputLayout(std::string layout) {
  548. desc.input_layout = std::move(layout);
  549. return *this;
  550. }
  551. /** @overload */
  552. Params&
  553. cfgInputLayout(detail::AttrMap<std::string> layout_map) {
  554. desc.input_layout = std::move(layout_map);
  555. return *this;
  556. }
  557. /** @see ie::Params::cfgOutputLayout */
  558. Params& cfgOutputLayout(std::string layout) {
  559. desc.output_layout = std::move(layout);
  560. return *this;
  561. }
  562. /** @overload */
  563. Params&
  564. cfgOutputLayout(detail::AttrMap<std::string> layout_map) {
  565. desc.output_layout = std::move(layout_map);
  566. return *this;
  567. }
  568. /** @see ie::Params::cfgResize */
  569. Params& cfgResize(int interpolation) {
  570. desc.interpolation = interpolation;
  571. return *this;
  572. }
  573. /** @overload */
  574. Params& cfgResize(detail::AttrMap<int> interpolation) {
  575. desc.interpolation = std::move(interpolation);
  576. return *this;
  577. }
  578. // BEGIN(G-API's network parametrization API)
  579. GBackend backend() const { return cv::gapi::ie::backend(); }
  580. std::string tag() const { return m_tag; }
  581. cv::util::any params() const { return { desc }; }
  582. // END(G-API's network parametrization API)
  583. protected:
  584. detail::ParamDesc desc;
  585. std::string m_tag;
  586. };
  587. } // namespace ie
  588. } // namespace gapi
  589. } // namespace cv
  590. #endif // OPENCV_GAPI_INFER_IE_HPP