Problem mapping data (AttributeError: 'Tensor' object has no attribute 'numpy')

Viewed 33

I try to map the data into the function that creates mfcc spectrogram. It says that

WARNING:tensorflow:Using a while_loop for converting IO>AudioResample
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-83-e7ba252d97b5> in <module>
----> 1 data = data.map(preprocess)

10 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/autograph/impl/api.py in wrapper(*args, **kwargs)
    690       except Exception as e:  # pylint:disable=broad-except
    691         if hasattr(e, 'ag_error_metadata'):
--> 692           raise e.ag_error_metadata.to_exception(e)
    693         else:
    694           raise

AttributeError: in user code:

    File "<ipython-input-29-2d6c4d8abe96>", line 4, in preprocess  *
        wav = wav.numpy()

    AttributeError: 'Tensor' object has no attribute 'numpy'

Here's the code

def preprocess(file_path, label): 
    wav = load_wav_16k_mono(file_path)
    wav = wav[:56320]
    wav = wav.numpy()
    mfccs = librosa.feature.mfcc(wav, sr =new_sr)
    mfccs = sklearn.preprocessing.scale(mfccs, axis=1)
    mfccs = tf.convert_to_tensor(mfccs)
    return mfccs, label

the data is a concatenated tensorflow dataset

<ConcatenateDataset element_spec=(TensorSpec(shape=(), dtype=tf.string, name=None), TensorSpec(shape=(), dtype=tf.float32, name=None))>

I suspect that the problem is caused by the line

wav = wav.numpy()

because it works when I removed it. The thing is I need to use this line because librosa only accepted numpy array.

I already set run functions eagerly as True on top of the program.

0 Answers
Related