Skip to content

Commit

Permalink
Fix unknown formats in tf detection api export (#40)
Browse files Browse the repository at this point in the history
* Support jpeg (along with jpg)
* Fix unknown formats
  • Loading branch information
Maxim Zhiltsov authored Oct 13, 2020
1 parent 245c770 commit a00a4ec
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Default `label-map` parameter value for VOC converter (<https://github.com/openvinotoolkit/datumaro/pull/34>)
- Randomness of random split transform (<https://github.com/openvinotoolkit/datumaro/pull/38>)
- `Transform.subsets()` method (<https://github.com/openvinotoolkit/datumaro/pull/38>)
- Supported unknown image formats in TF Detection API converter (<https://github.com/openvinotoolkit/datumaro/pull/40>)

### Security
-
Expand Down
2 changes: 1 addition & 1 deletion datumaro/plugins/tf_detection_api_format/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _make_tf_example(self, item):
def _save_image(self, item, path=None):
src_ext = item.image.ext.lower()
dst_ext = osp.splitext(osp.basename(path))[1].lower()
fmt = DetectionApiPath.IMAGE_EXT_FORMAT.get(dst_ext)
fmt = DetectionApiPath.IMAGE_EXT_FORMAT.get(dst_ext, '')
if not fmt:
log.warning("Item '%s': can't find format string for the '%s' "
"image extension, the corresponding field will be empty." % \
Expand Down
2 changes: 1 addition & 1 deletion datumaro/plugins/tf_detection_api_format/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class DetectionApiPath:
ANNOTATIONS_DIR = 'annotations'

DEFAULT_IMAGE_EXT = '.jpg'
IMAGE_EXT_FORMAT = {'.jpg': 'jpeg', '.png': 'png'}
IMAGE_EXT_FORMAT = {'.jpg': 'jpeg', '.jpeg': 'jpeg', '.png': 'png'}

LABELMAP_FILE = 'label_map.pbtxt'
21 changes: 20 additions & 1 deletion tests/test_tfrecord_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
AnnotationType, Bbox, Mask, LabelCategories
)
from datumaro.components.project import Project
from datumaro.util.image import Image
from datumaro.util.image import Image, ByteImage, encode_image
from datumaro.util.test_utils import (TestDir, compare_datasets,
test_save_and_load)
from datumaro.util.tf_util import check_import
Expand Down Expand Up @@ -135,6 +135,25 @@ def test_can_save_dataset_with_image_info(self):
self._test_save_and_load(test_dataset,
TfDetectionApiConverter.convert, test_dir)

def test_can_save_dataset_with_unknown_image_formats(self):
test_dataset = Dataset.from_iterable([
DatasetItem(id=1,
image=ByteImage(data=encode_image(np.ones((5, 4, 3)), 'png'),
path='1/q.e'),
attributes={'source_id': ''}
),
DatasetItem(id=2,
image=ByteImage(data=encode_image(np.ones((6, 4, 3)), 'png'),
ext='qwe'),
attributes={'source_id': ''}
)
], categories={ AnnotationType.label: LabelCategories(), })

with TestDir() as test_dir:
self._test_save_and_load(test_dataset,
partial(TfDetectionApiConverter.convert, save_images=True),
test_dir)

def test_labelmap_parsing(self):
text = """
{
Expand Down

0 comments on commit a00a4ec

Please sign in to comment.