openvinotoolkit / openvino

OpenVINO™ is an open-source toolkit for optimizing and deploying AI inference
https://docs.openvino.ai
Apache License 2.0
7.25k stars 2.26k forks source link

[Feature Request]: Convolution #24296

Open lcx1874000 opened 6 months ago

lcx1874000 commented 6 months ago

Request Description

class ov::op::v1::Convolution。Convolution, can you use this API like torch.nn.Conv2d in Pytorch? I refer to the build model in the official example. This method requires compile_model. I want to call this convolution separately. I looked at the documentation but could not find the relevant interface. Do you support the above operations

Feature Use Case

Convolution, can you use this API like torch.nn.Conv2d in Pytorch?

Issue submission checklist

rkazants commented 6 months ago

Hi @lcx1874000,

As I understand, you want to create the single layer model that contain OV Convolution and run it for inference. Here is an example how to create the single layer model with Divide operation:

import numpy as np
import openvino.runtime.opset9 as ov
from openvino.runtime import Model, Core

# create a model with TopK
x = ov.parameter([1], name="x", dtype=np.int32)
y = ov.parameter([1], name="y", dtype=np.int32)
divide = ov.divide(x, y)
model = Model([divide], [x, y], "model")

# infer it on CPU
core = Core()
compiled_model = core.compile_model(model, "CPU")
output = compiled_model.infer_new_request({0: np.array([4], dtype=np.int32), 1: np.array([-3], dtype=np.int32)})

Since you want to create with Convolution, please refer to Convolution Python documentation: https://docs.openvino.ai/2024/api/ie_python_api/_autosummary/openvino.runtime.opset14.convolution.html Examples with convolution in test: https://github.com/openvinotoolkit/openvino/blob/master/src/bindings/python/tests/test_graph/test_convolution.py

Pay attention that we have no eager execution mode for inference. Please elaborate your request more if I missed somenthing.

Best regards, Roman