airctic / icevision

An Agnostic Computer Vision Framework - Pluggable to any Training Library: Fastai, Pytorch-Lightning with more to come
https://airctic.github.io/icevision/
Apache License 2.0
848 stars 150 forks source link

segmentation fault core dump when converting a single mask record with .to_mask #1098

Open rbavery opened 2 years ago

rbavery commented 2 years ago

🐛 Bug

I have the following record

{'common': {'width': 6443,
  'height': 4176,
  'record_id': 0,
  'filepath': Path('/root/data-cv2/Coincident/S1A_IW_GRDH_1SDV_20200729T034859_20200729T034924_033664_03E6D3_93EF/Background.png'),
  'img': None},
 'detection': {'areas': [3833, 2466, 17029],
  'bboxes': [<BBox (xmin:1025.0, ymin:5659.0, xmax:1298.0, ymax:6155.0)>,
   <BBox (xmin:2945.0, ymin:6249.0, xmax:3005.0, ymax:6376.0)>,
   <BBox (xmin:3655.0, ymin:1569.0, xmax:3827.0, ymax:2014.0)>],
  'labels': ['coincident_vessel', 'old_vessel', 'old_vessel'],
  'label_ids': [3, 5, 5],
  'iscrowds': [1, 1, 1],
  'masks': [<icevision.core.mask.RLE at 0x7fdd155ecb20>,
   <icevision.core.mask.RLE at 0x7fdd14dc2df0>,
   <icevision.core.mask.RLE at 0x7fdd14dc2eb0>],
  'mask_array': None}}

above is the record in dict form, before calling .as_dict it is this type <icevision.core.mask.RLE at 0x7fdd155ecb20>

then when I try to convert this to a mask, the kernel crashes

m.to_mask(train_records[0][0].as_dict()["common"]["height"], train_records[0][0].as_dict()["common"]["width"]).data

To Reproduce Steps to reproduce the behavior: I'm not certain but maybe this is due to the image size, 6443, 4176. and from looking at the to_mask func maybe there is some error in that func causing memory to blow up.

Expected behavior Return the mask. this works for 512x512 images. But I'd really like it to work for larger images so that I can use the same code for calculating statistics, etc. that expects a coco dictionary.

Desktop (please complete the following information):

rbavery commented 2 years ago

possibly related to https://github.com/cocodataset/cocoapi/issues/362

rbavery commented 2 years ago

I've tracked that this is an issue with pycocotools, which appears to be unmaintained. any help is much appreciated.

here's a reproducible example that causes a seg fault

from pycocotools import mask
erles = [{'size': [4176, 6443],
  'counts': b'\\UbU74QU70OO02N00001O002NN3O02NN30N3N11MO211NN201OO21OM1120NO100002N01M22N1ON40NN22MO220N0O12N00O11O02N0010O00N22L22N001O011L21M3ON3O11NO2O02NN22N02NN20O30MO220NN21O1N30M10N22N02NN22N01N12NN11O21OO0OO22N10M31N000O12L21M22N01OO1002ON10000002NN22NN30O2OM11O3OO001M22N10M130MO3N12L21M22N02NN22NN30M22N000002N00N31N10M1101O1O01O000O12N02MO3O02NO110O01O00N22NO1002ON11O02NN20O12OO0O111NN2002OM21M40L22NN22N02NO12OO1OO12N00N201O01O0020N0N22L22M12OO02NN2002NN2020ON12NN040N0N130OO1OO120L20N40M110N12N000000001OO21N00O12N02L03O010O1O002NN20002ON21M12NN20020M11gi[Zb0'}]
mask.decode(erles)
rbavery commented 2 years ago

this is also happening with 224, 224 masks. a work around is using the mask_array attribute instead

valid_ds[0].detection.mask_array[0].data works