[英]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.您需要为
EagerTensor
对象启用numpy
行为。 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. ravel() 是一个numpy function并且只能对 numpy 个对象进行操作。 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.
您可以通过将 X_test 转换为 numpy 数据类型来解决此问题,例如,如果 X_test 是张量,则 X_test.numpy() 将返回 numpy object。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.