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

labelme2coco.py bounding box problems #419

Closed
Darshan2701 opened this issue Jun 18, 2019 · 2 comments
Closed

labelme2coco.py bounding box problems #419

Darshan2701 opened this issue Jun 18, 2019 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@Darshan2701
Copy link

Darshan2701 commented Jun 18, 2019

Hi fellow researchers,
I have encountered a problem and need a bit of clarification and help. Kindly read the following..
Steps to try:

  1. Annotate the same objects (2 or more) in an image by using a rectangle (Not polygons)
  2. Save the file as json.
  3. Convert the existing json to coco format using the labelme2coco.py file.
  4. Compare the jsons.

I see that there is only one bbox field in the coco converted json though there are more than one bbox in the image. But the number of segmentations in the coco converted json matches with the non coco json file.

Is this an issue with the code? Or is this intended to be like this?
Kindly clarify.

@wkentaro
Copy link
Member

wkentaro commented Jun 19, 2019

Or is this intended to be like this?

Yes. Because current labelme2coco.py assumes the annotation is a segment instead of a bounding box.
The way of solving this is

  • create new labelme2coco_bbox.py
  • or
  • name different label to different bbox (e.g., person-1, person-2)

@JennyLouise
Copy link

I replaced lines 109 to 125 in the original labelme2coco.py file with the following, renaming labels to person-1, person-2, etc, before adding them to the coco annotations file.

        masks = {}                                     # for area
        segmentations = collections.defaultdict(list)  # for segmentation
        labels_indices = {}

        for shape in label_data['shapes']:
            points = shape['points']
            label = shape['label']
            shape_type = shape.get('shape_type', None)
            mask = labelme.utils.shape_to_mask(
                img.shape[:2], points, shape_type
            )

            if label in masks:
                labels_indices[label] += 1
                label=label+"-"+str(labels_indices[label])
                
            else:
                labels_indices[label]=0

            masks[label] = mask

@wkentaro wkentaro added the help wanted Extra attention is needed label Jul 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants