Tensorflow 模型拟合:AttributeError:'numpy.dtype[float64]' 对象没有属性 'is_floating'

问题描述 投票:0回答:1

我使用 Tensorflow 2.9.1 开发模型。

我的输入是这样的:

x = [...] # Array of 24 floats
y = 0.0

当我处理这些数据时:

x = tf.convert_to_tensor(x, dtype=tf.float32)
x = tf.reshape(x, shape=(1,24))
x.dtype.is_floating # Is True

y = tf.convert_to_tensor(y, dtype=tf.float32)
y = tf.reshape(y, shape=(1, 1))
y.dtype.is_floating # Is True

然后在我的模型上应用拟合,我收到此错误:

AttributeError:'numpy.dtype [float64]'对象没有属性'is_floating'

在目标数据上运行 keras.engine.compile_utils.match_dtype_and_rank 时代码失败,所以我猜问题来自我的 y 张量,但我不明白为什么它被视为 numpy.dtype[float64]

有什么建议吗?

python numpy tensorflow data-fitting
1个回答
0
投票

可能,x 数组中有较大的浮点值,该值被视为 float64。但是我在 Google Colab 中使用 TF 2.9 尝试了相同的代码,并且没有显示任何错误。

import numpy as np
import tensorflow as tf
x=np.arange(0.0, 24.0)
print(x)
#x = [...] # Array of 24 floats
y = 0.0
print(y)

x = tf.convert_to_tensor(x, dtype=tf.float64) #try using float64 in place of float32
x = tf.reshape(x, shape=(1,24))

x.dtype.is_floating # Is True

输出:

[ 0.  1.  2.  3.  4.  5.  6.  7.  8.  9. 10. 11. 12. 13. 14. 15. 16. 17.
 18. 19. 20. 21. 22. 23.]
0.0
True

以及

y

y = tf.convert_to_tensor(y, dtype=tf.float64)
y = tf.reshape(y, shape=(1, 1))

y.dtype.is_floating # Is True

输出:

True

请告诉我们问题是否仍然存在,并提供更多代码来复制错误。谢谢你。

© www.soinside.com 2019 - 2024. All rights reserved.