Wenli Huang
Wenli Huang

Reputation: 1

AttributeError: module 'tensorflow_core.keras.utils' has no attribute 'audio_dataset_from_directory'

When I tried to run the code below, I got:
AttributeError: module 'tensorflow_core.keras.utils' has no attribute 'audio_dataset_from_directory'

the code:

import tensorflow as tf

BATCH_SIZE = 32
OUTPUT_SEQUENCE_LENGTH = 16000
TRAIN_DATASET = '/dataset/cats_dogs/train'
VALIDATION_DATASET = '/dataset/cats_dogs/test'

class AudioDataLoader():
  def __init__(self):
    pass

  def get_training_dataset_and_class_names(self):
    train_ds = tf.keras.utils.audio_dataset_from_directory(
      TRAIN_DATASET,
      batch_size=BATCH_SIZE,
      output_sequence_length=OUTPUT_SEQUENCE_LENGTH,
      seed=1
    )

dataloader = AudioDataLoader()
train_ds, class_names = dataloader.get_training_dataset_and_class_names()

Actuall, this code is from Kaggle: https://www.kaggle.com/code/ryanburnsworth/audio-classification-dogs-vs-cats/notebook
But when I tried to run the code locally, I took mistake.
My python version is 3.7, and tensorflow == 2.1.0, keras == 2.3.1

What I have done is below:

  1. I have tried to run the code above with tensorflow == 2.2.0, and I got the same error. So I uninstall the tensorflow, and install tensorflow == 2.1.0. as you can see, it didn't work.
  2. I have tried to replace the tf.keras.utils.audio_dataset_from_directory with tf.python.keras.preprocessing.audio_dataset_from_directory, then I got: AttributeError: module 'tensorflow' has no attribute 'python'

Upvotes: 0

Views: 25

Answers (0)

Related Questions