tensorflow / tensorflow/datasets

Under mock_data, a trivial decoder changes the output tensor

Open
#3,754 2 comments 0 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
When tfds.testing.mock_data is active, passing a custom decoder to tfds.load alters the result, even if the decoder doesn't actually change the decoding logic.

Environment information

  • Operating System: Ubuntu 18.04

  • Python version: 3.7.5

  • tensorflow-datasets/tfds-nightly version: tensorflow-datasets 4.5.2

  • tensorflow/tf-nightly version: tensorflow 2.7.0

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

Reproduction instructions

import contextlib
import tensorflow as tf
import tensorflow_datasets as tfds

@tfds.decode.make_decoder()
def no_op_decoder(example, feature):
    return feature.decode_example(example)

with tfds.testing.mock_data():
#with contextlib.nullcontext():
    ds = tfds.load('imagenet_v2', split='test')
    image1 = next(iter(ds))['image']

    ds = tfds.load('imagenet_v2', split='test',
        decoders={'image': no_op_decoder()})
    image2 = next(iter(ds))['image']

    print(tf.reduce_all(image1 == image2).numpy())

Running this prints False, but if you comment the mock_data line and uncomment the nullcontext line, it prints True.

Link to logs
N/A

Expected behavior
It should print True in both cases.

Additional context
N/A

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 with the tfds.testing.mock_data context, tfds.load, and the tfds.decode.make_decoder entry points shown in the reproduction. Compare the two loading paths and add or run a regression test using the no-op decoder; done means both paths produce equal image tensors, as the example expects.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
data, testing
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.