Added documentation for get_layout API (#13937)

* Added documentation for get_layout API

* Fixed typo
This commit is contained in:
Ilya Churaev 2022-11-10 19:10:07 +04:00 committed by GitHub
parent cf34d48e53
commit 63e24773ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 1 deletions

View File

@ -147,6 +147,26 @@ A layout can be converted to a string in the advanced syntax format. It can be u
@endsphinxtabset
### Get layout from Model Input/Output
OpenVINO provides helpers which provide a simple interface to get layout from Model input or output.
@sphinxtabset
@sphinxtab{C++}
@snippet docs/snippets/ov_layout.cpp ov:layout:get_from_model
@endsphinxtab
@sphinxtab{Python}
@snippet docs/snippets/ov_layout.py ov:layout:get_from_model
@endsphinxtab
@endsphinxtabset
## See also
* API Reference: <code>ov::Layout</code> C++ class

View File

@ -1,7 +1,8 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <openvino/core/layout.hpp>
#include "openvino/core/layout.hpp"
#include "openvino/core/model.hpp"
int main() {
ov::Layout layout;
@ -54,5 +55,13 @@ layout = ov::Layout("NCHW");
std::cout << layout.to_string(); // prints [N,C,H,W]
//! [ov:layout:dump]
std::shared_ptr<ov::Model> model;
//! [ov:layout:get_from_model]
// Get layout for model input
layout = ov::layout::get_layout(model->input("input_tensor_name"));
// Get layout for model with single output
layout = ov::layout::get_layout(model->output());
//! [ov:layout:get_from_model]
return 0;
}

View File

@ -1,6 +1,7 @@
# Copyright (C) 2018-2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
import openvino.runtime as ov
# ! [ov:layout:simple]
from openvino.runtime import Layout
@ -52,3 +53,27 @@ layout_helpers.width_idx(Layout('...HW'))
layout = Layout('NCHW')
print(layout) # prints [N,C,H,W]
# ! [ov:layout:dump]
def create_simple_model():
# This example shows how to create ov::Function
#
# Parameter--->Multiply--->Add--->Result
# Constant---' /
# Constant---'
data = ov.opset8.parameter([3, 1, 2], ov.Type.f32)
mul_constant = ov.opset8.constant([1.5], ov.Type.f32)
mul = ov.opset8.multiply(data, mul_constant)
add_constant = ov.opset8.constant([0.5], ov.Type.f32)
add = ov.opset8.add(mul, add_constant)
res = ov.opset8.result(add)
return ov.Model([res], [data], "model")
model = create_simple_model()
# ! [ov:layout:get_from_model]
# Get layout for model input
layout = layout_helpers.get_layout(model.input("input_tensor_name"))
# Get layout for model with single output
layout = layout_helpers.get_layout(model.output())
# ! [ov:layout:get_from_model]