tensorflow / tensorflow/datasets

Support optional tensors

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

Nobody has claimed this yet.

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

Description

TF recently added optional support: https://www.tensorflow.org/api_docs/python/tf/experimental/Optional
It seems to be working inside tf.data:

ds = tf.data.Dataset.range(3)
ds = ds.map(lambda x: tf.experimental.Optional.from_value(x))
list(ds)[0].get_value()

We should update our feature connectors to accept None to return optionals. Maybe with a tfds.features.Optional like

def _info(self):
  features=FeatureDict({
      'image': tfds.features.Optional(tfds.features.Image()),
  })

def _generate_examples(self):
  yield {
      'image': None,  # Accept `None` or feature
  }

Which would returns:

ds = tfds.load()
ds.element_spec = {'image': OptionalSpec(TensorSpec(shape=(None, None, 3), dtype=tf.uint8, name=None),)}

Not clear how this would translate into tf.train.Example spec though.

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 reviewing TFDS feature connectors and the TensorFlow Optional API, then trace how feature values are represented in tf.train.Example. Determine the intended Optional connector behavior for None, including element_spec and serialization, and add coverage for accepted optional values once the representation is decided.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
data, machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.