Skip to content

Commit 39eb62e

Browse files
KMYsqHRKtriklozoidmakseq
authored
feat: LEAP-1937: Add brush_to_coco format (#429)
Co-authored-by: Sergei Ivashchenko <[email protected]> Co-authored-by: Max Tkachenko <[email protected]>
1 parent 68d512f commit 39eb62e

File tree

6 files changed

+652
-9
lines changed

6 files changed

+652
-9
lines changed

poetry.lock

+36-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jsonschema = ">=4.23.0"
4646
lxml = ">=4.2.5"
4747
nltk = "^3.9.1"
4848
numpy = ">=1.26.4,<2.0.0"
49+
opencv-python = "^4.9.0" #add openCV
4950
pandas = ">=0.24.0"
5051
pydantic = ">= 1.9.2"
5152
pydantic-core = "^2.18.2"

src/label_studio_sdk/converter/converter.py

+21
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Format(Enum):
5959
YOLO_WITH_IMAGES = 14
6060
COCO_WITH_IMAGES = 15
6161
YOLO_OBB_WITH_IMAGES = 16
62+
BRUSH_TO_COCO = 17
6263

6364
def __str__(self):
6465
return self.name
@@ -167,6 +168,12 @@ class Converter(object):
167168
"format expected by NVIDIA NeMo models.",
168169
"link": "https://labelstud.io/guide/export.html#ASR-MANIFEST",
169170
"tags": ["speech recognition"],
171+
},
172+
Format.BRUSH_TO_COCO: {
173+
"title": "Brush labels to COCO",
174+
"description": "Export your brush labels as COCO format for segmentation tasks. Converts RLE encoded masks to COCO polygons.",
175+
"link": "https://labelstud.io/guide/export.html#COCO",
176+
"tags": ["image segmentation", "brush annotations"],
170177
},
171178
}
172179

@@ -293,6 +300,19 @@ def convert(self, input_data, output_data, format, is_dir=True, **kwargs):
293300
upload_dir=self.upload_dir,
294301
download_resources=self.download_resources,
295302
)
303+
elif format == Format.BRUSH_TO_COCO:
304+
items = (
305+
self.iter_from_dir(input_data)
306+
if is_dir
307+
else self.iter_from_json_file(input_data)
308+
)
309+
from label_studio_sdk.converter.exports.brush_to_coco import convert_to_coco
310+
image_dir = kwargs.get("image_dir")
311+
convert_to_coco(
312+
items,
313+
output_data,
314+
output_image_dir=image_dir
315+
)
296316

297317
def _get_data_keys_and_output_tags(self, output_tags=None):
298318
data_keys = set()
@@ -376,6 +396,7 @@ def _get_supported_formats(self):
376396
):
377397
all_formats.remove(Format.BRUSH_TO_NUMPY.name)
378398
all_formats.remove(Format.BRUSH_TO_PNG.name)
399+
all_formats.remove(Format.BRUSH_TO_COCO.name)
379400
if not (
380401
("Audio" in input_tag_types or "AudioPlus" in input_tag_types)
381402
and "TextArea" in output_tag_types

0 commit comments

Comments
 (0)