-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
how object segmentation are written in dataset json files? #111
Comments
Just convert your own polygon representation to a binary mask (one per polygon) and then convert the mask to the COCO polygon format. E.g. the following script converts .png files (with non-overlapping polygons) https://github.com/nightrome/cocoapi/blob/master/PythonAPI/cocostuff/pngToCocoResultDemo.py |
@nightrome : I am using my own dataset and I have annotated the images. My groundtruth is an image of same size and for every pixel I have a number which is the class ID. Like for Person class my ground truth image has pixel colour (1,1,1) same as COCO dataset. My question is if there are two person in an image should both be annotated with colour (1,1,1) or is there a different rule? Any help would be really appreciated as I am not able to find this information anywhere. Thank you. |
That doesn't work. You cannot write instances (e.g. two persons) into an image and preserve that information. Take a look at the json format and then write your own script to create it: http://cocodataset.org/#download |
@nightrome
Then my question is how did they get this from pixel-wise annotated image? Because if you assign different colour like (1,1,1) (2,2,2) (3,3,3) for different person in the image then in json format how do we reach to same category_id? And I need this as I want to use some categories of MS COCO dataset and add few of my own for my own dataset. So I want to have same annotation format. |
The trick is to convert one object instance at a time from your format into a binary map and then into COCO polygon format. Also note that you don't need to make up an encoding into 3 rgb channels. You can just write images with a single channel. |
@nightrome how to convert polygons into binary mask? |
@priyanka-chaudhary
|
@dexter1608 : I am trying to do that from masks. Not figured out yet. |
@nightrome : You mentioned As when I passed binary mask to
|
Looks good to me! From the COCO page:
The RLE encoded polygons can be used (more or less) interchangeably with the more readable type of polygon annotation above. |
@nightrome : So can I use this above result to append to the |
Yes, we do that for the COCO-Stuff annotations, but don't forget the other fields (area, iscrowd, bbox, id). |
@nightrome : Yes I got the area, bbox from |
AFAIK crowd sourced annotations have a big id and regular annotations a small id. But it should not matter as long as there are no duplicates. |
@nightrome : Any way to find out till where the ids are used or any documentation of it? as they are quite huge files not sure how to find that information. I am not using crowd sourced annotations |
Generally speaking the search function is your friend. The codebase is not really big. I think it is only used as a unique index. |
@nightrome |
@nightrome : Thank you for the support. I found a way to do it. |
@dexter1608
|
@priyanka-chaudhary How did you get the area, bbox from mask.py? |
@raninbowlalala : There are functions defined already in mask.py to get bbox and area from segmentation. From here |
@priyanka-chaudhary Thank you very much. A further question, how did you generate the id? Which number should be selected to be the first number? |
@raninbowlalala : I extracted all the ids from train and validation files and sorted them. The highest value I found for |
@priyanka-chaudhary Thanks for your help! |
@nightrome I used COCO-Stuff annotations to convert my own dataset to coco format, and added "area","bbox","id" to json file. When I finetuning the End-to-End_X-101-64x4d-FPN.pkl on my own dataset, I got the error like below: At: It seems like the segmentation format is polygons, but my dataset used RLE format. Do you have this problem? |
Sorry, but I am not familiar with that code. I suggest you contact the authors or look at how they parse the .json file. Or you save it as raw polygons instead of RLE format polygons. |
@nightrome OK, thanks for your help. |
@nightrome Do you know how to convert mask binary image to raw polygons? Or convert RLE format to polygons format? Thanks a lot. |
Unfotunately not, I have never worked with polygons :-( |
I found an issue and helped me convert mask binary image to polygon format. Hope this answer will help others people. |
@priyanka-chaudhary I got the same output just like you after run |
@lscelory: The segmentationToCocoMask function is not part of this repository, but actually of the COCO-Stuff repository. Could you repost your question there with more information on what you are trying to achieve? I am losing track of the conversation here. |
@lscelory : You can use it directly. You don't need to convert it to polygon format. Atleast I used it like that only. So I am not aware of any method to convert it to polygon format. |
@nightrome do you know where I can find details on COCO's
, or how to convert a mask to an uncompressed RLE representation that COCO would work with? I need it to create |
@waspinator: Not sure why you would create an uncompressed RLE. For compressed RLE have a look at the COCO-Stuff repository. If you have any more questions please open a ticket there. |
@nightrome for example when you download
|
@waspinator: I am not sure how to write them, but they can definitely be read using the standard mask API. So imho there is no reason to store your annotations uncompressed. Just take whatever you have and compress it. Try to play around with these functions, that's all we have from Python. |
@nightrome and @dexter1608 How to convert my own polygon representation to a binary mask? or Segmentation format? Thanks! |
I wrote a library and article to help with creating COCO style datasets. |
Hello everyone Thanks in advance |
@vsd550 did you try the reading the link above you? It doesn't work for your exact use case, but you should be able to write a converter for your format using it as a guide. For example you could use http://scikit-image.org/docs/dev/api/skimage.draw.html#skimage.draw.polygon to convert your polygons to masks, and then use pycococreator as-is to generate the coco-style dataset. |
https://github.com/nightrome/cocoapi/blob/master/PythonAPI/pycocotools/cocostuffhelper.py#L19 |
@waspinator thanks for the answer. After I generate the binary mask I am using the function
This function creates a binary mask given a polygon coordinates, one at a time. |
What is the type of your input polygons? |
@nightrome @waspinator hey guys , i am having a strange issue i.e i get mask mAP as 0 and bounding box mAP correct values . Here is the step i have performed
|
Thanks a lot @waspinator !!! It helped me in annotation separation for crowded and non-crowded regions as well as clean decoding of masked data. |
A mask from png image's last(alpha) channel is a soft mask, which has good quality in edges and I think this is good for training. |
Hi Guys, so I am wanting to do instance segmentation and the model that I am using expects the data to be in COCO 2017 format. When looking at the COCO 2017 json files for segmentation, I have noticed that the segmentations in the json file are written as bounding box coordinates and not polygon coordinates. I was expecting polygon coordinates that would match up to points that create the bitmap images. I guess the mask images are enough information, coupled with the bounding box that encompasses the mask, for the model to understand what is going on ? |
How to convert the masks to polygon format? @nightrome @ priyanka-chaudhary |
|
hi,
I have polygons made using labelme annotation tool
which are written like this
points": [
[
258.69565217391306,
346.0869565217391
],
[
252.60869565217394,
345.21739130434776
],
[
245.6521739130435,
340.0
],
[
243.04347826086956,
337.3913043478261
],
[
239.56521739130437,
336.52173913043475
],
[
232.60869565217394,
332.17391304347825
],
[
231.73913043478262,
332.17391304347825
],
[
222.17391304347825,
328.695652173913
],
[
216.08695652173913,
320.86956521739125
],
[
209.1304347826087,
319.13043478260863
],
[
205.6521739130435,
318.2608695652174
],
[
197.82608695652175,
315.6521739130435
],
[
185.6521739130435,
315.6521739130435
],
[
162.17391304347825,
308.695652173913
]]
and in coco 2014 dataset the segmentations are written like this
{"segmentation": [[239.97,260.24,222.04,270.49,199.84,253.41,213.5,227.79,259.62,200.46,274.13,202.17,277.55,210.71,249.37,253.41,237.41,264.51,242.54,261.95,228.87,271.34]]
i dont know the difference how can I convert my polygons into coco type segmentation
thankyou in advance
The text was updated successfully, but these errors were encountered: