Skip to content

Don't import TensorFlow when defining an Audio feature - #11241

Open
raashish1601 wants to merge 1 commit into
tensorflow:masterfrom
raashish1601:fix/11233-audio-lazy-tf-dtype
Open

raashish1601 wants to merge 1 commit into
tensorflow:masterfrom
raashish1601:fix/11233-audio-lazy-tf-dtype

Conversation

@raashish1601

Copy link
Copy Markdown

Fixes #11233.

_AudioDecoder.__init__ called tf.dtypes.as_dtype right away, so just defining a tfds.features.Audio (for example in a builder's _info()) imported TensorFlow. That breaks TensorFlow-free use such as tfds.data_source on audio datasets.

This turns _dtype into a property, so TensorFlow is only used when a decoder actually needs the TF dtype.

Tests: added test_construction_does_not_use_tensorflow. I couldn't run the TF test files locally (TensorFlow doesn't import on native Windows here), but in an environment without TensorFlow tfds.features.Audio(sample_rate=16000) raises ModuleNotFoundError before this change and works after it.

@google-cla

google-cla Bot commented Oct 6, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tfds.features.Audio eagerly imports TensorFlow in _AudioDecoder.__init__, breaking TensorFlow-less usage

1 participant