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

fix: Import multiple segmentations from coco format json #251

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/label_studio_sdk/converter/imports/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ def create_bbox(annotation, categories, from_name, image_height, image_width, to


def create_segmentation(
annotation, categories, from_name, image_height, image_width, to_name
category_id, segmentation, categories, from_name, image_height, image_width, to_name
makseq marked this conversation as resolved.
Show resolved Hide resolved
):
label = categories[int(annotation["category_id"])]
segmentation = annotation["segmentation"][0]
label = categories[int(category_id)]
points = [list(x) for x in zip(*[iter(segmentation)] * 2)]

for i in range(len(points)):
Expand Down Expand Up @@ -216,15 +215,17 @@ def convert_coco_to_ls(
task[out_type][0]["result"].append(item)

if "segmentation" in annotation and len(annotation["segmentation"]):
item = create_segmentation(
annotation,
categories,
segmentation_from_name,
image_height,
image_width,
to_name,
)
task[out_type][0]["result"].append(item)
for single_segmentation in annotation["segmentation"]:
makseq marked this conversation as resolved.
Show resolved Hide resolved
item = create_segmentation(
annotation["category_id"],
single_segmentation,
categories,
segmentation_from_name,
image_height,
image_width,
to_name,
)
task[out_type][0]["result"].append(item)

if "keypoints" in annotation:
items = create_keypoints(
Expand Down Expand Up @@ -270,7 +271,7 @@ def add_parser(subparsers):
"--input",
dest="input",
required=True,
help="directory with COCO where images, labels, notes.json are located",
help="input COCO json file",
makseq marked this conversation as resolved.
Show resolved Hide resolved
action=ExpandFullPath,
)
coco.add_argument(
Expand Down