我是靠谱客的博主 清秀大船,这篇文章主要介绍tf.cast()数据类型转换,现在分享给大家,希望可以做个参考。

tf.cast()数据类型转换函数

tf.cast()函数的作用是执行tensorflow中张量数据类型转换,将图片数据类型为int8类型的,转换为float32。

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

x:被转换的数据(张量)
dtype:目标数据类型
name:可选参数,定义操作名称

int32转换为float32:

import tensorflow as tf
import numpy as np

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

print('t1:{}'.format(t1))
print('t2:{}'.format(t2))

输出结果:
t1:<tf.Variable ‘Variable:0’ shape=(5,) dtype=int32, numpy=array([1, 2, 3, 4, 5])>
t2:[1. 2. 3. 4. 5.]



最后

以上就是清秀大船最近收集整理的关于tf.cast()数据类型转换的全部内容,更多相关tf内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(154)

评论列表共有 0 条评论

立即
投稿
返回
顶部