示例#1
0
    def test_save_segmentation(self):
        '''
        test correct bbox conversion
        '''
        subject = ImportCoco(self.dataset)

        # add boundingbox [x,y,width,height]
        import_data = copy.deepcopy(self.correct_json_data)
        import_data['annotations'].append({
            'id':
            1002,
            'image_id':
            1,
            'category_id':
            3,
            'segmentation': [[10, 10, 20, 10, 20, 20, 10, 20]],
            'mask':
            'somestring',
            'iscrowd':
            True
        })
        subject.data = subject.convert(import_data)
        subject.save()

        result_anno_seg = Annotation.segmentation_objects.all()[0]
        self.assertEqual(result_anno_seg.identifier, '1002')
        self.assertEqual(result_anno_seg.category.identifier, '3')
        self.assertEqual(result_anno_seg.image.identifier, '1')
        self.assertEqual(result_anno_seg.segmentation,
                         [[10, 10, 20, 10, 20, 20, 10, 20]])
        self.assertEqual(result_anno_seg.mask, 'somestring')

        self.assertEqual(result_anno_seg.is_crowd, True)
示例#2
0
    def test_save_bbox(self):
        '''
        test correct bbox conversion
        '''
        import copy
        subject = ImportCoco(self.dataset)

        # add boundingbox [x,y,width,height]
        import_data = copy.deepcopy(self.correct_json_data)
        import_data['annotations'].append({
            'id': 1001,
            'image_id': 1,
            'category_id': 3,
            'bbox': [100, 100, 100, 100],
            'iscrowd': True
        })
        subject.data = subject.convert(import_data)
        subject.save()

        result_anno_bbox = Annotation.boundingbox_objects.all()[0]
        self.assertEqual(result_anno_bbox.identifier, '1001')
        self.assertEqual(result_anno_bbox.category.identifier, '3')
        self.assertEqual(result_anno_bbox.image.identifier, '1')
        self.assertEqual(result_anno_bbox.x_min, 100)
        self.assertEqual(result_anno_bbox.y_min, 100)
        self.assertEqual(result_anno_bbox.x_max, 200)
        self.assertEqual(result_anno_bbox.y_max, 200)
        self.assertEqual(result_anno_bbox.is_crowd, True)
示例#3
0
    def test_import_ids(self):
        '''
        we only need to import stuff, that belongs to defined images
        so we can ignore the rest
        '''
        subject = ImportCoco(self.dataset)
        subject.data = subject.convert(self._incorrect_data())
        result = subject.import_ids()

        self.assertEqual(result['images'], [1])
        self.assertEqual(result['annotations'], [2])
        self.assertEqual(result['categories'], [3])
        self.assertEqual(result['licenses'], [5])
示例#4
0
    def test_convert_and_filter(self):
        test_json_data = self.correct_json_data
        test_json_data['not_known_key'] = [{'id': 4, 'name': 'not known'}]

        subject = ImportCoco(self.dataset)
        result = subject.convert(test_json_data)

        self.assertEqual(
            list(result.keys()).sort(),
            ['info', 'images', 'annotations', 'categories', 'licenses'].sort())

        self.assertEqual(list(result['images'].keys()), [1])
        self.assertEqual(list(result['annotations'].keys()), [2])
        self.assertEqual(list(result['categories'].keys()), [3])
        self.assertEqual(list(result['licenses'].keys()), [5])

        self.assertEqual(result['images'][1], test_json_data['images'][0])
示例#5
0
    def test_stats_cleaned(self):
        '''
        we only need to import stuff, that belongs to defined images
        so we can ignore the rest
        '''
        subject = ImportCoco(self.dataset)
        subject.data = subject.convert(self._incorrect_data())
        result = subject.stats()

        self.assertEqual(
            result, {
                'images': 1,
                'images_all': 1,
                'annotations': 1,
                'annotations_all': 2,
                'categories': 1,
                'categories_all': 2,
                'licenses': 1,
                'licenses_all': 2
            })
示例#6
0
    def test_save_annotation(self):
        '''
        test correct bbox conversion
        '''
        import copy
        subject = ImportCoco(self.dataset)

        # add boundingbox [x,y,width,height]
        import_data = copy.deepcopy(self.correct_json_data)
        import_data['annotations'].append({
            'id': 1000,
            'image_id': 1,
            'category_id': 3,
        })
        subject.data = subject.convert(import_data)
        subject.save()

        result_anno = Annotation.objects.all()[1]
        self.assertEqual(result_anno.identifier, '1000')
        self.assertEqual(result_anno.category.identifier, '3')
        self.assertEqual(result_anno.image.identifier, '1')
示例#7
0
    def test_save(self):
        '''
        we only need to import stuff, that belongs to defined images
        so we can ignore the rest
        '''
        subject = ImportCoco(self.dataset)
        subject.data = subject.convert(self.correct_json_data)
        subject.save()

        result_i = [image.identifier for image in Image.objects.all()]
        expected_i = [
            str(image['id']) for image in self.correct_json_data['images']
        ]
        self.assertEqual(expected_i, result_i)

        result_c = [category.identifier for category in Category.objects.all()]
        expected_c = [
            str(category['id'])
            for category in self.correct_json_data['categories']
        ]
        self.assertEqual(expected_i, result_i)