Detectron2: Error decoding masks when training Mask R-CNN

Created on 11 Feb 2020  路  5Comments  路  Source: facebookresearch/detectron2

Instructions To Reproduce the Issue:

  1. what changes you made (git diff) or what code you wrote
register_coco_instances("corn", {}, "annos.json", ".")

My annotation file looks like this:

"annotations": [
        {
            "id": 2159120,
            "image_id": 2159100,
            "category_id": 2159121,
            "segmentation": {
                "counts": [
                    492904,
                    18,
                    3015,
                    18,
                    .....],
                "size": [
                    3033,
                    2275
                  ]
            },
            "area": 0,
            "bbox": [
                162,
                1502,
                229,
                123
            ],
            "iscrowd": 0
       },
       .....
]
  1. what exact command you run:
    I use the same training code in the Getting Started notebook.
  2. what you observed (including the full logs):
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/detectron2/engine/train_loop.py", line 132, in train
    self.run_step()
  File "/usr/local/lib/python3.6/dist-packages/detectron2/engine/train_loop.py", line 208, in run_step
    data = next(self._data_loader_iter)
  File "/usr/local/lib/python3.6/dist-packages/detectron2/data/common.py", line 109, in __iter__
    for d in self.dataset:
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 345, in __next__
    data = self._next_data()
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 856, in _next_data
    return self._process_data(data)
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 881, in _process_data
    data.reraise()
  File "/usr/local/lib/python3.6/dist-packages/torch/_utils.py", line 394, in reraise
    raise self.exc_type(msg)
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.6/dist-packages/detectron2/data/common.py", line 39, in __getitem__
    data = self._map_func(self._dataset[cur_idx])
  File "/usr/local/lib/python3.6/dist-packages/detectron2/utils/serialize.py", line 23, in __call__
    return self._obj(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/detectron2/data/dataset_mapper.py", line 128, in __call__
    for obj in dataset_dict.pop("annotations")
  File "/usr/local/lib/python3.6/dist-packages/detectron2/data/dataset_mapper.py", line 129, in <listcomp>
    if obj.get("iscrowd", 0) == 0
  File "/usr/local/lib/python3.6/dist-packages/detectron2/data/detection_utils.py", line 180, in transform_instance_annotations
    mask = mask_util.decode(segm)
  File "/usr/local/lib/python3.6/dist-packages/pycocotools/mask.py", line 91, in decode
    return _mask.decode([rleObjs])[:,:,0]
  File "pycocotools/_mask.pyx", line 146, in pycocotools._mask.decode
  File "pycocotools/_mask.pyx", line 128, in pycocotools._mask._frString
TypeError: Expected bytes, got list

Expected behavior:

The annotations show up when using the visualizer, but there's the above error when training

Environment:


sys.platform linux
Python 3.6.9 (default, Nov 7 2019, 10:44:02) [GCC 8.3.0]
numpy 1.17.5
detectron2 0.1 @/usr/local/lib/python3.6/dist-packages/detectron2
detectron2 compiler GCC 7.3
detectron2 CUDA compiler 10.0
detectron2 arch flags sm_35, sm_37, sm_50, sm_52, sm_60, sm_61, sm_70, sm_75
DETECTRON2_ENV_MODULE
PyTorch 1.4.0+cu100 @/usr/local/lib/python3.6/dist-packages/torch
PyTorch debug build False
CUDA available True
GPU 0 Tesla P100-PCIE-16GB
CUDA_HOME /usr/local/cuda
NVCC Cuda compilation tools, release 10.0, V10.0.130
Pillow 6.2.2
torchvision 0.5.0+cu100 @/usr/local/lib/python3.6/dist-packages/torchvision
torchvision arch flags sm_35, sm_50, sm_60, sm_70, sm_75
cv2 4.1.2


PyTorch built with:

  • GCC 7.3
  • Intel(R) Math Kernel Library Version 2019.0.4 Product Build 20190411 for Intel(R) 64 architecture applications
  • Intel(R) MKL-DNN v0.21.1 (Git Hash 7d2fd500bc78936d1d648ca713b901012f470dbc)
  • OpenMP 201511 (a.k.a. OpenMP 4.5)
  • NNPACK is enabled
  • CUDA Runtime 10.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_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=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, USE_STATIC_DISPATCH=OFF,

Most helpful comment

Turns out what I have is uncompressed RLE format. To compress it:

pycocotools.mask.frPyObjects(rle, rle['size'][0], rle['size'][1])

where rle is the uncompressed RLE dict

All 5 comments

Please follow the documentation https://detectron2.readthedocs.io/tutorials/datasets.html and use

鈺扳攢$ pycocotools.mask.encode(np.asarray(mask.astype("uint8"), order="F"))                                  
Out[9]: {'size': [30, 30], 'counts': b'Tl0'}

to produce masks at the correct format.

@ppwwyyxx what is mask.astype("uint8") supposed to be? Is it the list of numbers in the counts attribute?

Have you seen my annotations yet? I am not trying to convert binary masks since I've already got RLE I think.

"segmentation": {
                "counts": [
                    492904,
                    18,
                    3015,
                    18,
                    .....],
                "size": [
                    3033,
                    2275
                  ]
            },

I just don't know how to convert this big list of numbers to the byte string that you got above.

what is mask.astype("uint8") supposed to be

mask is supposed to be the segmentation mask.

am not trying to convert binary masks since I've already got RLE I think.

Then you need to figure out how to convert "your RLE", whatever it means, into the RLE format pycocotools.mask.encode produces. This is not related to detectron2.

Turns out what I have is uncompressed RLE format. To compress it:

pycocotools.mask.frPyObjects(rle, rle['size'][0], rle['size'][1])

where rle is the uncompressed RLE dict

Was this page helpful?
0 / 5 - 0 ratings

Related issues

limsijie93 picture limsijie93  路  3Comments

guy4261 picture guy4261  路  4Comments

soumik12345 picture soumik12345  路  3Comments

choasup picture choasup  路  3Comments

ChungNPH picture ChungNPH  路  3Comments