From 6033e52dd9b76374388597e268957d9bb075d77c Mon Sep 17 00:00:00 2001 From: Bartek Szmelczynski Date: Wed, 15 Jun 2022 12:10:00 +0200 Subject: [PATCH] Remove `set_from` from samples, update docstrings (#11889) --- samples/cpp/hello_classification/main.cpp | 2 +- .../hello_classification.py | 3 ++- .../graph/preprocess/pre_post_process.cpp | 24 +++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/samples/cpp/hello_classification/main.cpp b/samples/cpp/hello_classification/main.cpp index 9c797256cbf..942956636de 100644 --- a/samples/cpp/hello_classification/main.cpp +++ b/samples/cpp/hello_classification/main.cpp @@ -76,7 +76,7 @@ int tmain(int argc, tchar* argv[]) { // - input() provides information about a single model input // - reuse precision and shape from already available `input_tensor` // - layout of data is 'NHWC' - ppp.input().tensor().set_from(input_tensor).set_layout(tensor_layout); + ppp.input().tensor().set_shape(input_shape).set_element_type(input_type).set_layout(tensor_layout); // 2) Adding explicit preprocessing steps: // - convert layout to 'NCHW' (from 'NHWC' specified above at tensor layout) // - apply linear resize from tensor spatial dims to model spatial dims diff --git a/samples/python/hello_classification/hello_classification.py b/samples/python/hello_classification/hello_classification.py index 9b8355b0607..0cf38352a5f 100755 --- a/samples/python/hello_classification/hello_classification.py +++ b/samples/python/hello_classification/hello_classification.py @@ -57,7 +57,8 @@ def main(): # - reuse precision and shape from already available `input_tensor` # - layout of data is 'NHWC' ppp.input().tensor() \ - .set_from(input_tensor) \ + .set_shape(input_tensor.shape) \ + .set_element_type(Type.u8) \ .set_layout(Layout('NHWC')) # noqa: ECE001, N400 # 2) Adding explicit preprocessing steps: diff --git a/src/bindings/python/src/pyopenvino/graph/preprocess/pre_post_process.cpp b/src/bindings/python/src/pyopenvino/graph/preprocess/pre_post_process.cpp index d5ba05d8733..5140b102d07 100644 --- a/src/bindings/python/src/pyopenvino/graph/preprocess/pre_post_process.cpp +++ b/src/bindings/python/src/pyopenvino/graph/preprocess/pre_post_process.cpp @@ -301,7 +301,17 @@ static void regclass_graph_InputTensorInfo(py::module m) { [](ov::preprocess::InputTensorInfo& self, const ov::Tensor& tensor) { return &self.set_from(tensor); }, - py::arg("runtime_tensor")); + py::arg("runtime_tensor"), + R"( + Helper function to reuse element type and shape from user's created tensor. Overwrites previously + set shape and element type via `set_shape` and `set_element_type' methods. This method should be + used only in case if runtime tensor is already known and avaiable before. + + :param runtime_tensor: User's created tensor + :type type: openvino.runtime.Tensor + :return: Reference to itself, allows chaining of calls in client's code in a builder-like manner. + :rtype: openvino.runtime.preprocess.InputTensorInfo + )"); info.def( "set_from", @@ -309,7 +319,17 @@ static void regclass_graph_InputTensorInfo(py::module m) { // Convert to contiguous array if not already C-style. return &self.set_from(Common::tensor_from_numpy(numpy_array, false)); }, - py::arg("runtime_tensor")); + py::arg("runtime_tensor"), + R"( + Helper function to reuse element type and shape from user's created tensor. Overwrites previously + set shape and element type via `set_shape` and `set_element_type' methods. This method should be + used only in case if runtime tensor is already known and avaiable before. + + :param runtime_tensor: User's created numpy array + :type type: numpy.ndarray + :return: Reference to itself, allows chaining of calls in client's code in a builder-like manner. + :rtype: openvino.runtime.preprocess.InputTensorInfo + )"); } static void regclass_graph_OutputTensorInfo(py::module m) {