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] fix headless device visualize #1630

Merged
merged 5 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
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
45 changes: 22 additions & 23 deletions mmdeploy/apis/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,26 @@ def visualize_model(model_cfg: Union[str, mmengine.Config],
with torch.no_grad():
result = model.test_step(model_inputs)[0]

visualize = True
try:
# check headless
import tkinter
tkinter.Tk()
except Exception as e:
from mmdeploy.utils import get_root_logger
logger = get_root_logger()
logger.warning(
f'render and display result skipped for headless device, exception {e}' # noqa: E501
)
visualize = False
if show_result:
try:
# check headless
import tkinter
tkinter.Tk()
except Exception as e:
from mmdeploy.utils import get_root_logger
logger = get_root_logger()
logger.warning(
f'render and display result skipped for headless device, exception {e}' # noqa: E501
)
show_result = False

if visualize is True:
if not isinstance(img, list):
img = [img]
for single_img in img:
task_processor.visualize(
image=single_img,
model=model,
result=result,
output_file=output_file,
window_name=backend.value,
show_result=show_result)
if isinstance(img, str) or not isinstance(img, Sequence):
img = [img]
for single_img in img:
task_processor.visualize(
image=single_img,
model=model,
result=result,
output_file=output_file,
window_name=backend.value,
show_result=show_result)
1 change: 1 addition & 0 deletions mmdeploy/codebase/base/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def build_pytorch_model(self,
from mmengine.registry import MODELS

model = deepcopy(self.model_cfg.model)
model.pop('pretrained', None)
preprocess_cfg = deepcopy(self.model_cfg.get('preprocess_cfg', {}))
preprocess_cfg.update(
deepcopy(self.model_cfg.get('data_preprocessor', {})))
Expand Down