question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: expected Tensor as element 1 in argument 0, but got int when converting from swin to onnx

See original GitHub issue

Thanks for your bug report. We appreciate it a lot.

Checklist

  1. I have searched related issues but cannot get the expected help.
  2. I have read the FAQ documentation but cannot get the expected help.
  3. The bug has not been fixed in the latest version.

Describe the bug

Error when converting swin to onnx

Reproduction

can be reproduced in the following colab notebook https://colab.research.google.com/drive/1_uf5cFgQNohxP48dztI1qmcSVa4KQ6rz?usp=sharing

wget https://download.openmmlab.com/mmdetection/v2.0/swin/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco_20210908_165006-90a4008c.pth

python tools/deploy.py \
    ./mmdeploy/configs/mmdet/instance-seg/instance-seg_onnxruntime_static.py \
    ./mmdetection/configs/swin/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco.py \
    ./mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco_20210908_165006-90a4008c.pth \
    ./mmdetection/demo/demo.jpg \
    --work-dir ./outputs \
    --device cuda:0 \
    --show
  1. Did you make any modifications on the code or config? Did you understand what you have modified? No changes made

Environment

  1. Please run python tools/check_env.py to collect necessary environment information and paste it here. 2022-08-21 14:55:13,190 - mmdeploy - INFO -

2022-08-21 14:55:13,190 - mmdeploy - INFO - Environmental information 2022-08-21 14:55:13,518 - mmdeploy - INFO - sys.platform: linux 2022-08-21 14:55:13,519 - mmdeploy - INFO - Python: 3.7.13 (default, Apr 24 2022, 01:04:09) [GCC 7.5.0] 2022-08-21 14:55:13,519 - mmdeploy - INFO - CUDA available: True 2022-08-21 14:55:13,519 - mmdeploy - INFO - GPU 0: Tesla P100-PCIE-16GB 2022-08-21 14:55:13,519 - mmdeploy - INFO - CUDA_HOME: /usr/local/cuda 2022-08-21 14:55:13,519 - mmdeploy - INFO - NVCC: Cuda compilation tools, release 11.1, V11.1.105 2022-08-21 14:55:13,519 - mmdeploy - INFO - GCC: x86_64-linux-gnu-gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 2022-08-21 14:55:13,519 - mmdeploy - INFO - PyTorch: 1.12.1+cu113 2022-08-21 14:55:13,519 - mmdeploy - INFO - PyTorch compiling details: PyTorch built with:

  • GCC 9.3
  • C++ Version: 201402
  • Intel® Math Kernel Library Version 2020.0.0 Product Build 20191122 for Intel® 64 architecture applications
  • Intel® MKL-DNN v2.6.0 (Git Hash 52b5f107dd9cf10910aaa19cb47f3abf9b349815)
  • OpenMP 201511 (a.k.a. OpenMP 4.5)
  • LAPACK is enabled (usually provided by MKL)
  • NNPACK is enabled
  • CPU capability usage: AVX2
  • CUDA Runtime 11.3
  • NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86
  • CuDNN 8.3.2 (built against CUDA 11.5)
  • Magma 2.5.2
  • Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.3, CUDNN_VERSION=8.3.2, CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, CXX_FLAGS= -fabi-version=11 -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.12.1, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=OFF, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF,

2022-08-21 14:55:13,519 - mmdeploy - INFO - TorchVision: 0.13.1+cu113 2022-08-21 14:55:13,519 - mmdeploy - INFO - OpenCV: 4.6.0 2022-08-21 14:55:13,519 - mmdeploy - INFO - MMCV: 1.6.1 2022-08-21 14:55:13,519 - mmdeploy - INFO - MMCV Compiler: GCC 9.3 2022-08-21 14:55:13,519 - mmdeploy - INFO - MMCV CUDA Compiler: 11.3 2022-08-21 14:55:13,519 - mmdeploy - INFO - MMDeploy: 0.7.0+1f8d889 2022-08-21 14:55:13,519 - mmdeploy - INFO -

2022-08-21 14:55:13,519 - mmdeploy - INFO - Backend information 2022-08-21 14:55:14,184 - mmdeploy - INFO - onnxruntime: 1.8.1 ops_is_avaliable : False 2022-08-21 14:55:14,187 - mmdeploy - INFO - tensorrt: None ops_is_avaliable : False 2022-08-21 14:55:14,213 - mmdeploy - INFO - ncnn: None ops_is_avaliable : False 2022-08-21 14:55:14,214 - mmdeploy - INFO - pplnn_is_avaliable: False 2022-08-21 14:55:14,216 - mmdeploy - INFO - openvino_is_avaliable: False 2022-08-21 14:55:14,240 - mmdeploy - INFO - snpe_is_available: False 2022-08-21 14:55:14,241 - mmdeploy - INFO -

2022-08-21 14:55:14,241 - mmdeploy - INFO - Codebase information 2022-08-21 14:55:14,242 - mmdeploy - INFO - mmdet: 2.25.1 2022-08-21 14:55:14,242 - mmdeploy - INFO - mmseg: None 2022-08-21 14:55:14,242 - mmdeploy - INFO - mmcls: None 2022-08-21 14:55:14,242 - mmdeploy - INFO - mmocr: None 2022-08-21 14:55:14,243 - mmdeploy - INFO - mmedit: None 2022-08-21 14:55:14,243 - mmdeploy - INFO - mmdet3d: None 2022-08-21 14:55:14,243 - mmdeploy - INFO - mmpose: None 2022-08-21 14:55:14,243 - mmdeploy - INFO - mmrotate: None

  1. You may add addition that may be helpful for locating the problem, such as Run on colab

Error traceback

  File "/content/mmdetection/mmdet/models/backbones/swin.py", line 210, in forward
    img_mask[:, h, w, :] = cnt
  File "/content/mmdeploy/mmdeploy/core/rewriters/rewriter_utils.py", line 379, in wrapper
    return self.func(self, *args, **kwargs)
  File "/content/mmdeploy/mmdeploy/pytorch/functions/tensor_setitem.py", line 62, in tensor__setitem__default
    out = torch.cat(cat_list, dim=i)
TypeError: expected Tensor as element 1 in argument 0, but got **int**

Bug fix

If you have already identified the reason, you can provide the information here. If you are willing to create a PR to fix it, please also leave a comment here and that would be much appreciated!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
grimoirecommented, Aug 24, 2022

I see. it is a bug of slice put by int. I will fix it ASAP. Thanks for the report.

0reactions
ducky777commented, Aug 23, 2022

https://colab.research.google.com/drive/1_uf5cFgQNohxP48dztI1qmcSVa4KQ6rz?usp=sharing

if you run all cells in the notebook above you will get the error.

Alternatively, could you let me know the exact pytorch version you’re using that’s stable? @AllentDan mentioned that it may be PyTorch’s version issue.

EDIT:

The error comes from running the following:

Weights downloaded from: https://download.openmmlab.com/mmdetection/v2.0/swin/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco_20210908_165006-90a4008c.pth

python tools/deploy.py \
    /content/mmdeploy/configs/mmdet/instance-seg/instance-seg_onnxruntime_static.py \
    /content/mmdetection/configs/swin/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco.py \
    /content/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco_20210908_165006-90a4008c.pth \
    /content/mmdetection/demo/demo.jpg \
    --work-dir /content/drive/MyDrive/data \
    --device cuda:0 \
    --show
Read more comments on GitHub >

github_iconTop Results From Across the Web

expected Tensor as element 0 in argument 0, but got int
I was using this example code in a deep q network but it keeps throwing an error “TypeError: expected Tensor as element 0...
Read more >
TypeError: expected Tensor as element 0 in argument 0, but ...
TypeError : expected Tensor as element 0 in argument 0, but got list. ... when run onnx vad example, it showed the error....
Read more >
expected Tensor as element 0 in argument 0, but got list
Usually this error is when we convert our data to torch tensor data type, it means that most of our conversion programs are...
Read more >
mmdet.apis — MMDetection 2.26.0 documentation
Tensor ) – Scales of the anchor. ratios (torch.Tensor) – The ratio between between the height and width of anchors in a single...
Read more >
expecter Tensor as element 0 in argument 0, but got tuple
I am using nvidia's neural rescorer to get a score of the model i trained. how do i say, if torch.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found