Skip to content

Commit

Permalink
Fix converter for Pascal VOC format (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Sizov authored May 13, 2021
1 parent 962ade0 commit f28d622
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added a label "face" for bounding boxes in Wider Face (<https://github.com/openvinotoolkit/datumaro/pull/215>)
- Allowed adding "difficult", "truncated", "occluded" attributes when converting to Pascal VOC if these attributes are not present (<https://github.com/openvinotoolkit/datumaro/pull/216>)
- Empty lines in YOLO annotations are ignored (<https://github.com/openvinotoolkit/datumaro/pull/221>)
- Export in VOC format when no image info is available (<https://github.com/openvinotoolkit/datumaro/pull/239>)

### Security
-
Expand Down
2 changes: 1 addition & 1 deletion datumaro/plugins/voc_format/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def save_subsets(self):
ET.SubElement(source_elem, 'annotation').text = 'Unknown'
ET.SubElement(source_elem, 'image').text = 'Unknown'

if item.has_image:
if item.has_image and item.image.has_size:
h, w = item.image.size
size_elem = ET.SubElement(root_elem, 'size')
ET.SubElement(size_elem, 'width').text = str(w)
Expand Down
28 changes: 27 additions & 1 deletion tests/test_voc_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,4 +763,30 @@ def test_inplace_save_writes_only_updated_data(self):
self.assertFalse(osp.isfile(
osp.join(path, 'SegmentationObject', '3.png')))
self.assertFalse(osp.isfile(
osp.join(path, 'SegmentationClass', '3.png')))
osp.join(path, 'SegmentationClass', '3.png')))

def test_can_save_dataset_with_no_data_images(self):
class TestExtractor(TestExtractorBase):
def __iter__(self):
return iter([
DatasetItem(id='frame1', subset='test',
image=Image(path='frame1.jpg'),
annotations=[
Bbox(1.0, 2.0, 3.0, 4.0,
attributes={
'difficult': False,
'truncated': False,
'occluded': False
},
id=1, label=0, group=1
)
]
)
])

def categories(self):
return VOC.make_voc_categories()

with TestDir() as test_dir:
self._test_save_and_load(TestExtractor(),
partial(VocConverter.convert, label_map='voc'), test_dir)

0 comments on commit f28d622

Please sign in to comment.