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.

Error when running inference on custom trained Cascade RCNN

See original GitHub issue

Thanks for your error report and we appreciate it a lot.

Checklist

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

Describe the bug A clear and concise description of what the bug is. I trained a cascade rcnn on custom data successfully. But when I run inference using the trained model I get an error: RuntimeError: The size of tensor a (81) must match the size of tensor b (10) at non-singleton dimension 1

Reproduction

  1. What command or script did you run?
result = inference_detector(model, image_path)
  1. Did you make any modifications on the code or config? Did you understand what you have modified? Modified number of classes and parameters for custom dataset. The model trained successfully.
  2. What dataset did you use? Custom dataset with 9 classes + 1 background class

Environment

  1. Please run python tools/collect_env.py to collect necessary environment infomation and paste it here.
sys.platform: linux
Python: 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) [GCC 7.2.0]
CUDA available: True
CUDA_HOME: /usr/local/cuda-10.1
NVCC: Cuda compilation tools, release 10.1, V10.1.243
GPU 0: Tesla V100-SXM2-16GB
GCC: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
PyTorch: 1.3.1
PyTorch compiling details: PyTorch built with:
  - GCC 7.3
  - Intel(R) Math Kernel Library Version 2018.0.3 Product Build 20180406 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v0.20.5 (Git Hash 0125f28c61c1f822fd48570b4c1066f96fcb9b2e)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - NNPACK is enabled
  - CUDA Runtime 10.1
  - 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_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_37,code=compute_37
  - CuDNN 7.6.3
  - Magma 2.5.1
  - Build settings: BLAS=MKL, BUILD_NAMEDTENSOR=OFF, BUILD_TYPE=Release, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -fopenmp -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -O2 -fPIC -Wno-narrowing -Wall -Wextra -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -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 -Wno-stringop-overflow, DISABLE_NUMA=1, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, USE_CUDA=True, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_STATIC_DISPATCH=OFF, 

TorchVision: 0.4.2
OpenCV: 4.1.2
MMCV: 0.2.16
MMDetection: 1.0rc1+78529ec
MMDetection Compiler: GCC 5.4
MMDetection CUDA Compiler: 10.1
  1. You may add addition that may be helpful for locating the problem, such as
    • How you installed PyTorch [e.g., pip, conda, source]
    • Other environment variables that may be related (such as $PATH, $LD_LIBRARY_PATH, $PYTHONPATH, etc.)

Error traceback If applicable, paste the error trackback here.

Traceback (most recent call last):
  File "prepare_mmdet_detections_txts.py", line 36, in <module>
    bboxes, labels = image_detections(image_path)
  File "prepare_mmdet_detections_txts.py", line 16, in image_detections
    result = inference_detector(model, image_path)
  File "/home/ubuntu/repos/mmdetection/mmdet/apis/inference.py", line 86, in inference_detector
    result = model(return_loss=False, rescale=True, **data)
  File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/ubuntu/repos/mmdetection/mmdet/core/fp16/decorators.py", line 49, in new_func
    return old_func(*args, **kwargs)
  File "/home/ubuntu/repos/mmdetection/mmdet/models/detectors/base.py", line 140, in forward
    return self.forward_test(img, img_meta, **kwargs)
  File "/home/ubuntu/repos/mmdetection/mmdet/models/detectors/base.py", line 123, in forward_test
    return self.simple_test(imgs[0], img_metas[0], **kwargs)
  File "/home/ubuntu/repos/mmdetection/mmdet/models/detectors/cascade_rcnn.py", line 353, in simple_test
    cls_score = sum(ms_scores) / self.num_stages
RuntimeError: The size of tensor a (81) must match the size of tensor b (10) at non-singleton dimension 1

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 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
shliang0603commented, Aug 12, 2020

I meet same error, I have solved it. image

You should modify all num_classes for yourself classes number. Some model configuration files have several num_classes modifications

1reaction
changruowangcommented, Jun 17, 2020

Maybe your three num_classes is not same

Read more comments on GitHub >

github_iconTop Results From Across the Web

3: Train with customized models and standard datasets
In this note, you will know how to train, test and inference your own customized models under standard datasets. We use the cityscapes...
Read more >
How to Train Detectron2 on Custom Object Detection Data
Run Detectron2 inference on test images. And finally, we can run our new custom Detectron2 detector on real images! Note, these are images...
Read more >
Object Detection with PyTorch and Detectron2
In this post, we will show you how to train Detectron2 on Gradient to detect custom objects ie Flowers on Gradient.
Read more >
How to train an object detection model with mmdetection
This tutorial shows you how to train a Pytorch mmdetection object detection model with your custom dataset, and minimal effort on Google Colab...
Read more >
Train Mask R-CNN on a Custom Dataset - YouTube
This video covers how to train Mask R-CNN on your own custom data with Keras. You can find the full code and run...
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