[Preprocess] InputTensorInfo::set_from implementation (#10839)

* InputTensorInfo::from implementation

If user's application already has `ov::runtime::Tensor` object created,
it will be possible to reuse basic characteristics for input (shape, precision) from tensor using InputTensorInfo::from method

* Rename 'from' to 'set_from' as  in Python 'from' keyword is used for import modules
Python bindings: from ov.Tensor and from numpy array

* Style fix (quotes)

* Apply suggestions from code review

Co-authored-by: Ilya Churaev <ilyachur@gmail.com>

* Fix code style

* Use set_from in hello_classification CPP sample

Co-authored-by: Ilya Churaev <ilyachur@gmail.com>
This commit is contained in:
Mikhail Nosov
2022-03-14 18:02:51 +03:00
committed by GitHub
parent 4c4581940a
commit 72fe6082ea
8 changed files with 120 additions and 19 deletions

View File

@@ -54,13 +54,11 @@ def main():
# 1) Set input tensor information:
# - input() provides information about a single model input
# - precision of tensor is supposed to be 'u8'
# - reuse precision and shape from already available `input_tensor`
# - layout of data is 'NHWC'
# - set static spatial dimensions to input tensor to resize from
ppp.input().tensor() \
.set_element_type(Type.u8) \
.set_layout(Layout('NHWC')) \
.set_spatial_static_shape(h, w) # noqa: ECE001, N400
.set_from(input_tensor) \
.set_layout(Layout('NHWC')) # noqa: ECE001, N400
# 2) Adding explicit preprocessing steps:
# - apply linear resize from tensor spatial dims to model spatial dims
@@ -73,7 +71,7 @@ def main():
# - precision of tensor is supposed to be 'f32'
ppp.output().tensor().set_element_type(Type.f32)
# 5) Apply preprocessing modifing the original 'model'
# 5) Apply preprocessing modifying the original 'model'
model = ppp.build()
# --------------------------- Step 5. Loading model to the device -----------------------------------------------------