我使用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然后在我的模型上应用fit,我得到了一个错误:
AttributeError:'numpy.dtypefloat64‘对象没有属性'is_floating'
当在目标数据上运行keras.engine.compile_utils.match_dtype_and_rank时,代码会失败,所以我想问题来自我的y张量,但是我不明白为什么它被认为是numpy.dtypefloat64.。
有什么建议吗?
发布于 2022-11-09 16:24:04
可能,x数组中有更大的浮点值,作为float64。但是,我在Google中尝试了TF2.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让我们知道,如果问题仍然存在的一些更多的代码,以复制错误。谢谢。
https://stackoverflow.com/questions/74170725
复制相似问题