open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.36k stars 9.42k forks source link

label = self.cat2label[name] KeyError: 'w', 'w' wasn't my class name #2906

Closed Ruolingdeng closed 4 years ago

Ruolingdeng commented 4 years ago

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 Recently when I trained the model, I met with the error: label = self.cat2label[name] KeyError: 'grain', 'grain' is my class name. I followed the solution of https://github.com/open-mmlab/mmdetection/issues/283 to modify CLASSES = ('.....') to CLASSES = ('grain',) in voc.py, and it can train successfully, but when I use the command of 'python tools/test.py configs/pascal_voc/faster_rcnn_r50_fpn_1x_voc0712.py /home/drl/workspace/mmdetection-1.1.0-for-grain/output/latest.pth --eval mAP' to see the mAP value, I met the error: label = self.cat2label[name] KeyError: 'w', I don't know how to do, please help me.

Reproduction

  1. What command or script did you run?
    python tools/test.py configs/pascal_voc/faster_rcnn_r50_fpn_1x_voc0712.py /home/drl/workspace/mmdetection-1.1.0-for-grain/output/latest.pth --eval mAP
  2. Did you make any modifications on the code or config? Did you understand what you have modified? Yes
  3. What dataset did you use?

Environment

  1. Please run python mmdet/utils/collect_env.py to collect necessary environment infomation and paste it here. sys.platform: linux Python: 3.6.10 |Anaconda, Inc.| (default, May 8 2020, 02:54:21) [GCC 7.3.0] CUDA available: True CUDA_HOME: /usr/local/cuda-9.0 NVCC: Cuda compilation tools, release 9.0, V9.0.176 GPU 0: GeForce GTX 1080 Ti GCC: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609 PyTorch: 1.1.0 PyTorch compiling details: PyTorch built with:
    • GCC 4.9
    • Intel(R) Math Kernel Library Version 2020.0.1 Product Build 20200208 for Intel(R) 64 architecture applications
    • Intel(R) MKL-DNN v0.18.1 (Git Hash 7de7e5d02bf687f971e7668963649728356e0c20)
    • OpenMP 201307 (a.k.a. OpenMP 4.0)
    • NNPACK is enabled
    • CUDA Runtime 9.0
    • NVCC architecture flags: -gencode;arch=compute_35,code=sm_35;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_50,code=compute_50
    • CuDNN 7.5.1
    • Magma 2.5.0
    • Build settings: BLAS=MKL, BUILD_TYPE=Release, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -fopenmp -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-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math, DISABLE_NUMA=1, PERF_WITH_AVX=1, PERF_WITH_AVX2=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=True, USE_NNPACK=True, USE_OPENMP=ON,

TorchVision: 0.3.0 OpenCV: 4.2.0 MMCV: 0.5.9 MMDetection: 1.1.0+unknown MMDetection Compiler: GCC 5.4 MMDetection CUDA Compiler: 9.0

  1. You may add addition that may be helpful for locating the problem, such as
    • How you installed PyTorch [e.g., pip, conda, source] conda install pytorch torchvision cudatoolkit=9.0 -c pytorch
    • Other environment variables that may be related (such as $PATH, $LD_LIBRARY_PATH, $PYTHONPATH, etc.) No

Error traceback

(mm) drl@drl-Precision:~/workspace/mmdetection-1.1.0-for-grain$ python tools/test.py configs/pascal_voc/faster_rcnn_r50_fpn_1x_voc0712.py /home/drl/workspace/mmdetection-1.1.0-for-grain/output/latest.pth --eval mAP
[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 160/160, 21.3 task/s, elapsed: 8s, ETA:     0sTraceback (most recent call last):
  File "tools/test.py", line 316, in <module>
    main()
  File "tools/test.py", line 312, in main
    dataset.evaluate(outputs, args.eval, **kwargs)
  File "/home/drl/workspace/mmdetection-1.1.0-for-grain/mmdet/datasets/voc.py", line 33, in evaluate
    annotations = [self.get_ann_info(i) for i in range(len(self))]
  File "/home/drl/workspace/mmdetection-1.1.0-for-grain/mmdet/datasets/voc.py", line 33, in <listcomp>
    annotations = [self.get_ann_info(i) for i in range(len(self))]
  File "/home/drl/workspace/mmdetection-1.1.0-for-grain/mmdet/datasets/xml_style.py", line 47, in get_ann_info
    label = self.cat2label[name]
KeyError: 'w'

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!

ZwwWayne commented 4 years ago

The solution is out-of-date. To use customized classes, you can refer to this tutorial

Ruolingdeng commented 4 years ago

@hellock @ZwwWayne I haven't solved my question, why did you close this issue? could you please help me how to solve it?

ZwwWayne commented 4 years ago

The solution is out-of-date. To use customized classes, you can refer to this tutorial