简体   繁体   English

AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object 没有属性 'ravel'

[英]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.

相关问题 &#39;tensorflow.python.framework.ops.EagerTensor&#39; 对象没有属性 &#39;squeeze&#39; - 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'squeeze' AttributeError: &#39;tensorflow.python.framework.ops.EagerTensor&#39; 对象没有属性 &#39;to_tensor&#39; - AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'to_tensor' AttributeError: &#39;tensorflow.python.framework.ops.EagerTensor&#39; 对象没有属性 &#39;decode&#39; - AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'decode' AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object 没有属性 'assign' - AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'assign' 'tensorflow.python.framework.ops.EagerTensor' object 没有属性 '_in_graph_mode' - 'tensorflow.python.framework.ops.EagerTensor' object has no attribute '_in_graph_mode' 类型 &#39;tensorflow.python.framework.ops.EagerTensor&#39; 没有 len() - type 'tensorflow.python.framework.ops.EagerTensor' has no len() 项目分配 Tensorflow 2.0 - TypeError: 'tensorflow.python.framework.ops.EagerTensor' object 不支持项目分配 - Item Assignment Tensorflow 2.0 - TypeError: 'tensorflow.python.framework.ops.EagerTensor' object does not support item assignment TypeError: &#39;tensorflow.python.framework.ops.EagerTensor&#39; 对象不支持项目分配 - TypeError: 'tensorflow.python.framework.ops.EagerTensor' object does not support item assignment 类型错误:<tf.tensor: shape ...> 有类型<class 'tensorflow.python.framework.ops.eagertensor'> ,但预期其中之一:(<class 'int'> ,)</class></class></tf.tensor:> - TypeError: <tf.Tensor: shape ... > has type <class 'tensorflow.python.framework.ops.EagerTensor'>, but expected one of: (<class 'int'>,) 类型错误: <tf.tensor ... has type <class 'tensorflow.python.framework.ops.eagertensor'> ,但期望其中之一:numbers.Real</tf.tensor> - TypeError: <tf.Tensor ... has type <class 'tensorflow.python.framework.ops.EagerTensor'>, but expected one of: numbers.Real
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM