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

RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #2 'target' in call to _thnn_nll_loss2d_forward #1600

Open
JackieWang9811 opened this issue Jul 1, 2022 · 1 comment
Assignees

Comments

@JackieWang9811
Copy link

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
RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #2 'target' in call to _thnn_nll_loss2d_forward

Reproduction

  1. What command or script did you run?
python tools/train.py configs/pointnet2/pointnet2_msg_16x2_cosine_80e_s3dis_seg-3d-13class.py
  1. i modified the code in mmdet3d/datasets/pipelines/loading.py line 521 seg_3d_dtype=np.int64 to seg_3d_dtype=np.int32 because of the error: IndexError: index 12884901891 is out of bounds for axis 0 with size 14, and also i modified the code in tools/create_data.py line 211 mask = np.fromfile(mask, dtype=np.int64) to mask = np.fromfile(mask, dtype=np.int32) because of the similar error like above.

  2. I use the S3DIS as the dataset of training model

Environment

fatal: not a git repository (or any of the parent directories): .git
sys.platform: win32
Python: 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 05:35:01) [MSC v.1916 64 bit (AMD64)]
CUDA available: True
GPU 0: NVIDIA GeForce RTX 3060 Laptop GPU
CUDA_HOME: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1
NVCC: Cuda compilation tools, release 11.1, V11.1.74
MSVC: 用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.29.30145 版
GCC: n/a
PyTorch: 1.7.1
PyTorch compiling details: PyTorch built with:

  • C++ Version: 199711
  • MSVC 192729112
  • Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191125 for Intel(R) 64 architecture applications
  • Intel(R) MKL-DNN v1.6.0 (Git Hash 5ef631a030a6f73131c77892041042805a06064f)
  • OpenMP 2019
  • CPU capability usage: AVX2
  • CUDA Runtime 11.0
  • 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_80,code=sm_80;-gencode;arch=compute_37,code=compute_37
  • CuDNN 8.0.4
  • Magma 2.5.4
  • Build settings: BLAS=MKL, BUILD_TYPE=Release, CXX_FLAGS=/DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -openmp:experimental -DNDEBUG -DUSE_FBGEMM -DUSE_VULKAN_WRAPPER, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, USE_CUDA=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=OFF, USE_NNPACK=OFF, USE_OPENMP=ON,

TorchVision: 0.8.2
OpenCV: 4.6.0
MMCV: 1.5.3
MMCV Compiler: MSVC 192930145
MMCV CUDA Compiler: 11.1
MMDetection: 2.25.0
MMSegmentation: 0.25.0
MMDetection3D: 1.0.0rc2+
spconv2.0: False

Error traceback
If applicable, paste the error trackback here.

Traceback (most recent call last):
  File "D:/mmdetection3d-master/tools/train.py", line 263, in <module>
    main()
  File "D:/mmdetection3d-master/tools/train.py", line 259, in main
    meta=meta)
  File "D:\mmdetection3d-master\mmdet3d\apis\train.py", line 342, in train_model
    meta=meta)
  File "D:\mmdetection3d-master\mmdet3d\apis\train.py", line 177, in train_segmentor
    runner.run(data_loaders, cfg.workflow)
  File "E:\Anaconda\envs\mmlab\lib\site-packages\mmcv\runner\epoch_based_runner.py", line 130, in run
    epoch_runner(data_loaders[i], **kwargs)
  File "E:\Anaconda\envs\mmlab\lib\site-packages\mmcv\runner\epoch_based_runner.py", line 51, in train
    self.run_iter(data_batch, train_mode=True, **kwargs)
  File "E:\Anaconda\envs\mmlab\lib\site-packages\mmcv\runner\epoch_based_runner.py", line 30, in run_iter
    **kwargs)
  File "E:\Anaconda\envs\mmlab\lib\site-packages\mmcv\parallel\data_parallel.py", line 75, in train_step
    return self.module.train_step(*inputs[0], **kwargs[0])
  File "E:\Anaconda\envs\mmlab\lib\site-packages\mmseg\models\segmentors\base.py", line 138, in train_step
    losses = self(**data_batch)
  File "E:\Anaconda\envs\mmlab\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "E:\Anaconda\envs\mmlab\lib\site-packages\mmcv\runner\fp16_utils.py", line 116, in new_func
    return old_func(*args, **kwargs)
  File "D:\mmdetection3d-master\mmdet3d\models\segmentors\base.py", line 67, in forward
    return self.forward_train(**kwargs)
  File "D:\mmdetection3d-master\mmdet3d\models\segmentors\encoder_decoder.py", line 168, in forward_train
    pts_semantic_mask_cat)
  File "D:\mmdetection3d-master\mmdet3d\models\segmentors\encoder_decoder.py", line 98, in _decode_head_forward_train
    self.train_cfg)
  File "D:\mmdetection3d-master\mmdet3d\models\decode_heads\decode_head.py", line 87, in forward_train
    losses = self.losses(seg_logits, pts_semantic_mask)
  File "E:\Anaconda\envs\mmlab\lib\site-packages\mmcv\runner\fp16_utils.py", line 205, in new_func
    return old_func(*args, **kwargs)
  File "D:\mmdetection3d-master\mmdet3d\models\decode_heads\decode_head.py", line 122, in losses
    seg_logit, seg_label, ignore_index=self.ignore_index)
  File "E:\Anaconda\envs\mmlab\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "E:\Anaconda\envs\mmlab\lib\site-packages\mmseg\models\losses\cross_entropy_loss.py", line 280, in forward
    **kwargs)
  File "E:\Anaconda\envs\mmlab\lib\site-packages\mmseg\models\losses\cross_entropy_loss.py", line 50, in cross_entropy
    ignore_index=ignore_index)
  File "E:\Anaconda\envs\mmlab\lib\site-packages\torch\nn\functional.py", line 2468, in cross_entropy
    return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
  File "E:\Anaconda\envs\mmlab\lib\site-packages\torch\nn\functional.py", line 2292, in nll_loss
    input, target, weight, reduction_enum, ignore_index)
RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #2 'target' in call to _thnn_nll_loss2d_forward

Process finished with exit code 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!

@phoenix9668
Copy link

I have a similar problem
RuntimeError: expected scalar type Long but found Int
when I run
python tools\train.py configs\pointnet2\pointnet2_msg_16x2_cosine_80e_s3dis_seg-3d-13class.py

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

No branches or pull requests

4 participants