zl程序教程

您现在的位置是:首页 >  大数据

当前栏目

tf.cast() 数据类型转换

数据 类型转换 TF cast
2023-09-14 09:06:09 时间

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

cast定义:cast(x, dtype, name=None)

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

int32转换为float32:

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

tensorflow中的数据类型列表:


原文链接:https://blog.csdn.net/dcrmg/article/details/79747814