tfds.features.Audio eagerly imports TensorFlow in _AudioDecoder.__init__, breaking TensorFlow-less usage
Maintainer thường phản hồi trong vòng 1 ngày
@raashish1601 đang làm issue này rồi.
Từ ngày 6/10/2026.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 76/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- data, machine-learning
Hướng nghiên cứu
Bắt đầu trong tensorflow_datasets/core/features/audio_feature.py tại _AudioDecoder.init và theo dõi cách _LazyDecoder.decode_audio sử dụng _dtype. Xác minh rằng việc khởi tạo tfds.features.Audio và tfds.builder("librispeech") hoạt động mà không cần TensorFlow, trong khi việc giải mã âm thanh vẫn xử lý dtype khi TensorFlow khả dụng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
TFDS supports TensorFlow-less dataset reading (e.g. via tfds.data_source with JAX, PyTorch, or Grain). However, constructing any dataset containing an audio feature (such as librispeech) or directly instantiating tfds.features.Audio fails with ModuleNotFoundError: No module named 'tensorflow' in an environment without TensorFlow.
Root Cause
In tensorflow_datasets/core/features/audio_feature.py, _AudioDecoder.__init__ eagerly evaluates tf.dtypes.as_dtype:
class _AudioDecoder(abc.ABC):
def __init__(self, file_format: Optional[str], np_dtype: np.dtype, shape: utils.Shape):
self._file_format = file_format
self._np_dtype = np_dtype
self._dtype = tf.dtypes.as_dtype(self._np_dtype) # <--- Forces import of lazy tf module
self._shape = shape
self._channels = shape[1] if len(shape) > 1 else 1
Because tf is lazily imported via etils.epy.lazy_imports, accessing tf.dtypes triggers import tensorflow immediately during feature specification construction in _info(), even when only reading NumPy arrays.
Minimal Reproduction
In a virtual environment with only tensorflow-datasets installed (no tensorflow):
import tensorflow_datasets as tfds
# Fails with ModuleNotFoundError: No module named 'tensorflow'
tfds.features.Audio(sample_rate=16000)
# Or:
tfds.builder("librispeech")
Minimal Workaround
Monkeypatch _AudioDecoder.__init__ before importing tfds:
import tensorflow_datasets.core.features.audio_feature as af
def _patched_init(self, file_format, np_dtype, shape):
self._file_format = file_format
self._np_dtype = np_dtype
self._dtype = None
self._shape = shape
self._channels = shape[1] if len(shape) > 1 else 1
af._AudioDecoder.__init__ = _patched_init
import tensorflow_datasets as tfds
# Now succeeds without TensorFlow installed:
ds = tfds.data_source("librispeech", split="train_clean100")
Suggested Fix
Make _dtype a lazy property or defer tf.dtypes.as_dtype to _LazyDecoder.decode_audio, where TensorFlow tensors are actually consumed:
@property
def _dtype(self):
return tf.dtypes.as_dtype(self._np_dtype)
- Ngôn ngữ chính
- Python
- Star
- 4.6k
- Fork
- 1.6k
- Merge trung bình
- 9 giờ
- Pull request đã merge (30 ngày)
- 8
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của tensorflow/datasets
-
DatasetInfo.read_from_directory reads the deprecated FieldDescriptor.label eagerly, warning on every openCó thể đã có người làm @jabrailkhalil đã nhận 12 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
tensorflow/datasets#11245 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
required dependency on importlib_resources missingCó thể đã có người làm @ArS377 đã nhận 92 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
tensorflow/datasets#11212 · 2 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
dataset request
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
tensorflow/datasets#11228 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
QM9 download links are brokenCó thể đã có người làm @mylonasc đã nhận 130 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 55/100
tensorflow/datasets#11210 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 1/100
tensorflow/datasets#11196 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của tensorflow/datasets
Issue tương tự
-
Project submission:Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
slavakurilyak/awesome-ai-agents#845 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tests: pin that the atomic writers in utils/paths.py stage the temporary file in the target's directoryCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởdifficulty:2 enhancement good first issue
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 92/100
MakazhanAlpamys/Soup#2178 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] dcg.waggr permutation p-values are folded twice, so near-zero scores get the smallest p-valuesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
scverse/rapids-singlecell#854 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Slang input: int8_t4_packed and uint8_t4_packed are copied into CrossGLCó thể đã có người làm @ninglinLiu đã nhận hôm nay. Đang mởarea:frontend backend:slang bug direction:input
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
random_elements(unique=True) on an OrderedDict: ZeroDivisionError once only zero weights remain, AssertionError with use_weighting=FalseCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 13 ngày