Commit
·
ad612da
1
Parent(s):
68274dc
Update coco.py
Browse filesadd 'skip' configurations
coco.py
CHANGED
@@ -565,13 +565,14 @@ PANOPTIC_FEATURE = datasets.Features(
|
|
565 |
class CocoConfig(datasets.BuilderConfig):
|
566 |
"""BuilderConfig for CocoConfig."""
|
567 |
|
568 |
-
def __init__(self, features, splits=None, has_panoptic=False, **kwargs):
|
569 |
super(CocoConfig, self).__init__(
|
570 |
**kwargs
|
571 |
)
|
572 |
self.features = features
|
573 |
self.splits = splits
|
574 |
self.has_panoptic = has_panoptic
|
|
|
575 |
|
576 |
|
577 |
# Copied from https://github.com/tensorflow/datasets/blob/master/tensorflow_datasets/object_detection/coco.py
|
@@ -659,6 +660,55 @@ class Coco(datasets.GeneratorBasedBuilder):
|
|
659 |
),
|
660 |
],
|
661 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
662 |
]
|
663 |
|
664 |
DEFAULT_CONFIG_NAME = "2017"
|
@@ -753,6 +803,8 @@ class Coco(datasets.GeneratorBasedBuilder):
|
|
753 |
elif annotation_type == AnnotationType.NONE: # No annotation for test sets
|
754 |
instance_filename = 'image_info_{}.json'
|
755 |
|
|
|
|
|
756 |
# Load the annotations (label names, images metadata,...)
|
757 |
instance_path = os.path.join(
|
758 |
annotation_dir,
|
@@ -760,13 +812,6 @@ class Coco(datasets.GeneratorBasedBuilder):
|
|
760 |
instance_filename.format(split_name),
|
761 |
)
|
762 |
coco_annotation = ANNOTATION_CLS[annotation_type](instance_path)
|
763 |
-
# Each category is a dict:
|
764 |
-
# {
|
765 |
-
# 'id': 51, # From 1-91, some entry missing
|
766 |
-
# 'name': 'bowl',
|
767 |
-
# 'supercategory': 'kitchen',
|
768 |
-
# }
|
769 |
-
categories = coco_annotation.categories
|
770 |
# Each image is a dict:
|
771 |
# {
|
772 |
# 'id': 262145,
|
@@ -835,6 +880,8 @@ class Coco(datasets.GeneratorBasedBuilder):
|
|
835 |
|
836 |
if not instances:
|
837 |
annotation_skipped += 1
|
|
|
|
|
838 |
|
839 |
def build_bbox(x, y, width, height):
|
840 |
# pylint: disable=cell-var-from-loop
|
|
|
565 |
class CocoConfig(datasets.BuilderConfig):
|
566 |
"""BuilderConfig for CocoConfig."""
|
567 |
|
568 |
+
def __init__(self, features, splits=None, has_panoptic=False, skip_empty_annotations=False, **kwargs):
|
569 |
super(CocoConfig, self).__init__(
|
570 |
**kwargs
|
571 |
)
|
572 |
self.features = features
|
573 |
self.splits = splits
|
574 |
self.has_panoptic = has_panoptic
|
575 |
+
self.skip_empty_annotations = skip_empty_annotations
|
576 |
|
577 |
|
578 |
# Copied from https://github.com/tensorflow/datasets/blob/master/tensorflow_datasets/object_detection/coco.py
|
|
|
660 |
),
|
661 |
],
|
662 |
),
|
663 |
+
CocoConfig(
|
664 |
+
name='2017_skip',
|
665 |
+
features=DETECTION_FEATURE,
|
666 |
+
description=_CONFIG_DESCRIPTION.format(year=2017),
|
667 |
+
version=_VERSION,
|
668 |
+
skip_empty_annotations=True,
|
669 |
+
splits=[
|
670 |
+
Split(
|
671 |
+
name=datasets.Split.TRAIN,
|
672 |
+
images='train2017',
|
673 |
+
annotations='annotations_trainval2017',
|
674 |
+
annotation_type=AnnotationType.BBOXES,
|
675 |
+
),
|
676 |
+
Split(
|
677 |
+
name=datasets.Split.VALIDATION,
|
678 |
+
images='val2017',
|
679 |
+
annotations='annotations_trainval2017',
|
680 |
+
annotation_type=AnnotationType.BBOXES,
|
681 |
+
),
|
682 |
+
Split(
|
683 |
+
name=datasets.Split.TEST,
|
684 |
+
images='test2017',
|
685 |
+
annotations='image_info_test2017',
|
686 |
+
annotation_type=AnnotationType.NONE,
|
687 |
+
),
|
688 |
+
],
|
689 |
+
),
|
690 |
+
CocoConfig(
|
691 |
+
name='2017_panoptic_skip',
|
692 |
+
features=PANOPTIC_FEATURE,
|
693 |
+
description=_CONFIG_DESCRIPTION.format(year=2017),
|
694 |
+
version=_VERSION,
|
695 |
+
has_panoptic=True,
|
696 |
+
skip_empty_annotations=True,
|
697 |
+
splits=[
|
698 |
+
Split(
|
699 |
+
name=datasets.Split.TRAIN,
|
700 |
+
images='train2017',
|
701 |
+
annotations='panoptic_annotations_trainval2017',
|
702 |
+
annotation_type=AnnotationType.PANOPTIC,
|
703 |
+
),
|
704 |
+
Split(
|
705 |
+
name=datasets.Split.VALIDATION,
|
706 |
+
images='val2017',
|
707 |
+
annotations='panoptic_annotations_trainval2017',
|
708 |
+
annotation_type=AnnotationType.PANOPTIC,
|
709 |
+
),
|
710 |
+
],
|
711 |
+
),
|
712 |
]
|
713 |
|
714 |
DEFAULT_CONFIG_NAME = "2017"
|
|
|
803 |
elif annotation_type == AnnotationType.NONE: # No annotation for test sets
|
804 |
instance_filename = 'image_info_{}.json'
|
805 |
|
806 |
+
skip_empty_annotations = self.config.skip_empty_annotations
|
807 |
+
|
808 |
# Load the annotations (label names, images metadata,...)
|
809 |
instance_path = os.path.join(
|
810 |
annotation_dir,
|
|
|
812 |
instance_filename.format(split_name),
|
813 |
)
|
814 |
coco_annotation = ANNOTATION_CLS[annotation_type](instance_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
815 |
# Each image is a dict:
|
816 |
# {
|
817 |
# 'id': 262145,
|
|
|
880 |
|
881 |
if not instances:
|
882 |
annotation_skipped += 1
|
883 |
+
if skip_empty_annotations:
|
884 |
+
continue
|
885 |
|
886 |
def build_bbox(x, y, width, height):
|
887 |
# pylint: disable=cell-var-from-loop
|