TypeError: 'DType' object is not callable
遇到此类错误,原因是在对tensor进行类型转换时,方法不对导致的。
目前tf2.x上面使用cast函数进行数据类型转换。
例如把float32转int32:
tf.dtypes.cast(x, tf.int32)
def cast(x, dtype, name=None):
"""Casts a tensor to a new type.
The operation casts `x` (in case of `Tensor`) or `x.values`
(in case of `SparseTensor` or `IndexedSlices`) to `dtype`.
For example:
>>> x = tf.constant([1.8, 2.2], dtype=tf.float32)
>>> tf.dtypes.cast(x, tf.int32)
<tf.Tensor: shape=(2,), dtype=int32, numpy=array([1, 2], dtype=int32)>