def test_ngraph_preprocess_set_from_np_infer(): shape = [1, 1, 1] parameter_a = ops.parameter(shape, dtype=np.float32, name="A") model = parameter_a function = Model(model, [parameter_a], "TestFunction") @custom_preprocess_function def custom_crop(out_node: Output): start = ops.constant(np.array([1, 1, 1]), dtype=np.int32) stop = ops.constant(np.array([2, 2, 2]), dtype=np.int32) step = ops.constant(np.array([1, 1, 1]), dtype=np.int32) axis = ops.constant(np.array([0, 1, 2]), dtype=np.int32) return ops.slice(out_node, start, stop, step, axis) input_data = np.array([[[0, 1, 2], [3, 4, 5], [6, 7, 8]], [[9, 10, 11], [12, 13, 14], [15, 16, 17]], [[18, 19, 20], [21, 22, 23], [24, 25, 26]]]).astype(np.int32) p = PrePostProcessor(function) inp = p.input() inp.tensor().set_from(input_data) inp.preprocess().convert_element_type().custom(custom_crop) function = p.build() assert function.input().shape == ov.Shape([3, 3, 3]) assert function.input().element_type == Type.i32 expected_output = np.array([[[13]]]).astype(np.float32) runtime = get_runtime() computation = runtime.computation(function) output = computation(input_data) assert np.equal(output, expected_output).all()
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")
def test_ngraph_preprocess_set_from_tensor(): shape = [1, 224, 224, 3] inp_shape = [1, 480, 640, 3] parameter_a = ops.parameter(shape, dtype=np.float32, name="A") parameter_a.set_layout(ov.Layout("NHWC")) model = parameter_a function = Model(model, [parameter_a], "TestFunction") input_data = ov.Tensor(Type.i32, inp_shape) p = PrePostProcessor(function) inp = p.input() inp.tensor().set_from(input_data) inp.preprocess().resize(ResizeAlgorithm.RESIZE_LINEAR) function = p.build() assert function.input().shape == ov.Shape(inp_shape) assert function.input().element_type == Type.i32 assert function.output().shape == ov.Shape(shape) assert function.output().element_type == Type.f32
input_tensor = ov.Tensor() infer_request.set_tensor(input_port, input_tensor) output_tensor = infer_request.get_tensor(output_port) #! [get_set_tensor_by_port] infer_request1 = compiled_model.create_infer_request() infer_request2 = compiled_model.create_infer_request() #! [cascade_models] output = infer_request1.get_output_tensor(0) infer_request2.set_input_tensor(0, output) #! [cascade_models] #! [roi_tensor] # input_tensor points to input of a previous network and # cropROI contains coordinates of output bounding box **/ input_tensor = ov.Tensor(type=ov.Type.f32, shape=ov.Shape([1, 3, 20, 20])) begin = [0, 0, 0, 0] end = [1, 2, 3, 3] # ... # roi_tensor uses shared memory of input_tensor and describes cropROI # according to its coordinates **/ roi_tensor = ov.Tensor(input_tensor, begin, end) infer_request2.set_tensor("input_name", roi_tensor) #! [roi_tensor] #! [remote_tensor] # NOT SUPPORTED #! [remote_tensor]