Xilinx / Vitis-AI

Vitis AI is Xilinx’s development stack for AI inference on Xilinx hardware platforms, including both edge devices and Alveo cards.
https://www.xilinx.com/ai
Apache License 2.0
1.49k stars 630 forks source link

Recursion Error in Model Inspector #1462

Open jakobropers-snkeos opened 2 months ago

jakobropers-snkeos commented 2 months ago

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?