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

Recursion Error in Model Inspector #1462

Open
jakobropers-snkeos opened this issue Sep 11, 2024 · 0 comments
Open

Recursion Error in Model Inspector #1462

jakobropers-snkeos opened this issue Sep 11, 2024 · 0 comments

Comments

@jakobropers-snkeos
Copy link

System: WSL Ubuntu 20.04
Vitis Version: 3.0

I am running the following code:

from mmpose.apis import inference_topdown, init_model
from mmpose.utils import register_all_modules
import cv2
import torch
from pytorch_nndct import Inspector
import torchvision.transforms as transforms
from mmpose.structures import PoseDataSample
import numpy as np
from mmengine.registry import init_default_scope
from mmengine.dataset import Compose, pseudo_collate

register_all_modules()

config_file = 'models/td-hm_hrnet-w48_8xb32-210e_coco-256x192.py'
checkpoint_file = 'models/td-hm_hrnet-w48_8xb32-210e_coco-256x192-0e67c616_20220913.pth'
model = init_model(config_file, checkpoint_file, device='cuda:0')  # or device='cuda:0'

img = cv2.imread("data/sample_input/Screenshot.png")
scope = model.cfg.get('default_scope', 'mmpose')
if scope is not None:
    init_default_scope(scope)
pipeline = Compose(model.cfg.test_dataloader.dataset.pipeline)
h, w = img.shape[:2]
bboxes = np.array([[0, 0, w, h]], dtype=np.float32)
data_list = []
for bbox in bboxes:
    if isinstance(img, str):
        data_info = dict(img_path=img)
    else:
        data_info = dict(img=img)
    data_info['bbox'] = bbox[None]  # shape (1, 4)
    data_info['bbox_score'] = np.ones(1, dtype=np.float32)  # shape (1,)
    data_info.update(model.dataset_meta)
    data_list.append(pipeline(data_info))

batch = pseudo_collate(data_list)


# Check if the model is a PyTorch model
if isinstance(model, torch.nn.Module):
    print("This is a PyTorch model.")
else:
    print("This is NOT a PyTorch model.")

# Specify a target name or fingerprint you want to deploy on
target = "DPUCZDX8G_ISA1_B4096"
# Initialize inspector with target
inspector = Inspector(target)

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
inspector.inspect(model, batch, device=device, output_dir="inspect", image_format="png") 

From this I get the following error:

[VAIQ_NOTE]: Loading NNDCT kernels...
Loads checkpoint by local backend from path: models/td-hm_hrnet-w48_8xb32-210e_coco-256x192-0e67c616_20220913.pth
This is a PyTorch model.

[VAIQ_NOTE]: Inspector is on.

[VAIQ_NOTE]: =>Start to inspect model...
Traceback (most recent call last):
  File "rtmpose_model_inspection.py", line 51, in <module>
    inspector.inspect(model, batch, device=device, output_dir="inspect", image_format="png") 
  File "/opt/vitis_ai/conda/envs/vitis-ai-pytorch/lib/python3.7/site-packages/pytorch_nndct/apis.py", line 196, in inspect
    self._inspector_impl.inspect(module, input_args, device, output_dir, verbose_level)
  File "/opt/vitis_ai/conda/envs/vitis-ai-pytorch/lib/python3.7/site-packages/pytorch_nndct/hardware_v3/inspector.py", line 52, in inspect
    dev_graph, deploy_graphs = prepare_deployable_graph(copied_model, input_args, device, output_dir)
  File "/opt/vitis_ai/conda/envs/vitis-ai-pytorch/lib/python3.7/site-packages/pytorch_nndct/hardware_v3/utils.py", line 25, in prepare_deployable_graph
    module, input_args = to_device(module, input_args, device)
  File "/opt/vitis_ai/conda/envs/vitis-ai-pytorch/lib/python3.7/site-packages/pytorch_nndct/utils/module_util.py", line 382, in to_device
    _, inp = to_device(None, input_args[i], device)
  File "/opt/vitis_ai/conda/envs/vitis-ai-pytorch/lib/python3.7/site-packages/pytorch_nndct/utils/module_util.py", line 382, in to_device
    _, inp = to_device(None, input_args[i], device)
  File "/opt/vitis_ai/conda/envs/vitis-ai-pytorch/lib/python3.7/site-packages/pytorch_nndct/utils/module_util.py", line 382, in to_device
    _, inp = to_device(None, input_args[i], device)
  [Previous line repeated 990 more times]
  File "/opt/vitis_ai/conda/envs/vitis-ai-pytorch/lib/python3.7/site-packages/pytorch_nndct/utils/module_util.py", line 376, in to_device
    if isinstance(input_args, torch.Tensor):
RecursionError: maximum recursion depth exceeded while calling a Python object

Has anyone experienced this before? What could be causing this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant