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

[Fix] import torchvision in wrapper #1702

Merged
merged 1 commit into from
Feb 2, 2023
Merged
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
13 changes: 12 additions & 1 deletion mmdeploy/backend/torchscript/wrapper.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Copyright (c) OpenMMLab. All rights reserved.
import importlib
import os.path as osp
from typing import Dict, Optional, Sequence, Union

import torch

from mmdeploy.utils import Backend
from mmdeploy.utils import Backend, get_root_logger
from mmdeploy.utils.timer import TimeCounter
from ..base import BACKEND_WRAPPER, BaseWrapper
from .init_plugins import get_ops_path
Expand Down Expand Up @@ -39,10 +40,20 @@ def __init__(self,
model: Union[str, torch.jit.RecursiveScriptModule],
input_names: Optional[Sequence[str]] = None,
output_names: Optional[Sequence[str]] = None):
logger = get_root_logger()

# load custom ops if exist
custom_ops_path = get_ops_path()
if osp.exists(custom_ops_path):
torch.ops.load_library(custom_ops_path)

# import torchvision for ops
try:
importlib.import_module('torchvision')
except Exception:
logger.warning(
'Can not import torchvision. '
'Models require ops in torchvision might not available.')
super().__init__(output_names)
self.ts_model = model
if isinstance(self.ts_model, str):
Expand Down