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

pytorch2onnx API supports multimodal input #2644

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions mmdeploy/apis/pytorch2onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def torch2onnx(img: Any,
deploy_cfg: Union[str, mmengine.Config],
model_cfg: Union[str, mmengine.Config],
model_checkpoint: Optional[str] = None,
append_input: list = None,
device: str = 'cuda:0'):
"""Convert PyTorch model to ONNX model.

Expand Down Expand Up @@ -42,6 +43,7 @@ def torch2onnx(img: Any,
model_cfg (str | mmengine.Config): Model config file or Config object.
model_checkpoint (str): A checkpoint path of PyTorch model,
defaults to `None`.
append_input (list): Additional inputs other than images, suitable for multimodal models such as text features of Grounded DINO.
device (str): A string specifying device type, defaults to 'cuda:0'.
"""

Expand All @@ -68,6 +70,10 @@ def torch2onnx(img: Any,

if isinstance(model_inputs, list) and len(model_inputs) == 1:
model_inputs = model_inputs[0]
if isinstance(append_input, list):
temp = [model_inputs]
temp.extend(append_input)
model_inputs = temp
data_samples = data['data_samples']
input_metas = {'data_samples': data_samples, 'mode': 'predict'}

Expand Down