From 1900940fa1173eea75780d745aebfe00be8dd7c2 Mon Sep 17 00:00:00 2001 From: Akkiy3314 Date: Wed, 12 Apr 2023 15:57:20 +0900 Subject: [PATCH 1/6] add mothod export segmentation --- fastlabel/__init__.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/fastlabel/__init__.py b/fastlabel/__init__.py index b2927b3..1b4a541 100644 --- a/fastlabel/__init__.py +++ b/fastlabel/__init__.py @@ -2484,6 +2484,8 @@ def export_semantic_segmentation( tasks: list, output_dir: str = os.path.join("output", "semantic_segmentation"), pallete: List[int] = const.COLOR_PALETTE, + classes: List = [], + start_index: int = 1, ) -> None: """ Convert tasks to index color semantic segmentation (PNG files). @@ -2493,13 +2495,16 @@ def export_semantic_segmentation( tasks is a list of tasks (Required). output_dir is output directory(default: output/semantic_segmentation)(Optional). pallete is color palette of index color. Ex: [255, 0, 0, ...] (Optional). + classes is fix classes list (Optional). + start_index is color pallet start index (Optional). """ - classes = [] - for task in tasks: - for annotation in task["annotations"]: - classes.append(annotation["value"]) - classes = list(set(classes)) - classes.sort() + target_classes = classes + if len(target_classes) == 0: + for task in tasks: + for annotation in task["annotations"]: + target_classes.append(annotation["value"]) + target_classes = list(set(classes)) + target_classes.sort() tasks = converters.to_pixel_coordinates(tasks) for task in tasks: @@ -2508,7 +2513,8 @@ def export_semantic_segmentation( output_dir=output_dir, pallete=pallete, is_instance_segmentation=False, - classes=classes, + classes=target_classes, + start_index=start_index, ) def __export_index_color_image( @@ -2518,12 +2524,13 @@ def __export_index_color_image( pallete: List[int], is_instance_segmentation: bool = True, classes: list = [], + start_index: int = 1, ) -> None: image = Image.new("RGB", (task["width"], task["height"]), 0) image = np.array(image) image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) - index = 1 + index = start_index # In case segmentation, to avoid hollowed points overwrite other segmentation # in them, segmentation rendering process is different from # other annotation type From 3c6f0f264de4713e28eba0620cd0b25b423147c2 Mon Sep 17 00:00:00 2001 From: Akkiy3314 Date: Fri, 14 Apr 2023 13:41:40 +0900 Subject: [PATCH 2/6] fix review --- fastlabel/__init__.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/fastlabel/__init__.py b/fastlabel/__init__.py index 1b4a541..4cc6e5f 100644 --- a/fastlabel/__init__.py +++ b/fastlabel/__init__.py @@ -2459,6 +2459,8 @@ def export_instance_segmentation( tasks: list, output_dir: str = os.path.join("output", "instance_segmentation"), pallete: List[int] = const.COLOR_PALETTE, + classes: List = [], + start_index: int = 1, ) -> None: """ Convert tasks to index color instance segmentation (PNG files). @@ -2469,6 +2471,9 @@ def export_instance_segmentation( tasks is a list of tasks (Required). output_dir is output directory(default: output/instance_segmentation)(Optional). pallete is color palette of index color. Ex: [255, 0, 0, ...] (Optional). + classes is a list of annotation values. + This list defines the value order that corresponds to the color index of the annotation.(Optional). + start_index is the first index of color index corresponding to color pallete (Optional). """ tasks = converters.to_pixel_coordinates(tasks) for task in tasks: @@ -2477,6 +2482,8 @@ def export_instance_segmentation( output_dir=output_dir, pallete=pallete, is_instance_segmentation=True, + classes=classes, + start_index=start_index, ) def export_semantic_segmentation( @@ -2495,16 +2502,16 @@ def export_semantic_segmentation( tasks is a list of tasks (Required). output_dir is output directory(default: output/semantic_segmentation)(Optional). pallete is color palette of index color. Ex: [255, 0, 0, ...] (Optional). - classes is fix classes list (Optional). - start_index is color pallet start index (Optional). + classes is a list of annotation values. + This list defines the value order that corresponds to the color index of the annotation.(Optional). + start_index is the first index of color index corresponding to color pallete (Optional). """ - target_classes = classes - if len(target_classes) == 0: + if len(classes) == 0: for task in tasks: for annotation in task["annotations"]: - target_classes.append(annotation["value"]) - target_classes = list(set(classes)) - target_classes.sort() + classes.append(annotation["value"]) + classes = list(set(classes)) + classes.sort() tasks = converters.to_pixel_coordinates(tasks) for task in tasks: @@ -2513,7 +2520,7 @@ def export_semantic_segmentation( output_dir=output_dir, pallete=pallete, is_instance_segmentation=False, - classes=target_classes, + classes=classes, start_index=start_index, ) From cc6a96d3cab756f3bd44dd9bb76725dbbd8c36ff Mon Sep 17 00:00:00 2001 From: Akkiy3314 Date: Fri, 14 Apr 2023 17:15:24 +0900 Subject: [PATCH 3/6] fix review 2 --- fastlabel/__init__.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fastlabel/__init__.py b/fastlabel/__init__.py index 4cc6e5f..c304f9d 100644 --- a/fastlabel/__init__.py +++ b/fastlabel/__init__.py @@ -2459,7 +2459,6 @@ def export_instance_segmentation( tasks: list, output_dir: str = os.path.join("output", "instance_segmentation"), pallete: List[int] = const.COLOR_PALETTE, - classes: List = [], start_index: int = 1, ) -> None: """ @@ -2471,8 +2470,6 @@ def export_instance_segmentation( tasks is a list of tasks (Required). output_dir is output directory(default: output/instance_segmentation)(Optional). pallete is color palette of index color. Ex: [255, 0, 0, ...] (Optional). - classes is a list of annotation values. - This list defines the value order that corresponds to the color index of the annotation.(Optional). start_index is the first index of color index corresponding to color pallete (Optional). """ tasks = converters.to_pixel_coordinates(tasks) @@ -2482,7 +2479,6 @@ def export_instance_segmentation( output_dir=output_dir, pallete=pallete, is_instance_segmentation=True, - classes=classes, start_index=start_index, ) From 2fa79b905f10ed7ddf80af3d6c197e82a46ace5d Mon Sep 17 00:00:00 2001 From: Akkiy3314 Date: Tue, 18 Apr 2023 18:57:15 +0900 Subject: [PATCH 4/6] fix classes start index --- fastlabel/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastlabel/__init__.py b/fastlabel/__init__.py index c304f9d..8e25628 100644 --- a/fastlabel/__init__.py +++ b/fastlabel/__init__.py @@ -2542,7 +2542,7 @@ def __export_index_color_image( color = ( index if is_instance_segmentation - else classes.index(annotation["value"]) + 1 + else classes.index(annotation["value"]) + start_index ) if annotation["type"] == AnnotationType.segmentation.value: # Create each annotation's masks and merge them finally From 56961c2b113f5cbb60935834ea9a08e9fdd0f039 Mon Sep 17 00:00:00 2001 From: Akkiy3314 Date: Tue, 18 Apr 2023 19:48:23 +0900 Subject: [PATCH 5/6] comment fix --- fastlabel/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fastlabel/__init__.py b/fastlabel/__init__.py index 8e25628..0c004bc 100644 --- a/fastlabel/__init__.py +++ b/fastlabel/__init__.py @@ -2470,7 +2470,9 @@ def export_instance_segmentation( tasks is a list of tasks (Required). output_dir is output directory(default: output/instance_segmentation)(Optional). pallete is color palette of index color. Ex: [255, 0, 0, ...] (Optional). - start_index is the first index of color index corresponding to color pallete (Optional). + start_index is the first index of color index corresponding to color pallete. + When start_index is 0, all pixels are assumed to have annotations + because they become the same color as the background(Optional). """ tasks = converters.to_pixel_coordinates(tasks) for task in tasks: @@ -2500,7 +2502,9 @@ def export_semantic_segmentation( pallete is color palette of index color. Ex: [255, 0, 0, ...] (Optional). classes is a list of annotation values. This list defines the value order that corresponds to the color index of the annotation.(Optional). - start_index is the first index of color index corresponding to color pallete (Optional). + start_index is the first index of color index corresponding to color pallete. + When start_index is 0, all pixels are assumed to have annotations + because they become the same color as the background(Optional). """ if len(classes) == 0: for task in tasks: From d435e4598ca7ee423586b6fa32d50e312e78d52c Mon Sep 17 00:00:00 2001 From: Akkiy3314 Date: Tue, 18 Apr 2023 19:50:17 +0900 Subject: [PATCH 6/6] comment fix --- fastlabel/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fastlabel/__init__.py b/fastlabel/__init__.py index 0c004bc..cbf3d90 100644 --- a/fastlabel/__init__.py +++ b/fastlabel/__init__.py @@ -2471,6 +2471,7 @@ def export_instance_segmentation( output_dir is output directory(default: output/instance_segmentation)(Optional). pallete is color palette of index color. Ex: [255, 0, 0, ...] (Optional). start_index is the first index of color index corresponding to color pallete. + The expected values for start_index are either 0 or 1. When start_index is 0, all pixels are assumed to have annotations because they become the same color as the background(Optional). """ @@ -2503,6 +2504,7 @@ def export_semantic_segmentation( classes is a list of annotation values. This list defines the value order that corresponds to the color index of the annotation.(Optional). start_index is the first index of color index corresponding to color pallete. + The expected values for start_index are either 0 or 1. When start_index is 0, all pixels are assumed to have annotations because they become the same color as the background(Optional). """