Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meaning of "counts" and "size" in "iscrowd: 1" segmentation #135

Closed
waspinator opened this issue Mar 14, 2018 · 4 comments
Closed

meaning of "counts" and "size" in "iscrowd: 1" segmentation #135

waspinator opened this issue Mar 14, 2018 · 4 comments

Comments

@waspinator
Copy link

waspinator commented Mar 14, 2018

These example were taken from instances_val2017.json

When "iscrowd": 0 segmentation looks like

"segmentation": [
    [
        289.74,
        443.39
    ],
    [
        289.74,
        443.39
    ]
]

but when "iscrowd: 1" then there are additional "counts" and "size" fields. What do they mean?

"segmentation": {
    "counts": [
        272,
        2,
        4,
        4
    ],
    "size": [
        240,
        320
    ]
}
@alwansm
Copy link

alwansm commented Mar 15, 2018

"iscrowd": 0 if your segmentation based on polygon (object instance)
"iscrowd": 1 if your segmentation based uncompressed RLE (crowd)
check: facebookresearch/Detectron#100

@waspinator
Copy link
Author

@alwansm Thanks, its as bit more clear now. I'm still confused on how I convert a compressed RLE to an uncompressed RLE version.

When I run

a = np.asfortranarray(np.zeros([5, 10])).astype(np.uint8)
mask.encode(a)

produces:

{'counts': b'b1', 'size': [5, 10]}

which is the encoded RLE instead of the list of something that coco expects.

@waspinator
Copy link
Author

def binary_mask_to_rle(binary_mask):
    rle = {'counts': [], 'size': list(binary_mask.shape)}
    counts = rle.get('counts')
    for i, (value, elements) in enumerate(groupby(binary_mask.ravel(order='F'))):
        if i == 0 and value == 1:
            counts.append(0)
        counts.append(len(list(elements)))
    return rle

@andics
Copy link

andics commented Jan 2, 2022

def binary_mask_to_rle(binary_mask):
    rle = {'counts': [], 'size': list(binary_mask.shape)}
    counts = rle.get('counts')
    for i, (value, elements) in enumerate(groupby(binary_mask.ravel(order='F'))):
        if i == 0 and value == 1:
            counts.append(0)
        counts.append(len(list(elements)))
    return rle

from itertools import groupby
Is missing from this code snippet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants