简体   繁体   中英

AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'ravel'

I got the following error, when I run the program. I attached my error and program as follows. What's wrong with my program?

import random
index=random.randint(0,len(X_test)-1)
samples = X_test[index].ravel()
print("Audio:",classes[np.argmax(y_test[index])])
ipd.Audio(samples, rate=16000)

Any idea what has gone wrong?

You need to enable the numpy behavior for EagerTensor objects. Use the following snippet:

from tensorflow.python.ops.numpy_ops import np_config
np_config.enable_numpy_behavior()

ravel() is a numpy function and can only operate on numpy objects. You can solve this problem by converting X_test into numpy data type eg if X_test is tensor then X_test.numpy() will return you numpy object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM