Open petoor opened 4 years ago
hi, have you solved it? I have the same problem
Given the algorithm and some data you should be able to find the details.
I also needed this so I created the following solution. It's not the cleanest of solutions but gets the job done.
Clone the repo and add the function below to PythonAPI/pycocotools/_mask.pyx
.
def decompress(rleObjs):
cdef RLEs Rs = _frString(rleObjs)
rles, hs, ws = [], [], []
for i in range(Rs.n):
rles.append([Rs._R[i].cnts[j] for j in range(Rs._R[i].m)])
hs.append(Rs._R[i].h)
ws.append(Rs._R[i].w)
return rles, hs, ws
Uninstall current pycocotools package:
pip uninstall pycocotools
Compile and install:
cd PythonAPI
make install
See the example below for its use. I used the binary mask from https://github.com/facebookresearch/Detectron/issues/100#issuecomment-373458213
import pycocotools.mask as mask_util
import pycocotools._mask as _mask_util
import numpy as np
binary_mask = np.array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0], [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=np.uint8)
fortran_binary_mask = np.asfortranarray(binary_mask) compressed_rle = mask_util.encode(fortran_binary_mask) decompressed_rles, heights, widths = _mask_util.decompress([compressed_rle])
I had the same issue, but it was quite simple.
You can just use
pycocotools.mask.decode(ANNON)
to decode your model output in compressed RLE to binary mask.
Then you can easily encode it to uncompressed RLE.
Hi,
As the title says, is there a way to go from compressed RLE to uncompressed RLE?
Or is there a way to decode the byte string returned by the "count" to return the array of integer counts?
Best regards.