TensorFlow 数据类型转换 cast

tf.cast()函数的作用是执行 tensorflow 中张量数据类型转换,比如读入的图片如果是int8类型的,一般在要在训练前把图像的数据格式转换为float32。

cast定义:

1
cast(x, dtype, name=None)
  • 第一个参数 x: 待转换的数据(张量)
  • 第二个参数 dtype: 目标数据类型
  • 第三个参数 name: 可选参数,定义操作的名称

用法:

1
2
t1 = tf.Variable([1,2,3,4,5])
t2 = tf.cast(t1,dtype=tf.float32)

TensorFlow 中数据类型列表:

数据类型列表

原文链接:
https://blog.csdn.net/abc13526222160/article/details/86299106