Exemple #1
0
def test_clone_model():
    # Create an original model
    shape = [2, 2]
    parameter_a = ops.parameter(shape, dtype=np.float32, name="A")
    parameter_b = ops.parameter(shape, dtype=np.float32, name="B")
    model_original = ov.Model(parameter_a + parameter_b,
                              [parameter_a, parameter_b])

    # Make copies of it
    model_copy1 = ov.utils.clone_model(model_original)
    model_copy2 = model_original.clone()

    # Make changes to the copied models' inputs
    model_copy1.reshape({"A": [3, 3], "B": [3, 3]})
    model_copy2.reshape({"A": [3, 3], "B": [3, 3]})

    original_model_shapes = [
        single_input.get_shape() for single_input in model_original.inputs
    ]
    model_copy1_shapes = [
        single_input.get_shape() for single_input in model_copy1.inputs
    ]
    model_copy2_shapes = [
        single_input.get_shape() for single_input in model_copy2.inputs
    ]

    assert original_model_shapes != model_copy1_shapes
    assert original_model_shapes != model_copy2_shapes
    assert model_copy1_shapes == model_copy2_shapes
Exemple #2
0
def create_model():
    # This example shows how to create ov::Function
    #
    # 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)
    return ov.Model([res], [data], "model")
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")
def create_advanced_model():
    # Advanced example with multi output operation
    #
    # Parameter->Split---0-->Result
    #               | `--1-->Relu-->Result
    #               `----2-->Result
    data = ov.opset8.parameter(ov.Shape([1, 3, 64, 64]), ov.Type.f32)
    # Create Constant for axis value
    axis_const = ov.opset8.constant(ov.Type.i64, ov.Shape({}), [1])

    # Create opset8::Split operation that splits input to three slices across 1st dimension
    split = ov.opset8.split(data, axis_const, 3)

    # Create opset8::Relu operation that takes 1st Split output as input
    relu = ov.opset8.relu(split.output(1))

    # Results operations will be created automatically based on provided OutputVector
    return ov.Model([split.output(0), relu, split.output[2]], [data], "model")
Exemple #5
0
#         |   Concat   |
#         |   concat   |
#         |____________|
#               |
#               | concat_t
#               |
#        _______|_______
#        |    Result   |
#        |    result   |
#        |_____________|

import openvino.runtime as ov


data1 = ov.opset8.parameter([1, 3, 2, 2], ov.Type.i64)
data1.friendly_name = "data1"      # operation name
data1.output(0).name = "data1_t" # tensor name
data2 = ov.opset8.parameter([1, 2, 2, 2], ov.Type.i64)
data2.friendly_name = "data2"      # operation name
data2.output(0).name = "data2_t"   # tensor name

concat = ov.opset8.concat([data1, data2], 1)
concat.friendly_name = "concat"    # operation name
concat.output(0).name = "concat_t" # tensor name

result = ov.opset8.result(concat)
result.friendly_name = "result"    # operation name

model = ov.Model(result, [data1, data2], "model_name")
#! [ov:graph]
Exemple #6
0
# SPDX-License-Identifier: Apache-2.0

import numpy as np

#! [auto_compilation]
import openvino.runtime as ov

compiled_model = ov.compile_model("model.xml")
#! [auto_compilation]

#! [properties_example]
core = ov.Core()

input_a = ov.opset8.parameter([8])
res = ov.opset8.absolute(input_a)
model = ov.Model(res, [input_a])
compiled = core.compile_model(model, "CPU")

print(model.inputs)
print(model.outputs)

print(compiled.inputs)
print(compiled.outputs)
#! [properties_example]

#! [tensor_basics]
data_float64 = np.ones(shape=(2, 8))

tensor = ov.Tensor(data_float64)
assert tensor.element_type == ov.Type.f64