Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#11,233 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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.

  • #11241 của @raashish1601 — đang mở
  • #11242 của @rootkiller6788 — đang mở

Đá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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tensorflow/datasets

Tất cả issue của tensorflow/datasets

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.