Ejemplo n.º 1
0
    def test_can_create_from_iterable(self):
        class TestExtractor(Extractor):
            def __iter__(self):
                return iter([
                    DatasetItem(id=1,
                                subset='train',
                                annotations=[
                                    Bbox(1, 2, 3, 4, label=2),
                                    Label(4),
                                ]),
                    DatasetItem(id=1, subset='val', annotations=[
                        Label(3),
                    ]),
                ])

            def categories(self):
                return {
                    AnnotationType.label:
                    LabelCategories.from_iterable(['a', 'b', 'c', 'd', 'e'])
                }

        actual = Dataset.from_iterable([
            DatasetItem(id=1,
                        subset='train',
                        annotations=[
                            Bbox(1, 2, 3, 4, label=2),
                            Label(4),
                        ]),
            DatasetItem(id=1, subset='val', annotations=[
                Label(3),
            ]),
        ],
                                       categories=['a', 'b', 'c', 'd', 'e'])

        compare_datasets(self, TestExtractor(), actual)
    def test_can_save_and_load(self):
        source_dataset = Dataset.from_iterable([
            DatasetItem(id='1',
                image=np.ones((8, 8, 3)),
                annotations=[Label(0)]
            ),
            DatasetItem(id='2',
                image=np.ones((10, 10, 3)),
                annotations=[Label(1)]
            ),
            DatasetItem(id='3',
                image=np.ones((10, 10, 3)),
                annotations=[Label(0)]
            ),
            DatasetItem(id='4',
                image=np.ones((8, 8, 3)),
                annotations=[Label(2)]
            ),
        ], categories={
            AnnotationType.label: LabelCategories.from_iterable(
                'label_' + str(label) for label in range(3)),
        })

        with TestDir() as test_dir:
            ImagenetConverter.convert(source_dataset, test_dir, save_images=True)

            parsed_dataset = ImagenetImporter()(test_dir).make_dataset()

            compare_datasets(self, source_dataset, parsed_dataset,
                require_images=True)
    def test_can_save_and_load_with_multiple_labels(self):
        source_dataset = Dataset.from_iterable(
            [
                DatasetItem(id='1',
                            subset='train',
                            annotations=[Label(1),
                                         Label(2),
                                         Label(3)]),
                DatasetItem(
                    id='2',
                    subset='train',
                    image=np.zeros((2, 8, 3)),
                ),
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable('label_' + str(label)
                                              for label in range(10)),
            })

        with TestDir() as test_dir:
            ImagenetTxtConverter.convert(source_dataset,
                                         test_dir,
                                         save_images=True)

            parsed_dataset = Dataset.import_from(test_dir, 'imagenet_txt')

            compare_datasets(self,
                             source_dataset,
                             parsed_dataset,
                             require_images=True)
Ejemplo n.º 4
0
    def test_annotation_comparison(self):
        a = Dataset.from_iterable([
            DatasetItem(id=1, annotations=[
                Caption('hello'), # unmatched
                Caption('world', group=5),
                Label(2, attributes={ 'x': 1, 'y': '2', }),
                Bbox(1, 2, 3, 4, label=4, z_order=1, attributes={
                    'score': 1.0,
                }),
                Bbox(5, 6, 7, 8, group=5),
                Points([1, 2, 2, 0, 1, 1], label=0, z_order=4),
                Mask(label=3, z_order=2, image=np.ones((2, 3))),
            ]),
        ], categories=['a', 'b', 'c', 'd'])

        b = Dataset.from_iterable([
            DatasetItem(id=1, annotations=[
                Caption('world', group=5),
                Label(2, attributes={ 'x': 1, 'y': '2', }),
                Bbox(1, 2, 3, 4, label=4, z_order=1, attributes={
                    'score': 1.0,
                }),
                Bbox(5, 6, 7, 8, group=5),
                Bbox(5, 6, 7, 8, group=5), # unmatched
                Points([1, 2, 2, 0, 1, 1], label=0, z_order=4),
                Mask(label=3, z_order=2, image=np.ones((2, 3))),
            ]),
        ], categories=['a', 'b', 'c', 'd'])

        comp = ExactComparator()
        matched, unmatched, _, _, errors = comp.compare_datasets(a, b)

        self.assertEqual(6, len(matched), matched)
        self.assertEqual(2, len(unmatched), unmatched)
        self.assertEqual(0, len(errors), errors)
Ejemplo n.º 5
0
 def append_bbox_voc(annotations, **kwargs):
     annotations.append(
         Bbox(
             1,
             1,
             2,
             2,
             label=kwargs["label_id"],
             id=kwargs["ann_id"] + 1,
             attributes=kwargs["attributes"],
             group=kwargs["ann_id"],
         ))  # obj
     annotations.append(
         Label(kwargs["label_id"], attributes=kwargs["attributes"]))
     annotations.append(
         Bbox(
             1,
             1,
             2,
             2,
             label=kwargs["label_id"] + 3,
             group=kwargs["ann_id"],
         ))  # part
     annotations.append(
         Label(kwargs["label_id"] + 3, attributes=kwargs["attributes"]))
Ejemplo n.º 6
0
    def test_split_for_detection_gives_error(self):
        with self.subTest(msg="bbox annotation"):
            source = Dataset.from_iterable([
                DatasetItem(1, annotations=[Label(0), Label(1)]),
                DatasetItem(2, annotations=[Label(0), Label(2)]),
            ],
                                           categories=["a", "b", "c"])

            with self.assertRaisesRegex(Exception, "more than one bbox"):
                splits = [("train", 0.5), ("val", 0.2), ("test", 0.3)]
                actual = splitter.DetectionSplit(source, splits)
                len(actual.get_subset("train"))

        source, _ = self._generate_detection_dataset(
            append_bbox=self._get_append_bbox("cvat"),
            with_attr=True,
            nimages=5,
        )

        with self.subTest("wrong ratio"):
            with self.assertRaisesRegex(Exception, "in the range"):
                splits = [("train", -0.5), ("test", 1.5)]
                splitter.DetectionSplit(source, splits)

            with self.assertRaisesRegex(Exception, "Sum of ratios"):
                splits = [("train", 0.5), ("test", 0.5), ("val", 0.5)]
                splitter.DetectionSplit(source, splits)

        with self.subTest("wrong subset name"):
            with self.assertRaisesRegex(Exception, "Subset name"):
                splits = [("train_", 0.5), ("val", 0.2), ("test", 0.3)]
                splitter.DetectionSplit(source, splits)
Ejemplo n.º 7
0
 def __iter__(self):
     yield DatasetItem(id=1,
                       subset='train',
                       annotations=[
                           Label(3, attributes={'x': 1}),
                           Label(4, id=4),
                       ])
Ejemplo n.º 8
0
 def __iter__(self):
     return iter([
         DatasetItem(id=100,
                     subset='train',
                     image=np.ones((10, 6, 3)),
                     annotations=[
                         Caption('hello', id=1),
                         Caption('world', id=2, group=5),
                         Label(2, id=3, attributes={
                             'x': 1,
                             'y': '2',
                         }),
                         Bbox(1,
                              2,
                              3,
                              4,
                              label=4,
                              id=4,
                              z_order=1,
                              attributes={
                                  'score': 1.0,
                              }),
                         Bbox(5, 6, 7, 8, id=5, group=5),
                         Points([1, 2, 2, 0, 1, 1],
                                label=0,
                                id=5,
                                z_order=4),
                         Mask(label=3,
                              id=5,
                              z_order=2,
                              image=np.ones((2, 3))),
                     ]),
         DatasetItem(id=21,
                     subset='train',
                     annotations=[
                         Caption('test'),
                         Label(2),
                         Bbox(1, 2, 3, 4, 5, id=42, group=42)
                     ]),
         DatasetItem(id=2,
                     subset='val',
                     annotations=[
                         PolyLine([1, 2, 3, 4, 5, 6, 7, 8],
                                  id=11,
                                  z_order=1),
                         Polygon([1, 2, 3, 4, 5, 6, 7, 8],
                                 id=12,
                                 z_order=4),
                     ]),
         DatasetItem(id=42,
                     subset='test',
                     attributes={
                         'a1': 5,
                         'a2': '42'
                     }),
         DatasetItem(id=42),
         DatasetItem(id=43, image=Image(path='1/b/c.qq', size=(2, 4))),
     ])
Ejemplo n.º 9
0
 def __iter__(self):
     return iter([
         DatasetItem(id=1, annotations=[
             Label(2, id=1, group=1),
         ]),
         DatasetItem(id=2, annotations=[
             Label(3, id=2, group=2),
         ]),
     ])
Ejemplo n.º 10
0
 def __iter__(self):
     return iter([
         DatasetItem(id=0,
                     subset='s1',
                     image=np.zeros((5, 10, 3)),
                     annotations=[
                         Polygon([0, 0, 4, 0, 4, 4],
                                 label=1,
                                 group=4,
                                 attributes={'occluded': True}),
                         Points([1, 1, 3, 2, 2, 3],
                                label=2,
                                attributes={
                                    'occluded': False,
                                    'a1': 'x',
                                    'a2': 42
                                }),
                         Label(1),
                         Label(2, attributes={
                             'a1': 'y',
                             'a2': 44
                         }),
                     ],
                     attributes={'frame': 0}),
         DatasetItem(id=1,
                     subset='s1',
                     annotations=[
                         PolyLine([0, 0, 4, 0, 4, 4],
                                  label=3,
                                  group=4,
                                  attributes={'occluded': False}),
                         Bbox(5,
                              0,
                              1,
                              9,
                              label=3,
                              group=4,
                              attributes={'occluded': False}),
                     ],
                     attributes={'frame': 1}),
         DatasetItem(id=2,
                     subset='s2',
                     image=np.ones((5, 10, 3)),
                     annotations=[
                         Polygon([0, 0, 4, 0, 4, 4],
                                 z_order=1,
                                 label=3,
                                 group=4,
                                 attributes={'occluded': False}),
                     ],
                     attributes={'frame': 0}),
         DatasetItem(id=3,
                     subset='s3',
                     image=Image(path='3.jpg', size=(2, 4)),
                     attributes={'frame': 0}),
     ])
Ejemplo n.º 11
0
 def __iter__(self):
     return iter([
         DatasetItem(id=0),
         DatasetItem(id=1, annotations=[
             Label(0),
         ]),
         DatasetItem(id=2, annotations=[
             Label(0),
         ]),
     ])
Ejemplo n.º 12
0
 def __iter__(self):
     return iter([
         DatasetItem(id=1,
                     subset='train',
                     annotations=[
                         Label(4, id=1, group=1),
                         Label(9, id=2, group=2),
                     ],
                     attributes={'id': 1}),
     ])
Ejemplo n.º 13
0
 def __iter__(self):
     return iter([
         DatasetItem(id=1, subset='train', annotations=[
             Bbox(1, 2, 3, 4),
             Label(4),
         ]),
         DatasetItem(id=1, subset='val', annotations=[
             Label(4),
         ]),
     ])
Ejemplo n.º 14
0
    def test_remap_labels(self):
        src_dataset = Dataset.from_iterable(
            [
                DatasetItem(
                    id=1,
                    annotations=[
                        # Should be remapped
                        Label(1),
                        Bbox(1, 2, 3, 4, label=2),
                        Mask(image=np.array([1]), label=3),

                        # Should be kept
                        Polygon([1, 1, 2, 2, 3, 4], label=4),
                        PolyLine([1, 3, 4, 2, 5, 6])
                    ])
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable('label%s' % i for i in range(5)),
                AnnotationType.mask:
                MaskCategories(colormap=mask_tools.generate_colormap(5)),
            })

        dst_dataset = Dataset.from_iterable(
            [
                DatasetItem(id=1,
                            annotations=[
                                Label(1),
                                Bbox(1, 2, 3, 4, label=0),
                                Mask(image=np.array([1]), label=1),
                                Polygon([1, 1, 2, 2, 3, 4], label=2),
                                PolyLine([1, 3, 4, 2, 5, 6], label=None)
                            ]),
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable(['label0', 'label9', 'label4']),
                AnnotationType.mask:
                MaskCategories(
                    colormap={
                        k: v
                        for k, v in mask_tools.generate_colormap(5).items()
                        if k in {0, 1, 3, 4}
                    })
            })

        actual = transforms.RemapLabels(src_dataset,
                                        mapping={
                                            'label1': 'label9',
                                            'label2': 'label0',
                                            'label3': 'label9',
                                        },
                                        default='keep')

        compare_datasets(self, dst_dataset, actual)
Ejemplo n.º 15
0
 def __iter__(self):
     return iter([
         DatasetItem(id=0,
                     subset='s1',
                     image=np.zeros((5, 10, 3)),
                     annotations=[
                         Polygon([0, 0, 4, 0, 4, 4],
                                 label=1,
                                 group=4,
                                 attributes={'occluded': True}),
                         Polygon([5, 0, 9, 0, 5, 5],
                                 label=2,
                                 group=4,
                                 attributes={'unknown': 'bar'}),
                         Points([1, 1, 3, 2, 2, 3],
                                label=2,
                                attributes={
                                    'a1': 'x',
                                    'a2': 42
                                }),
                         Label(1),
                         Label(2, attributes={
                             'a1': 'y',
                             'a2': 44
                         }),
                     ]),
         DatasetItem(id=1,
                     subset='s1',
                     annotations=[
                         PolyLine([0, 0, 4, 0, 4, 4],
                                  label=3,
                                  id=4,
                                  group=4),
                         Bbox(5, 0, 1, 9, label=3, id=4, group=4),
                     ]),
         DatasetItem(
             id=2,
             subset='s2',
             image=np.ones((5, 10, 3)),
             annotations=[
                 Polygon([0, 0, 4, 0, 4, 4],
                         label=3,
                         group=4,
                         attributes={
                             'z_order': 1,
                             'occluded': False
                         }),
                 PolyLine([5, 0, 9, 0, 5,
                           5]),  # will be skipped as no label
             ]),
         DatasetItem(id=3,
                     subset='s3',
                     image=Image(path='3.jpg', size=(2, 4))),
     ])
Ejemplo n.º 16
0
    def test_split_for_reidentification_gives_error(self):
        query = 0.4 / 0.7  # valid query ratio

        with self.subTest("no label"):
            source = Dataset.from_iterable([
                DatasetItem(1, annotations=[]),
                DatasetItem(2, annotations=[]),
            ],
                                           categories=["a", "b", "c"])

            with self.assertRaisesRegex(Exception, "exactly one is expected"):
                splits = [("train", 0.5), ("val", 0.2), ("test", 0.3)]
                actual = splitter.ReidentificationSplit(source, splits, query)
                len(actual.get_subset("train"))

        with self.subTest(msg="multi label"):
            source = Dataset.from_iterable([
                DatasetItem(1, annotations=[Label(0), Label(1)]),
                DatasetItem(2, annotations=[Label(0), Label(2)]),
            ],
                                           categories=["a", "b", "c"])

            with self.assertRaisesRegex(Exception, "exactly one is expected"):
                splits = [("train", 0.5), ("val", 0.2), ("test", 0.3)]
                actual = splitter.ReidentificationSplit(source, splits, query)
                len(actual.get_subset("train"))

        counts = {i: (i % 3 + 1) * 7 for i in range(10)}
        config = {"person": {"attrs": ["PID"], "counts": counts}}
        source = self._generate_dataset(config)
        with self.subTest("wrong ratio"):
            with self.assertRaisesRegex(Exception, "in the range"):
                splits = [("train", -0.5), ("val", 0.2), ("test", 0.3)]
                splitter.ReidentificationSplit(source, splits, query)

            with self.assertRaisesRegex(Exception, "Sum of ratios"):
                splits = [("train", 0.6), ("val", 0.2), ("test", 0.3)]
                splitter.ReidentificationSplit(source, splits, query)

            with self.assertRaisesRegex(Exception, "in the range"):
                splits = [("train", 0.5), ("val", 0.2), ("test", 0.3)]
                actual = splitter.ReidentificationSplit(source, splits, -query)

        with self.subTest("wrong subset name"):
            with self.assertRaisesRegex(Exception, "Subset name"):
                splits = [("_train", 0.5), ("val", 0.2), ("test", 0.3)]
                splitter.ReidentificationSplit(source, splits, query)

        with self.subTest("wrong attribute name for person id"):
            splits = [("train", 0.5), ("val", 0.2), ("test", 0.3)]
            actual = splitter.ReidentificationSplit(source, splits, query)

            with self.assertRaisesRegex(Exception, "Unknown subset"):
                actual.get_subset("test")
Ejemplo n.º 17
0
            def __iter__(self):
                return iter([
                    DatasetItem(id='a/0', subset='a', annotations=[
                        Label(1),
                        Label(2),
                        Label(3),
                    ]),

                    DatasetItem(id=1, subset='b', annotations=[
                        Label(4),
                    ]),
                ])
Ejemplo n.º 18
0
    def test_can_save_and_load_labels(self):
        expected_dataset = Dataset.from_iterable([
            DatasetItem(id=1, subset='train',
                annotations=[
                    Label(4, id=1, group=1),
                    Label(9, id=2, group=2),
                ], attributes={'id': 1}),
        ], categories=[str(i) for i in range(10)])

        with TestDir() as test_dir:
            self._test_save_and_load(expected_dataset,
                CocoLabelsConverter.convert, test_dir)
Ejemplo n.º 19
0
    def test_can_import_labels(self):
        expected_dataset = Dataset.from_iterable([
            DatasetItem(id=1, subset='train',
                annotations=[
                    Label(1, id=1, group=1),
                    Label(0, id=2, group=2),
                ], attributes={'id': 1}),
        ], categories=['a', 'b'])

        dataset = Dataset.import_from(
            osp.join(DUMMY_DATASET_DIR, 'coco_labels'), 'coco')

        compare_datasets(self, expected_dataset, dataset)
Ejemplo n.º 20
0
    def test_dataset(self):
        label_categories = LabelCategories()
        for i in range(5):
            label_categories.add('cat' + str(i))

        mask_categories = MaskCategories(
            generate_colormap(len(label_categories.items)))

        points_categories = PointsCategories()
        for index, _ in enumerate(label_categories.items):
            points_categories.add(index, ['cat1', 'cat2'], joints=[[0, 1]])

        return Dataset.from_iterable([
            DatasetItem(id=100, subset='train', image=np.ones((10, 6, 3)),
                annotations=[
                    Caption('hello', id=1),
                    Caption('world', id=2, group=5),
                    Label(2, id=3, attributes={
                        'x': 1,
                        'y': '2',
                    }),
                    Bbox(1, 2, 3, 4, label=4, id=4, z_order=1, attributes={
                        'score': 1.0,
                    }),
                    Bbox(5, 6, 7, 8, id=5, group=5),
                    Points([1, 2, 2, 0, 1, 1], label=0, id=5, z_order=4),
                    Mask(label=3, id=5, z_order=2, image=np.ones((2, 3))),
                ]),
            DatasetItem(id=21, subset='train',
                annotations=[
                    Caption('test'),
                    Label(2),
                    Bbox(1, 2, 3, 4, label=5, id=42, group=42)
                ]),

            DatasetItem(id=2, subset='val',
                annotations=[
                    PolyLine([1, 2, 3, 4, 5, 6, 7, 8], id=11, z_order=1),
                    Polygon([1, 2, 3, 4, 5, 6, 7, 8], id=12, z_order=4),
                ]),

            DatasetItem(id=42, subset='test',
                attributes={'a1': 5, 'a2': '42'}),

            DatasetItem(id=42),
            DatasetItem(id=43, image=Image(path='1/b/c.qq', size=(2, 4))),
        ], categories={
            AnnotationType.label: label_categories,
            AnnotationType.mask: mask_categories,
            AnnotationType.points: points_categories,
        })
Ejemplo n.º 21
0
    def test_can_allow_undeclared_attrs(self):
        source_dataset = Dataset.from_iterable([
            DatasetItem(
                id=0,
                annotations=[
                    Label(0, attributes={
                        'x': 4,
                        'y': 2
                    }),
                    Bbox(1, 2, 3, 4, label=0, attributes={
                        'x': 1,
                        'y': 1
                    }),
                ]),
        ],
                                               categories=[('a', '', {'x'})])

        target_label_cat = LabelCategories(attributes={'occluded'})
        target_label_cat.add('a', attributes={'x'})
        target_dataset = Dataset.from_iterable(
            [
                DatasetItem(id=0,
                            annotations=[
                                Label(0, attributes={
                                    'x': 4,
                                    'y': 2
                                }),
                                Bbox(1,
                                     2,
                                     3,
                                     4,
                                     label=0,
                                     attributes={
                                         'x': 1,
                                         'y': 1,
                                         'occluded': False
                                     }),
                            ],
                            attributes={'frame': 0}),
            ],
            categories={AnnotationType.label: target_label_cat})

        with TestDir() as test_dir:
            self._test_save_and_load(source_dataset,
                                     partial(CvatConverter.convert,
                                             allow_undeclared_attrs=True),
                                     test_dir,
                                     target_dataset=target_dataset)
Ejemplo n.º 22
0
    def test_can_match_items(self):
        # items 1 and 3 are unique, item 2 is common and should be merged

        source0 = Dataset.from_iterable([
            DatasetItem(1, annotations=[ Label(0), ]),
            DatasetItem(2, annotations=[ Label(0), ]),
        ], categories=['a', 'b'])

        source1 = Dataset.from_iterable([
            DatasetItem(2, annotations=[ Label(1), ]),
            DatasetItem(3, annotations=[ Label(0), ]),
        ], categories=['a', 'b'])

        source2 = Dataset.from_iterable([
            DatasetItem(2, annotations=[ Label(0), Bbox(1, 2, 3, 4) ]),
        ], categories=['a', 'b'])

        expected = Dataset.from_iterable([
            DatasetItem(1, annotations=[
                Label(0, attributes={'score': 1/3}),
            ]),
            DatasetItem(2, annotations=[
                Label(0, attributes={'score': 2/3}),
                Label(1, attributes={'score': 1/3}),
                Bbox(1, 2, 3, 4, attributes={'score': 1.0}),
            ]),
            DatasetItem(3, annotations=[
                Label(0, attributes={'score': 1/3}),
            ]),
        ], categories=['a', 'b'])

        merger = IntersectMerge()
        merged = merger([source0, source1, source2])

        compare_datasets(self, expected, merged)
        self.assertEqual(
            [
                NoMatchingItemError(item_id=('1', ''), sources={1, 2}),
                NoMatchingItemError(item_id=('3', ''), sources={0, 2}),
            ],
            sorted((e for e in merger.errors
                    if isinstance(e, NoMatchingItemError)),
                key=lambda e: e.item_id)
        )
        self.assertEqual(
            [
                NoMatchingAnnError(item_id=('2', ''), sources={0, 1},
                    ann=source2.get('2').annotations[1]),
            ],
            sorted((e for e in merger.errors
                    if isinstance(e, NoMatchingAnnError)),
                key=lambda e: e.item_id)
        )
Ejemplo n.º 23
0
 def transform_item(self, item):
     annotations = list(item.annotations)
     attributes = item.attributes
     if item.attributes:
         annotations.append(Label(self._label, attributes=item.attributes))
         attributes = {}
     return item.wrap(annotations=annotations, attributes=attributes)
Ejemplo n.º 24
0
 def _generate_classification_dataset(self, config, num_duplicate):
     subsets = ["train", "val", "test"]
     dummy_images = [
         np.random.randint(0, 255, size=(224, 224, 3))
         for _ in range(num_duplicate)
     ]
     iterable = []
     label_cat = LabelCategories()
     idx = 0
     for label_id, label in enumerate(config.keys()):
         label_cat.add(label, attributes=None)
         num_item = config[label]
         for subset in subsets:
             for _ in range(num_item):
                 idx += 1
                 iterable.append(
                     DatasetItem(
                         idx,
                         subset=subset,
                         annotations=[Label(label_id)],
                         image=Image(data=dummy_images[idx %
                                                       num_duplicate]),
                     ))
     categories = {AnnotationType.label: label_cat}
     dataset = Dataset.from_iterable(iterable, categories)
     return dataset
Ejemplo n.º 25
0
 def __iter__(self):
     return iter([
         DatasetItem(
             id='2007_000001',
             subset='train',
             image=Image(path='2007_000001.jpg', size=(10, 20)),
             annotations=[
                 Label(self._label(l.name))
                 for l in VOC.VocLabel if l.value % 2 == 1
             ] + [
                 Bbox(
                     1,
                     2,
                     2,
                     2,
                     label=self._label('cat'),
                     attributes={
                         'pose': VOC.VocPose(1).name,
                         'truncated': True,
                         'difficult': False,
                         'occluded': False,
                     },
                     id=1,
                     group=1,
                 ),
                 Bbox(
                     4,
                     5,
                     2,
                     2,
                     label=self._label('person'),
                     attributes={
                         'truncated': False,
                         'difficult': False,
                         'occluded': False,
                         **{
                             a.name: a.value % 2 == 1
                             for a in VOC.VocAction
                         }
                     },
                     id=2,
                     group=2,
                 ),
                 Bbox(5.5,
                      6,
                      2,
                      2,
                      label=self._label(VOC.VocBodyPart(1).name),
                      group=2),
                 Mask(
                     image=np.ones([5, 10]),
                     label=self._label(VOC.VocLabel(2).name),
                     group=1,
                 ),
             ]),
         DatasetItem(id='2007_000002',
                     subset='test',
                     image=np.ones((10, 20, 3))),
     ])
Ejemplo n.º 26
0
            def __iter__(self):
                return iter([
                    DatasetItem(id=1, subset='train',
                        annotations=[
                            Label(4, id=1, group=1),
                            Label(9, id=2, group=2),
                        ]),
                    DatasetItem(id=2, subset='train',
                        annotations=[
                            Label(4, id=4, group=4),
                        ]),

                    DatasetItem(id=3, subset='val',
                        annotations=[
                            Label(2, id=1, group=1),
                        ]),
                ])
Ejemplo n.º 27
0
    def transform_item(self, item):
        labels = set(p.label for p in item.annotations
                     if getattr(p, 'label') != None)
        annotations = []
        for label in labels:
            annotations.append(Label(label=label))

        return item.wrap(annotations=annotations)
Ejemplo n.º 28
0
    def test_attributes(self):
        source0 = Dataset.from_iterable([
            DatasetItem(1, annotations=[
                Label(2, attributes={
                    'unique': 1,
                    'common_under_quorum': 2,
                    'common_over_quorum': 3,
                    'ignored': 'q',
                }),
            ]),
        ], categories=['a', 'b', 'c'])

        source1 = Dataset.from_iterable([
            DatasetItem(1, annotations=[
                Label(2, attributes={
                    'common_under_quorum': 2,
                    'common_over_quorum': 3,
                    'ignored': 'q',
                }),
            ]),
        ], categories=['a', 'b', 'c'])

        source2 = Dataset.from_iterable([
            DatasetItem(1, annotations=[
                Label(2, attributes={
                    'common_over_quorum': 3,
                    'ignored': 'q',
                }),
            ]),
        ], categories=['a', 'b', 'c'])

        expected = Dataset.from_iterable([
            DatasetItem(1, annotations=[
                Label(2, attributes={ 'common_over_quorum': 3 }),
            ]),
        ], categories=['a', 'b', 'c'])

        merger = IntersectMerge(conf={
            'quorum': 3, 'ignored_attributes': {'ignored'}})
        merged = merger([source0, source1, source2])

        compare_datasets(self, expected, merged, ignored_attrs={'score'})
        self.assertEqual(2, len([e for e in merger.errors
            if isinstance(e, FailedAttrVotingError)])
        )
Ejemplo n.º 29
0
    def test_can_join_annotations(self):
        a = Dataset.from_iterable([
            DatasetItem(id=1,
                        subset='train',
                        annotations=[
                            Label(1, id=3),
                            Label(2, attributes={'x': 1}),
                        ])
        ],
                                  categories=['a', 'b', 'c', 'd'])

        b = Dataset.from_iterable([
            DatasetItem(id=1,
                        subset='train',
                        annotations=[
                            Label(2, attributes={'x': 1}),
                            Label(3, id=4),
                        ])
        ],
                                  categories=['a', 'b', 'c', 'd'])

        expected = Dataset.from_iterable([
            DatasetItem(id=1,
                        subset='train',
                        annotations=[
                            Label(1, id=3),
                            Label(2, attributes={'x': 1}),
                            Label(3, id=4),
                        ])
        ],
                                         categories=['a', 'b', 'c', 'd'])

        merged = Dataset.from_extractors(a, b)

        compare_datasets(self, expected, merged)
Ejemplo n.º 30
0
    def test_can_import(self):
        expected_dataset = Dataset.from_iterable([
            DatasetItem(id='1',
                image=np.ones((8, 8, 3)),
                annotations=[Label(0), Label(1)]
            ),
            DatasetItem(id='2',
                image=np.ones((10, 10, 3)),
                annotations=[Label(0)]
            ),
        ], categories={
            AnnotationType.label: LabelCategories.from_iterable(
                'label_' + str(label) for label in range(2)),
        })

        dataset = Dataset.import_from(DUMMY_DATASET_DIR, 'imagenet')

        compare_datasets(self, expected_dataset, dataset, require_images=True)