open-mmlab / mmdetection

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

FilterAnnotations does not work properly with PolygonMasks #8131

Closed MiXaiLL76 closed 2 years ago

MiXaiLL76 commented 2 years ago

Checklist

  1. [x] I have searched related issues but cannot get the expected [DONE] (Didn't see similar bug reports)
  2. [x] I have read the FAQ documentation but cannot get the expected help. [DONE]
  3. [x] The bug has not been fixed in the latest version. [DONE] (bug not fixed)

Describe

When working with datasets in PolygonMasks mode, indexes are transferred incorrectly.

Reproduction

  1. What command or script did you run?

Dataset loader pipeline and use poly2mask=False

 [{'type': 'LoadImageFromFile'},
  {'type': 'LoadAnnotations',
   'with_bbox': True,
   'with_mask': True,
   'poly2mask': False},
  {'type': 'FilterAnnotations', 'min_gt_bbox_wh': (5, 5)},
  {'type': 'Collect',
   'keys': ['img', 'gt_bboxes', 'gt_labels', 'gt_masks'],
   'meta_keys': ('filename', 'img_shape')}]
  1. Did you make any modifications on the code or config? Did you understand what you have modified?

    I didn't modify anything

  2. What dataset did you use?

    Custom dataset in coco format.
    I will attach a simple code to test

Environment

  1. Please run python mmdet/utils/collect_env.py to collect necessary environment information and paste it here.

/bin/sh: 1: /usr/local/cuda/bin/nvcc: not found
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
sys.platform: linux
Python: 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
CUDA available: True
GPU 0: NVIDIA GeForce RTX 3080 Ti
CUDA_HOME: /usr/local/cuda
NVCC: Not Available
GCC: x86_64-linux-gnu-gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
PyTorch: 1.10.0+cu113
PyTorch compiling details: PyTorch built with:
  - GCC 7.3
  - C++ Version: 201402
  - Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191122 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.2.3 (Git Hash 7336ca9f055cf1bfa13efb658fe15dc9b41f0740)
  - 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.2
  - Magma 2.5.2
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.3, CUDNN_VERSION=8.2.0, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -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-sign-compare -Wno-unused-parameter -Wno-unused-variable -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 -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.10.0, USE_CUDA=ON, USE_CUDNN=ON, 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, 

TorchVision: 0.11.1+cu113
OpenCV: 4.5.5
MMCV: 1.5.2
MMCV Compiler: GCC 7.3
MMCV CUDA Compiler: 11.3
MMDetection: 2.25.0+
  1. You may add addition that may be helpful for locating the problem:
    I add dataset and bug example file

Error traceback

bug have not traceback

Why did the bug happen?

The PolygonMasks module does not support numpy binary arrays for selection.

Bug fix

I have already fixed this bug by adding a boolean mask conversion to indexes in the function.

You need to add the following code to line 627 in the file: https://github.com/open-mmlab/mmdetection/blob/ca11860f4f3c3ca2ce8340e2686eeaec05b29111/mmdet/datasets/pipelines/loading.py#L627

CODE:

keep = np.where(keep == True)[0]

PS...

There is still a small typo in the output of information about the function in line 410 of the file =)

https://github.com/open-mmlab/mmdetection/blob/ca11860f4f3c3ca2ce8340e2686eeaec05b29111/mmdet/datasets/pipelines/loading.py#L410

CODE to fix:

repr_str += f'file_client_args={self.file_client_args})'
MiXaiLL76 commented 2 years ago

error repeat code.zip

The code is presented in ZIP. there is an ipynb file to repeat the error. I also provide a pdf conversion of this file for a better preview. bug_report.pdf

chhluo commented 2 years ago

Hi, @MiXaiLL76 , I have read your bug_report and verified it's a bug, thanks. And could you please propose a pr to fix it?

MiXaiLL76 commented 2 years ago

@chhluo I haven’t made a pull request in global frameworks for a long time) Of course I will

chhluo commented 2 years ago

I think keep = keep.nonzero()[0] is better than keep = np.where(keep == True)[0], because the meaning of the former is more straightforward.

MiXaiLL76 commented 2 years ago

@chhluo I created a pull request with the changes you suggested (tested them, they work). Also corrected a typo in the output of the function description.


Should I close this issue?

chhluo commented 2 years ago

No, this issue will be closed automatically when the pr is merged.