tensorflow / tensorflow/datasets

lsun/car and many other classes are encoded as webp, which decode_image does not support

Open
#3,345 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
4.6k
Forks
1.6k
Avg merge
3h 54m
Merged PRs (30d)
1

Description

Short description

Decoding the LSUN dataset isn't fully supported as some images are encoded as WebP.

Consider the code:

builder = tfds.builder('lsun/car')
builder.download_and_prepare()
dataset = builder.as_dataset("train")
for i, example in enumerate(dataset):
  if i > 10: break
  media.show_image(example['image'])

This causes:

InvalidArgumentError: Unknown image file format. One of JPEG, PNG, GIF, BMP required.

The error is very explicit about which formats are supported. Unfortunately multiple of the classes in LSUN are encoded as WebP, causing this error.

I would like to point out that tfio.image.decode_webp exists, so this is definitely fixable via a tf.cond() in the pipeline.

Environment information

  • Operating System: any

  • Python version: any

  • All versions affected.

  • Does the issue still exists with the last tfds-nightly package (pip install --upgrade tfds-nightly) ?
    Yes

Reproduction instructions

builder = tfds.builder('lsun/car')
builder.download_and_prepare()
dataset = builder.as_dataset("train")
for i, example in enumerate(dataset):
  if i > 10: break
  media.show_image(example['image'])

Link to logs

---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-14-7304f5f9c25c> in <module>()
      2 builder.download_and_prepare()
      3 dataset = builder.as_dataset("train")
----> 4 for i, example in enumerate(dataset):
      5   if i > 10: break
      6   media.show_image(example['image'])

4 frames
google3/third_party/tensorflow/python/data/ops/iterator_ops.py in __next__(self)
    759   def __next__(self):
    760     try:
--> 761       return self._next_internal()
    762     except errors.OutOfRangeError:
    763       raise StopIteration

google3/third_party/tensorflow/python/data/ops/iterator_ops.py in _next_internal(self)
    745           self._iterator_resource,
    746           output_types=self._flat_output_types,
--> 747           output_shapes=self._flat_output_shapes)
    748 
    749       try:

google3/third_party/tensorflow/python/ops/gen_dataset_ops.py in iterator_get_next(iterator, output_types, output_shapes, name)
   2726       return _result
   2727     except _core._NotOkStatusException as e:
-> 2728       _ops.raise_from_not_ok_status(e, name)
   2729     except _core._FallbackException:
   2730       pass

google3/third_party/tensorflow/python/framework/ops.py in raise_from_not_ok_status(e, name)
   6904   message = e.message + (" name: " + name if name is not None else "")
   6905   # pylint: disable=protected-access
-> 6906   six.raise_from(core._status_to_exception(e.code, message), None)
   6907   # pylint: enable=protected-access
   6908 

google3/third_party/py/six/__init__.py in raise_from(value, from_value)

InvalidArgumentError: Unknown image file format. One of JPEG, PNG, GIF, BMP required.
	 [[{{node decode_image/DecodeImage}}]] [Op:IteratorGetNext]

Expected behavior
Be able to iterate through all classes in LSUN.

Additional context
tf.io.decode_image explicitly does not support WebP.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the LSUN builder's image decoding path and how it calls tf.io.decode_image; compare that with the available tfio.image.decode_webp operation. Reproduce the issue with the provided lsun/car example, then verify that iteration works for all LSUN classes and add regression coverage if the repository has a suitable dataset test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
computer-vision, data, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.