Convert EagerTensor to Numpy array, throw different types of errors

Hello,
I am trying to convert an EagerTensor to a Numpy array using the code below,

tensor.numpy()
but I got an error, “AttributeError: ‘Tensor’ object has no attribute ‘numpy’”

Also when I used the below code, it shows this error, “NotImplementedError: Cannot convert a symbolic Tensor (concat:0) to a numpy array. This error may indicate that you’re trying to pass a Tensor to a NumPy call, which is not supported”
np.add(tensor,1)

I have searched a lot regarding this error all solutions state that it is related to eager execution is enabled, or the version of numpy. however, I have disabled the eager and downgraded the Numpy but the problem is still firing.

I am trying to implement a CNN model for speech recognition using Cochleagram waveform, I have used the simple speech recognition of TensorFlow, below is my code to run it

def get_cochleagram(waveform):
 input_len = 16000
 waveform = waveform[:input_len]
 zero_padding = tf.zeros([16000] - tf.shape(waveform), dtype=tf.float32)
 waveform = tf.cast(waveform, dtype=tf.float32)
 equal_length = tf.concat([waveform, zero_padding], 0) 
 cochleagram = np.add(equal_length,1) // here I got the error

 cochleagram = cgram.cochleagram(cochleagram, sr = 16000, n=40,low_lim=50, hi_lim=8000, sample_factor=1)
 cochleagram = tf.multiply(cochleagram, 42)
 return cochleagram

All your suggestions are appreciated.

Hi @Fatimah_Alqadheeb could you kindly post your code here. That would be much helpful for debugging.

Thanks, @Atia for your reply, I have updated my question and included my code.

I would suggest you try to output the data type of “equal_length” variable first. This is to check if it can be evaluated. I would suppose its output is a tensor of a certain shape in that case the np.add should work but try that just to ascertain its type first.

Hi @Atia,

This is the type of the equal_length variable.

<class 'tensorflow.python.framework.ops.EagerTensor'>

I have tried replicating you error but mine worked just fine. From what I could dig up, it appears all computations should be in symbolic tensor format. In other words, all computations should be computed as tensors instead of mixing tensors and numpy arrays. I suggest instead of np.add, use the tf equivalent tf.add.