Пример #1
0
            def __iter__(self):
                return iter([
                    DatasetItem(id=1, subset='train', image=np.ones((4, 4, 3)),
                        annotations=[
                            # Bbox + single polygon
                            Bbox(0, 1, 2, 2,
                                label=2, group=1, id=1,
                                attributes={ 'is_crowd': False }),
                            Polygon([0, 1, 2, 1, 2, 3, 0, 3],
                                attributes={ 'is_crowd': False },
                                label=2, group=1, id=1),
                        ]),
                    DatasetItem(id=2, subset='train', image=np.ones((4, 4, 3)),
                        annotations=[
                            # Mask + bbox
                            Mask(np.array([
                                    [0, 1, 0, 0],
                                    [0, 1, 0, 0],
                                    [0, 1, 1, 1],
                                    [0, 0, 0, 0]],
                                ),
                                attributes={ 'is_crowd': True },
                                label=4, group=3, id=3),
                            Bbox(1, 0, 2, 2, label=4, group=3, id=3,
                                attributes={ 'is_crowd': True }),
                        ]),

                    DatasetItem(id=3, subset='val', image=np.ones((4, 4, 3)),
                        annotations=[
                            # Bbox + mask
                            Bbox(0, 1, 2, 2, label=4, group=3, id=3,
                                attributes={ 'is_crowd': True }),
                            Mask(np.array([
                                    [0, 0, 0, 0],
                                    [1, 1, 1, 0],
                                    [1, 1, 0, 0],
                                    [0, 0, 0, 0]],
                                ),
                                attributes={ 'is_crowd': True },
                                label=4, group=3, id=3),
                        ]),
                ])
Пример #2
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,
                              attributes={
                                  'score': 1.0,
                              }),
                         Bbox(5, 6, 7, 8, id=5, group=5),
                         Points([1, 2, 2, 0, 1, 1], label=0, id=5),
                         Mask(label=3, id=5, 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),
                         Polygon([1, 2, 3, 4, 5, 6, 7, 8], id=12),
                     ]),
         DatasetItem(id=42, subset='test'),
         DatasetItem(id=42),
         DatasetItem(id=43, image=Image(path='1/b/c.qq', size=(2, 4))),
     ])
Пример #3
0
    def test_can_save_and_load(self):
        source_dataset = Dataset.from_iterable([
            DatasetItem(id='1', subset='train', image=np.ones((8, 8, 3)),
                annotations=[
                    Bbox(0, 2, 4, 2, label=0, group=1),
                    Points([3.2, 3.12, 4.11, 3.2, 2.11,
                        2.5, 3.5, 2.11, 3.8, 2.13], label=0, group=1),
                ]
            ),
            DatasetItem(id='2', subset='train', image=np.ones((10, 10, 3)),
                annotations=[
                    Points([4.23, 4.32, 5.34, 4.45, 3.54,
                        3.56, 4.52, 3.51, 4.78, 3.34], label=1, group=1),
                ]
            ),
            DatasetItem(id='3', subset='train', image=np.ones((8, 8, 3)),
                annotations=[Label(2, group=1)]
            ),
            DatasetItem(id='4', subset='train', image=np.ones((10, 10, 3)),
                annotations=[
                    Bbox(0, 2, 4, 2, label=3, group=1),
                    Points([3.2, 3.12, 4.11, 3.2, 2.11,
                        2.5, 3.5, 2.11, 3.8, 2.13], label=3, group=1),
                ]
            ),
            DatasetItem(id='a/5', subset='train', image=np.ones((8, 8, 3)),
                annotations=[
                    Bbox(2, 2, 2, 2, group=1),
                ]
            ),
            DatasetItem(id='label_0', subset='train', image=np.ones((8, 8, 3)),
            ),
        ], categories={
            AnnotationType.label: LabelCategories.from_iterable(
                [('label_%s' % i, 'class_%s' % i) for i in range(5)]),
        })

        with TestDir() as test_dir:
            VggFace2Converter.convert(source_dataset, test_dir, save_images=True)
            parsed_dataset = Dataset.import_from(test_dir, 'vgg_face2')

            compare_datasets(self, source_dataset, parsed_dataset)
Пример #4
0
 def __iter__(self):
     return iter([
         DatasetItem(id='2007_000001', subset='train',
             image=Image(path='2007_000001.jpg', size=(20, 10)),
             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.zeros((20, 10, 3))),
     ])
Пример #5
0
    def test_item_representations():
        item = DatasetItem(id=1, subset='subset', path=['a', 'b'],
            image=np.ones((5, 4, 3)),
            annotations=[
                Label(0, attributes={'a1': 1, 'a2': '2'}, id=1, group=2),
                Caption('hello', id=1),
                Caption('world', group=5),
                Label(2, id=3, attributes={ 'x': 1, 'y': '2' }),
                Bbox(1, 2, 3, 4, label=4, id=4, attributes={ 'a': 1.0 }),
                Bbox(5, 6, 7, 8, id=5, group=5),
                Points([1, 2, 2, 0, 1, 1], label=0, id=5),
                Mask(id=5, image=np.ones((3, 2))),
                Mask(label=3, id=5, image=np.ones((2, 3))),
                PolyLine([1, 2, 3, 4, 5, 6, 7, 8], id=11),
                Polygon([1, 2, 3, 4, 5, 6, 7, 8]),
            ]
        )

        encoded = DatasetItemEncoder.encode(item)
        DatasetItemEncoder.to_string(encoded)
Пример #6
0
    def test_can_import(self):
        expected_dataset = Dataset.from_iterable(
            [
                DatasetItem(id=1,
                            subset='train',
                            image=np.ones((10, 15, 3)),
                            annotations=[
                                Bbox(0, 2, 4, 2, label=2),
                                Bbox(3, 3, 2, 3, label=4),
                            ]),
            ],
            categories={
                AnnotationType.label:
                LabelCategories.from_iterable('label_' + str(i)
                                              for i in range(10)),
            })

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

        compare_datasets(self, expected_dataset, dataset)
Пример #7
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),
             Label(5),
         ]),
     ])
    def test_can_save_and_load_with_no_subsets(self):
        expected_dataset = Dataset.from_iterable([
            DatasetItem(id=1, image=np.ones((8, 8, 3)),
                annotations=[
                    Bbox(0, 1, 3, 5),
                ]),
        ])

        with TestDir() as test_dir:
            self._test_save_and_load(expected_dataset,
                IcdarTextLocalizationConverter.convert, test_dir)
    def test_can_save_bboxes(self):
        test_dataset = Dataset.from_iterable([
            DatasetItem(id=1, subset='train',
                image=np.ones((16, 16, 3)),
                annotations=[
                    Bbox(0, 4, 4, 8, label=2),
                    Bbox(0, 4, 4, 4, label=3),
                    Bbox(2, 4, 4, 4),
                ], attributes={'source_id': ''}
            ),
        ], categories={
            AnnotationType.label: LabelCategories.from_iterable(
                'label_' + str(label) for label in range(10)),
        })

        with TestDir() as test_dir:
            self._test_save_and_load(
                test_dataset,
                partial(TfDetectionApiConverter.convert, save_images=True),
                test_dir)
Пример #10
0
 def __iter__(self):
     yield DatasetItem(id=1, annotations=[
         # drop non voc label
         Bbox(2, 3, 4, 5, label=self._label('cat'), id=1, group=1,
             attributes={
                 'truncated': False,
                 'difficult': False,
                 'occluded': False,
             }
         ),
     ])
Пример #11
0
 def __iter__(self):
     yield DatasetItem(id=1,
                       annotations=[
                           Bbox(1,
                                2,
                                3,
                                4,
                                label=0,
                                id=1,
                                group=1,
                                attributes={
                                    'act1': True,
                                    'act2': False,
                                    'truncated': False,
                                    'difficult': False,
                                    'occluded': False,
                                }),
                           Bbox(2, 3, 4, 5, label=1, group=1),
                           Bbox(2, 3, 4, 6, label=2, group=1),
                       ])
Пример #12
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))),
     ])
Пример #13
0
 def __iter__(self):
     return iter([
         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)
                     ]),
     ])
Пример #14
0
    def test_can_load_dataset_with_exact_image_info(self):
        source_dataset = Dataset.from_iterable([
            DatasetItem(id=1, subset='train',
                image=Image(path='1.jpg', size=(10, 15)),
                annotations=[
                    Bbox(0, 2, 4, 2, label=2),
                    Bbox(3, 3, 2, 3, label=4),
                ]),
        ], categories={
            AnnotationType.label: LabelCategories.from_iterable(
                'label_' + str(i) for i in range(10)),
        })

        with TestDir() as test_dir:
            YoloConverter.convert(source_dataset, test_dir)

            parsed_dataset = YoloImporter()(test_dir,
                image_info={'1': (10, 15)}).make_dataset()

            compare_datasets(self, source_dataset, parsed_dataset)
Пример #15
0
 def setUpClass(cls):
     cls.dataset = Dataset.from_iterable([
         DatasetItem(id=1, image=np.ones((5, 5, 3)), annotations=[
             Label(1, id=0, attributes={'a': 1, 'b': 7, }),
             Bbox(1, 2, 3, 4, id=1, label=0, attributes={
                 'a': 1, 'b': 2,
             }),
         ]),
         DatasetItem(id=2, image=np.ones((2, 4, 3)), annotations=[
             Label(2, id=0, attributes={'a': 2, 'b': 2, }),
             Bbox(2, 3, 1, 4, id=1, label=0, attributes={
                 'a': 1, 'b': 1,
             }),
         ]),
         DatasetItem(id=3),
         DatasetItem(id=4, image=np.ones((2, 4, 3)), annotations=[
             Label(0, id=0, attributes={'b': 4, }),
             Label(1, id=1, attributes={'a': 11, 'b': 7, }),
             Bbox(1, 3, 2, 4, id=2, label=0, attributes={
                 'a': 2, 'b': 1,
             }),
             Bbox(3, 1, 4, 2, id=3, label=0, attributes={
                 'a': 2, 'b': 2,
             }),
         ]),
         DatasetItem(id=5, image=np.ones((2, 4, 3)), annotations=[
             Label(0, id=0, attributes={'a': 20, 'b': 10, }),
             Bbox(1, 2, 3, 4, id=1, label=1, attributes={
                 'a': 1, 'b': 1,
             }),
         ]),
         DatasetItem(id=6, image=np.ones((2, 4, 3)), annotations=[
             Label(1, id=0, attributes={'a': 11, 'b': 2, 'c': 3, }),
             Bbox(2, 3, 4, 1, id=1, label=1, attributes={
                 'a': 2, 'b': 2,
             }),
         ]),
         DatasetItem(id=7, image=np.ones((2, 4, 3)), annotations=[
             Label(1, id=0, attributes={'a': 1, 'b': 2, 'c': 5, }),
             Bbox(1, 2, 3, 4, id=1, label=2, attributes={
                 'a': 1, 'b': 2,
             }),
         ]),
         DatasetItem(id=8, image=np.ones((2, 4, 3)), annotations=[
             Label(2, id=0, attributes={'a': 7, 'b': 9, 'c': 5, }),
             Bbox(2, 1, 3, 4, id=1, label=2, attributes={
                 'a': 2, 'b': 1,
             }),
         ]),
     ], categories=[[f'label_{i}', None, {'a', 'b', }]
         for i in range(2)])
Пример #16
0
 def __iter__(self):
     return iter([
         DatasetItem(id=1, subset='train',
             image=np.ones((16, 16, 3)),
             annotations=[
                 Bbox(0, 4, 4, 8, label=2, group=2),
                 Polygon([0, 4, 4, 4, 5, 6], label=3, attributes={
                     'occluded': True,
                     'a1': 'qwe',
                     'a2': True,
                     'a3': 123,
                 }),
                 Mask(np.array([[0, 1], [1, 0], [1, 1]]), group=2,
                     attributes={ 'username': '******' }),
                 Bbox(1, 2, 3, 4, group=3),
                 Mask(np.array([[0, 0], [0, 0], [1, 1]]), group=3,
                     attributes={ 'occluded': True }
                 ),
             ]
         ),
     ])
Пример #17
0
 def append_bbox_mot(annotations, **kwargs):
     annotations.append(
         Bbox(
             1,
             1,
             2,
             2,
             label=kwargs["label_id"],
             attributes=kwargs["attributes"],
         ))
     annotations.append(
         Label(kwargs["label_id"], attributes=kwargs["attributes"]))
Пример #18
0
    def test_can_save_dataset_with_no_labels(self):
        source_dataset = Dataset.from_iterable([
            DatasetItem(id='1', image=np.ones((8, 8, 3)),
                annotations=[
                    Bbox(0, 2, 4, 2, group=1),
                    Points([4.23, 4.32, 5.34, 4.45, 3.54,
                        3.56, 4.52, 3.51, 4.78, 3.34], group=1),
                ]
            ),
            DatasetItem(id='2', image=np.ones((8, 8, 3)),
                annotations=[
                    Bbox(2, 2, 4, 2, group=1),
                ]
            ),
        ], categories=[])

        with TestDir() as test_dir:
            VggFace2Converter.convert(source_dataset, test_dir, save_images=False)
            parsed_dataset = Dataset.import_from(test_dir, 'vgg_face2')

            compare_datasets(self, source_dataset, parsed_dataset)
Пример #19
0
    def test_can_save_dataset_with_image_info(self):
        source_dataset = Dataset.from_iterable([
            DatasetItem(id=1, subset='train',
                image=Image(path='1.jpg', size=(10, 15)),
                annotations=[
                    Bbox(0, 2, 4, 2, label=2),
                    Bbox(3, 3, 2, 3, label=4),
                ]),
        ], categories={
            AnnotationType.label: LabelCategories.from_iterable(
                'label_' + str(i) for i in range(10)),
        })

        with TestDir() as test_dir:
            YoloConverter.convert(source_dataset, test_dir)

            save_image(osp.join(test_dir, 'obj_train_data', '1.jpg'),
                np.ones((10, 15, 3))) # put the image for dataset
            parsed_dataset = YoloImporter()(test_dir).make_dataset()

            compare_datasets(self, source_dataset, parsed_dataset)
Пример #20
0
 def __iter__(self):
     return iter([
         DatasetItem(id=1,
                     subset='train',
                     image=np.ones((16, 16, 3)),
                     annotations=[
                         Bbox(0,
                              4,
                              4,
                              8,
                              label=2,
                              attributes={
                                  'occluded': True,
                              }),
                         Bbox(0,
                              4,
                              4,
                              4,
                              label=3,
                              attributes={
                                  'visibility': 0.4,
                              }),
                         Bbox(2,
                              4,
                              4,
                              4,
                              attributes={'ignored': True}),
                     ]),
         DatasetItem(id=2,
                     subset='val',
                     image=np.ones((8, 8, 3)),
                     annotations=[
                         Bbox(1, 2, 4, 2, label=3),
                     ]),
         DatasetItem(
             id=3,
             subset='test',
             image=np.ones((5, 4, 3)) * 3,
         ),
     ])
    def test_can_import_bboxes(self):
        expected_dataset = Dataset.from_iterable([
            DatasetItem(id='img_1', subset='train',
                image=np.ones((10, 15, 3)),
                annotations=[
                    Polygon([0, 0, 3, 1, 4, 6, 1, 7],
                        attributes={'text': 'FOOD'}),
                ]
            ),
            DatasetItem(id='img_2', subset='train',
                image=np.ones((10, 15, 3)),
                annotations=[
                    Bbox(0, 0, 2, 3, attributes={'text': 'RED'}),
                    Bbox(3, 3, 2, 3, attributes={'text': 'LION'}),
                ]
            ),
        ])

        dataset = Dataset.import_from(
            osp.join(DUMMY_DATASET_DIR, 'text_localization'), 'icdar')

        compare_datasets(self, expected_dataset, dataset)
Пример #22
0
    def test_can_find_missing_boxes(self):
        detections = 3
        class_count = 2
        item1 = DatasetItem(id=1, annotations=[
            Bbox(i * 10, 10, 10, 10, label=i)
            for i in range(detections) if i % 2 == 0
        ])
        item2 = DatasetItem(id=2, annotations=[
            Bbox(i * 10, 10, 10, 10, label=(i + 1) % class_count)
            for i in range(detections) if i % 2 == 1
        ])

        iou_thresh = 0.5
        comp = DistanceComparator(iou_threshold=iou_thresh)

        result = comp.match_boxes(item1, item2)

        matches, mispred, a_greater, b_greater = result
        self.assertEqual(0, len(mispred))
        self.assertEqual(len(item1.annotations), len(a_greater))
        self.assertEqual(len(item2.annotations), len(b_greater))
        self.assertEqual(0, len(matches))
Пример #23
0
 def __iter__(self):
     return iter([
         DatasetItem(id='a', annotations=[
             Bbox(2, 3, 4, 5, label=2, id=1, group=1,
                 attributes={
                     'truncated': False,
                     'difficult': False,
                     'occluded': True,
                     'x': '1', 'y': '2', # can only read strings
                 }
             ),
         ]),
     ])
Пример #24
0
 def __iter__(self):
     return iter([
         DatasetItem(id=1,
                     subset='train',
                     image=np.ones((16, 16, 3)),
                     annotations=[
                         Bbox(0, 4, 4, 8, label=2),
                         Bbox(0, 4, 4, 4, label=3),
                         Bbox(2, 4, 4, 4),
                     ]),
         DatasetItem(id=2,
                     subset='val',
                     image=np.ones((8, 8, 3)),
                     annotations=[
                         Bbox(1, 2, 4, 2, label=3),
                     ]),
         DatasetItem(
             id=3,
             subset='test',
             image=np.ones((5, 4, 3)) * 3,
         ),
     ])
Пример #25
0
            def __iter__(self):
                return iter([
                    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], label=None)
                    ]),
                ])
Пример #26
0
    def test_can_merge_classes(self):
        source0 = Dataset.from_iterable([
            DatasetItem(1,
                        annotations=[
                            Label(0),
                            Label(1),
                            Bbox(0, 0, 1, 1, label=1),
                        ]),
        ],
                                        categories=['a', 'b'])

        source1 = Dataset.from_iterable([
            DatasetItem(1,
                        annotations=[
                            Label(0),
                            Label(1),
                            Bbox(0, 0, 1, 1, label=0),
                            Bbox(0, 0, 1, 1, label=1),
                        ]),
        ],
                                        categories=['b', 'c'])

        expected = Dataset.from_iterable([
            DatasetItem(1,
                        annotations=[
                            Label(0),
                            Label(1),
                            Label(2),
                            Bbox(0, 0, 1, 1, label=1),
                            Bbox(0, 0, 1, 1, label=2),
                        ]),
        ],
                                         categories=['a', 'b', 'c'])

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

        compare_datasets(self, expected, merged, ignored_attrs={'score'})
Пример #27
0
 def append_bbox_coco(annotations, **kwargs):
     annotations.append(
         Bbox(
             1,
             1,
             2,
             2,
             label=kwargs["label_id"],
             id=kwargs["ann_id"],
             attributes=kwargs["attributes"],
             group=kwargs["ann_id"],
         ))
     annotations.append(
         Label(kwargs["label_id"], attributes=kwargs["attributes"]))
Пример #28
0
            def _process(self, image):
                detections = []
                for i, roi in enumerate(self.rois):
                    roi_sum = self.roi_value(roi, image)
                    roi_base_sum = self.roi_base_sums[i]
                    first_run = roi_base_sum is None
                    if first_run:
                        roi_base_sum = roi_sum
                        self.roi_base_sums[i] = roi_base_sum

                    cls_conf = roi_sum / roi_base_sum

                    if roi.threshold < roi_sum / roi_base_sum:
                        cls = roi.label
                        detections.append(
                            Bbox(roi.x,
                                 roi.y,
                                 roi.w,
                                 roi.h,
                                 label=cls,
                                 attributes={'score': cls_conf}))

                    if first_run:
                        continue
                    for j in range(self.fp_count):
                        if roi.threshold < cls_conf:
                            cls = roi.label
                        else:
                            cls = (i + j) % self.class_count
                        box = [roi.x, roi.y, roi.w, roi.h]
                        offset = (np.random.rand(4) - 0.5) * self.pixel_jitter
                        detections.append(
                            Bbox(*(box + offset),
                                 label=cls,
                                 attributes={'score': cls_conf}))

                return detections
Пример #29
0
    def download_labeled_image(self, task_id: int, frame_id: int, outdir: str):
        filename, img = self.task.download_frame(task_id,
                                                 frame_id,
                                                 outdir,
                                                 save=False)
        labels = dict([(label.id, label)
                       for label in self.task.get_id(task_id).labels])
        jobs = self.task.get_jobs(task_id)
        job_id_with_frame = [
            job.id for job in jobs if (int(job.start_frame) <= frame_id)
            & (frame_id <= int(job.stop_frame))
        ]
        job_annos_list = [
            self.job.get_annotations(job_id) for job_id in job_id_with_frame
        ]
        annos = [[anno for anno in job_annos.shapes
                  if anno.frame == frame_id][0]
                 for job_annos in job_annos_list]
        categories = [label.name for label in labels.values()]
        items = []
        for anno in annos:
            attriname = dict([(attr.id, attr.name)
                              for attr in labels[anno.label_id].attributes])
            attris = dict([(attriname[attr.spec_id], attr.value)
                           for attr in anno.attributes])
            if anno.type == 'rectangle':
                x, y, x2, y2 = anno.points
                items.append(
                    Bbox(x,
                         y,
                         x2 - x,
                         y2 - y,
                         attributes=attris,
                         label=categories.index(labels[anno.label_id].name)))
            elif anno.type == 'polygon':
                items.append(
                    Polygon(anno.points,
                            attributes=attris,
                            label=categories.index(
                                labels[anno.label_id].name)))

        # image = {'data': np.asarray(img),
        #          'path': str(Path(outdir)/filename)}
        dataset = Dataset.from_iterable(
            [DatasetItem(id=filename, annotations=items, image=np.array(img))],
            categories=categories)
        customset = customDataset(dataset)
        for image_data in customset._imageDatas:
            image_data.drawItem('s', 's').saveImg(Path(outdir) / filename)
    def test_can_save_and_load_bboxes(self):
        expected_dataset = Dataset.from_iterable([
            DatasetItem(id=1, subset='train',
                annotations=[
                    Bbox(1, 3, 6, 10),
                    Bbox(0, 1, 3, 5, attributes={'text': 'word_0'}),
                ]),
            DatasetItem(id=2, subset='train',
                annotations=[
                    Polygon([0, 0, 3, 0, 4, 7, 1, 8],
                        attributes={'text': 'word_1'}),
                    Polygon([1, 2, 5, 3, 6, 8, 0, 7]),
                ]),
            DatasetItem(id=3, subset='train',
                annotations=[
                    Polygon([2, 2, 8, 3, 7, 10, 2, 9],
                        attributes={'text': 'word_2'}),
                    Bbox(0, 2, 5, 9, attributes={'text': 'word_3'}),
                ]),
        ])

        with TestDir() as test_dir:
            self._test_save_and_load(expected_dataset,
                IcdarTextLocalizationConverter.convert, test_dir)