-
Notifications
You must be signed in to change notification settings - Fork 2k
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
From binary masks with holes to COCO JSON format #574
Comments
Hello there, thank you for opening an Issue ! 🙏🏻 The team was notified and they will get back to you asap. |
It looks like this issue is a duplicate of #373. For this reason, I am closing this issue. If I misunderstood something, feel free to reopen the issue. |
Using the script general_json2yolo.py, you can convert the RLE mask with holes to the YOLO segmentation format. The RLE mask is converted to a parent polygon and a child polygon using
The RLE mask. The converted YOLO segmentation format. To run the script, put the COCO JSON file coco_train.json into Edit use_segments and use_keypoints in the script.
To convert the COCO bbox format to YOLO bbox format.
To convert the COCO segmentation format to YOLO segmentation format.
To convert the COCO keypoints format to YOLO keypoints format.
This script originates from Ultralytics JSON2YOLO repository. |
Search before asking
Description
The code does not seem to support masks with holes, feature that is quite important for instance segmentation (especially for food images datasets for example). By using the RLE format from COCO this would be attainable.
Use case
It will help improve the binary masks exportation to COCO JSON format, by relying on RLE encoding when needed, otherwise keeping the polygon format.
For example, if we take the binary mask of a specific class/category, from an image mask, we can find all possible contours in the class-mask (using RETR_TREE in openCV). If there is only 1 contour in the mask that is for sure 1 full polygon, therefore, we keep the polygon encoding. Otherwise, if it means that either there are multiple instances in the mask (multiple contours), either there are some holes in some of the instances (we can check the contour hierarchy for contours that are parents to others). In this case we can go from binary to uncompressed RLE, which will encode the possible holes in some instances. (for finding the area and bbox for this cases, it is needed to go from uncompressed RLE to compressed RLE first).
Additional
I built such an exporter here based on other sources, and I could contribute with a PR, if needed.
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: