Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS] Recreation of Namespace redesign for 23.1 #19917

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/optimization_guide/nncf/ptq/code/ptq_aa_openvino.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def transform_fn(data_item):
#! [validation]
import numpy as np
import torch
import openvino
import openvino as ov
from sklearn.metrics import accuracy_score

def validate(model: openvino.CompiledModel,
def validate(model: ov.CompiledModel,
validation_loader: torch.utils.data.DataLoader) -> float:
predictions = []
references = []
Expand Down
6 changes: 3 additions & 3 deletions docs/snippets/gpu/preprocessing_nv12_two_planes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

core = ov.Core()

p = PrePostProcessor(model)
p = ov.preprocess.PrePostProcessor(model)
p.input().tensor().set_element_type(ov.Type.u8).set_color_format(
ColorFormat.NV12_TWO_PLANES, ["y", "uv"]
ov.preprocess.ColorFormat.NV12_TWO_PLANES, ["y", "uv"]
).set_memory_type("GPU_SURFACE")
p.input().preprocess().convert_color(ColorFormat.BGR)
p.input().preprocess().convert_color(ov.preprocess.ColorFormat.BGR)
p.input().model().set_layout(ov.Layout("NCHW"))
model_with_preproc = p.build()
#! [init_preproc]
1 change: 0 additions & 1 deletion docs/snippets/ov_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
assert compiled_model

# ! [ov:caching:part1]
core = ov.Core()
compiled_model = core.compile_model(model=model_path, device_name=device_name)
# ! [ov:caching:part1]

Expand Down
18 changes: 8 additions & 10 deletions docs/snippets/ov_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

import openvino as ov
from openvino.tools.mo import convert_model

#! [py_frontend_extension_ThresholdedReLU_header]
import openvino.runtime.opset12 as ops
Expand All @@ -28,26 +29,23 @@
#! [add_extension_lib]

#! [py_frontend_extension_MyRelu]
from openvino.frontend import OpExtension
core.add_extension(OpExtension("Relu", "MyRelu"))
core.add_extension(ov.frontend.OpExtension("Relu", "MyRelu"))
#! [py_frontend_extension_MyRelu]

#! [py_frontend_extension_ThresholdedReLU]
def conversion(node):
input_node = node.get_input(0)
input_type = input_node.get_element_type()
greater = ops.greater(input_node, ops.constant([node.get_attribute("alpha")], input_type))
casted = ops.convert(greater, input_type.get_type_name())
return ops.multiply(input_node, casted).outputs()
greater = ov.runtime.opset8.greater(input_node, ov.runtime.opset8.constant([node.get_attribute("alpha")], input_type))
casted = ov.runtime.opset8.convert(greater, input_type.get_type_name())
return ov.runtime.opset8.multiply(input_node, casted).outputs()

core.add_extension(ConversionExtension("ThresholdedRelu", conversion))
#! [py_frontend_extension_ThresholdedReLU]


#! [py_frontend_extension_aten_hardtanh]
import torch
from openvino.frontend import ConversionExtension, NodeContext
from openvino.tools.mo import convert_model


class HardTanh(torch.nn.Module):
Expand All @@ -60,14 +58,14 @@ def forward(self, inp):
return torch.nn.functional.hardtanh(inp, self.min_val, self.max_val)


def convert_hardtanh(node: NodeContext):
def convert_hardtanh(node: ov.frontend.NodeContext):
inp = node.get_input(0)
min_value = node.get_values_from_const_input(1)
max_value = node.get_values_from_const_input(2)
return ops.clamp(inp, min_value, max_value).outputs()
return ov.runtime.opset8.clamp(inp, min_value, max_value).outputs()


model = HardTanh(min_val=0.1, max_val=2.0)
hardtanh_ext = ConversionExtension("aten::hardtanh", convert_hardtanh)
hardtanh_ext = ov.frontend.ConversionExtension("aten::hardtanh", convert_hardtanh)
ov_model = convert_model(input_model=model, extensions=[hardtanh_ext])
#! [py_frontend_extension_aten_hardtanh]
30 changes: 15 additions & 15 deletions docs/snippets/ov_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,52 @@

# ! [ov:layout:simple]
from openvino import Layout
layout = Layout('NCHW')
layout = ov.Layout('NCHW')
# ! [ov:layout:simple]
# ! [ov:layout:complex]
# Each dimension has name separated by comma
# Layout is wrapped with square brackets
layout = Layout('[time,temperature,humidity]')
layout = ov.Layout('[time,temperature,humidity]')
# ! [ov:layout:complex]
# ! [ov:layout:partially_defined]
# First dimension is batch, 4th is 'channels'.
# Others are not important for us
layout = Layout('N??C')
layout = ov.Layout('N??C')

# Or the same using advanced syntax
layout = Layout('[n,?,?,c]')
layout = ov.Layout('[n,?,?,c]')
# ! [ov:layout:partially_defined]
# ! [ov:layout:dynamic]
# First dimension is 'batch' others are whatever
layout = Layout('N...')
layout = ov.Layout('N...')

# Second dimension is 'channels' others are whatever
layout = Layout('?C...')
layout = ov.Layout('?C...')

# Last dimension is 'channels' others are whatever
layout = Layout('...C')
layout = ov.Layout('...C')
# ! [ov:layout:dynamic]

# ! [ov:layout:predefined]
from openvino.runtime import layout_helpers
# returns 0 for batch
layout_helpers.batch_idx(Layout('NCDHW'))
ov.layout_helpers.batch_idx(ov.Layout('NCDHW'))

# returns 1 for channels
layout_helpers.channels_idx(Layout('NCDHW'))
ov.layout_helpers.channels_idx(ov.Layout('NCDHW'))

# returns 2 for depth
layout_helpers.depth_idx(Layout('NCDHW'))
ov.layout_helpers.depth_idx(ov.Layout('NCDHW'))

# returns -2 for height
layout_helpers.height_idx(Layout('...HW'))
ov.layout_helpers.height_idx(ov.Layout('...HW'))

# returns -1 for width
layout_helpers.width_idx(Layout('...HW'))
ov.layout_helpers.width_idx(ov.Layout('...HW'))
# ! [ov:layout:predefined]

# ! [ov:layout:dump]
layout = Layout('NCHW')
layout = ov.Layout('NCHW')
print(layout) # prints [N,C,H,W]
# ! [ov:layout:dump]

Expand All @@ -74,7 +74,7 @@ def create_simple_model():

# ! [ov:layout:get_from_model]
# Get layout for model input
layout = layout_helpers.get_layout(model.input("input_tensor_name"))
layout = ov.layout_helpers.get_layout(model.input("input_tensor_name"))
# Get layout for model with single output
layout = layout_helpers.get_layout(model.output())
layout = ov.layout_helpers.get_layout(model.output())
# ! [ov:layout:get_from_model]
10 changes: 3 additions & 7 deletions docs/snippets/ov_python_exclusives.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#! [properties_example]

#! [auto_compilation]
compiled_model = ov.compile_model(model)
compiled_model = ov.core().compile_model(model)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, revert changes in snippets folder, they are already updated

#! [auto_compilation]

#! [tensor_basics]
Expand Down Expand Up @@ -143,17 +143,13 @@ def f(request, userdata):
unt8_data = np.ones([100], dtype=np.uint8)

#! [packing_data]
from openvino.helpers import pack_data

packed_buffer = pack_data(unt8_data, ov.Type.u4)
packed_buffer = ov.helpers.pack_data(unt8_data, ov.Type.u4)
# Create tensor with shape in element types
t = ov.Tensor(packed_buffer, [100], ov.Type.u4)
#! [packing_data]

#! [unpacking]
from openvino.helpers import unpack_data

unpacked_data = unpack_data(t.data, t.element_type, t.shape)
unpacked_data = ov.helpers.unpack_data(t.data, t.element_type, t.shape)
assert np.array_equal(unpacked_data , unt8_data)
#! [unpacking]

Expand Down
4 changes: 2 additions & 2 deletions docs/snippets/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def create_model():
#
# To construct a model, please follow
# https://docs.openvino.ai/latest/openvino_docs_OV_UG_Model_Representation.html
data = ov.opset8.parameter([3, 1, 2], ov.Type.f32)
res = ov.opset8.result(data)
data = ov.runtime.opset8.parameter([3, 1, 2], ov.Type.f32)
res = ov.runtime.opset8.result(data)
return ov.Model([res], [data], "model")

model = create_model()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def main():
tput = {'PERFORMANCE_HINT': 'THROUGHPUT'}
# Pick a device by replacing CPU, for example MULTI:CPU(4),GPU(8).
# It is possible to set CUMULATIVE_THROUGHPUT as PERFORMANCE_HINT for AUTO device
compiled_model = core.compile_model(model, 'CPU', tput)
compiled_model = ov.compile_model(model, 'CPU', tput)
# AsyncInferQueue creates optimal number of InferRequest instances
ireqs = ov.AsyncInferQueue(compiled_model)

Expand Down
7 changes: 3 additions & 4 deletions samples/python/benchmark/sync_benchmark/sync_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import numpy as np
import openvino as ov
from openvino.runtime import get_version
from openvino.runtime.utils.types import get_dtype



def fill_tensor_random(tensor):
dtype = get_dtype(tensor.element_type)
dtype = ov.utils.types.get_dtype(tensor.element_type)
rand_min, rand_max = (0, 1) if dtype == bool else (np.iinfo(np.uint8).min, np.iinfo(np.uint8).max)
# np.random.uniform excludes high: add 1 to have it generated
if np.dtype(dtype).kind in ['i', 'u', 'b']:
Expand All @@ -41,8 +41,7 @@ def main():
# Pick a device by replacing CPU, for example AUTO:GPU,CPU.
# Using MULTI device is pointless in sync scenario
# because only one instance of openvino.runtime.InferRequest is used
core = ov.Core()
compiled_model = core.compile_model(sys.argv[1], 'CPU', latency)
compiled_model = ov.compile_model(sys.argv[1], 'CPU', latency)
ireq = compiled_model.create_infer_request()
# Fill input data for the ireq
for model_input in compiled_model.inputs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
import numpy as np
import openvino as ov
from openvino.runtime import get_version
from openvino.runtime.utils.types import get_dtype


def fill_tensor_random(tensor):
dtype = get_dtype(tensor.element_type)
dtype = ov.utils.types.get_dtype(tensor.element_type)
rand_min, rand_max = (0, 1) if dtype == bool else (np.iinfo(np.uint8).min, np.iinfo(np.uint8).max)
# np.random.uniform excludes high: add 1 to have it generated
if np.dtype(dtype).kind in ['i', 'u', 'b']:
Expand All @@ -40,8 +39,7 @@ def main():
# Create Core and use it to compile a model.
# Pick a device by replacing CPU, for example MULTI:CPU(4),GPU(8).
# It is possible to set CUMULATIVE_THROUGHPUT as PERFORMANCE_HINT for AUTO device
core = ov.Core()
compiled_model = core.compile_model(sys.argv[1], 'CPU', tput)
compiled_model = ov.compile_model(sys.argv[1], 'CPU', tput)
# AsyncInferQueue creates optimal number of InferRequest instances
ireqs = ov.AsyncInferQueue(compiled_model)
# Fill input data for ireqs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def main() -> int:

# --------------------------- Step 5. Loading model to the device -----------------------------------------------------
log.info('Loading the model to the plugin')
compiled_model = core.compile_model(model, args.device)
compiled_model = ov.compile_model(model, args.device)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we need to revert changes in samples, because they are updated here f9c0e96


# --------------------------- Step 6. Create infer request queue ------------------------------------------------------
log.info('Starting inference in asynchronous mode')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def main():

# --------------------------- Step 5. Loading model to the device -----------------------------------------------------
log.info('Loading the model to the plugin')
compiled_model = core.compile_model(model, device_name)
compiled_model = ov.compile_model(model, device_name)

# --------------------------- Step 6. Create infer request and do inference synchronously -----------------------------
log.info('Starting inference in synchronous mode')
Expand Down
2 changes: 1 addition & 1 deletion samples/python/hello_reshape_ssd/hello_reshape_ssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def main():

# ---------------------------Step 4. Loading model to the device-------------------------------------------------------
log.info('Loading the model to the plugin')
compiled_model = core.compile_model(model, device_name)
compiled_model = ov.compile_model(model, device_name)

# --------------------------- Step 6. Create infer request and do inference synchronously -----------------------------
log.info('Starting inference in synchronous mode')
Expand Down
Loading