SysCV / shift-dev

SHIFT Dataset DevKit - CVPR2022
https://www.vis.xyz/shift
MIT License
101 stars 10 forks source link

RLE to mask #21

Closed leandro-svg closed 1 year ago

leandro-svg commented 1 year ago

Dear authors, Thank you for your work.

Would you mind explain to me how would we go from the RLE bitmask 'counts' to a binary mask in the instance segmentation labels ? The RLE shouldn't be a list of integers ?

FYI, I have used this following piece of code to go from RLE to binary mask : def rleToMask(img, rleString,height,width): rows,cols = height,width rleNumbers = [int(numstring) for numstring in rleString.split(' ')] rlePairs = np.array(rleNumbers).reshape(-1,2) for index,length in rlePairs: index -= 1 img[index:index+length] = 255 img = img.reshape(cols,rows) img = img.T return img

The returned error is the following :

ValueError: invalid literal for int() with base 10: 'fg_08hh0000O10J6N20000000O102M:GO10nZ22PeM00O100MWOFh0:WOFh0:WOF`h0:300000000000000000001O001O001O010O00001O00000002OO0000000O101O00001O3MTcX='

I have also tried the _mask.decode function from pycocotools but it returns me a zeros-bitmask :

def decode(rleObjs): if type(rleObjs) == list: return _mask.decode(rleObjs) else: return _mask.decode([rleObjs])[:,:,0] mask = (mask_utils.decode(dict(rle)) > 0).astype( np.uint8, copy=False )

Looking forward to hear from you soon.

suniique commented 1 year ago

Hey @leandro-svg, thanks for the question!

We recommend using Scalabel's utilities function to convert RLE to bit masks. You could find an example used in code below: https://github.com/SysCV/shift-dev/blob/c54c1b0746ebb485779177fd7932bb0325f79bdf/shift_dev/vis/utils.py#L480

leandro-svg commented 1 year ago

Ok, I indeed didn't see those codes. Thank you!