0

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.

wthra
  • 1
  • 1
    Does this answer your question? [Convert a tensor to numpy array in Tensorflow?](https://stackoverflow.com/questions/34097281/convert-a-tensor-to-numpy-array-in-tensorflow) – 0x5453 Sep 08 '22 at 19:46
  • If you are using eager execution you should be able to call `numpy()` directly however if you are using graph execution you will need to register a session and then call `eval()` to convert to numpy array – Shary Sep 08 '22 at 20:11
  • @0x5453 unfortunately no. I will recheck on the data, sense that there's some incompatiblilty. – wthra Sep 13 '22 at 07:31

0 Answers0