tf函数总结(一)
来源:互联网 发布:php类与对象做出兔子 编辑:程序博客网 时间:2024/05/25 21:35
1、tf.concat
concat( values, axis, name='concat')
将一组张量沿某一维度连接起来。当axis=i时,如果values[i].shape=[d1,d2, ....,daxis[i], ..., dn],则连接后的张量维度为[d1,d2,..., Raxis,...,dn],其中Raxis=sum(daxis[i]),这就是输入的张量数据沿着某一维度连接。
t1 = [[1, 2, 3], [4, 5, 6]]t2 = [[7, 8, 9], [10, 11, 12]]tf.concat([t1, t2], 0) ==> [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]tf.concat([t1, t2], 1) ==> [[1, 2, 3, 7, 8, 9], [4, 5, 6, 10, 11, 12]]# tensor t3 with shape [2, 3]# tensor t4 with shape [2, 3]tf.shape(tf.concat([t3, t4], 0)) ==> [4, 3]tf.shape(tf.concat([t3, t4], 1)) ==> [2, 6]
2、tf.split
split( value, num_or_size_splits, axis=0, num=None, name='split')
将一个张量分开成多个子张量如果num_or_size_splits是一个整数为num_splits,则会将value沿着axis维度分为num_splits个子张量,如果不为整数可以是一个一维张量,将axis维度分为len(num_splits)个子张量,每个子张量在axis的维度上等于num_splits[i]
# 'value' is a tensor with shape [5, 30]# Split 'value' into 3 tensors with sizes [4, 15, 11] along dimension 1split0, split1, split2 = tf.split(value, [4, 15, 11], 1)tf.shape(split0) ==> [5, 4]tf.shape(split1) ==> [5, 15]tf.shape(split2) ==> [5, 11]# Split 'value' into 3 tensors along dimension 1split0, split1, split2 = tf.split(value, num_or_size_splits=3, axis=1)tf.shape(split0) ==> [5, 10]
3、tf.expand_dimsexpand_dims( input, axis=None, name=None, dim=None)
axis为增加维度的位置,0表示第一个位置,如果是负数,则从后面计算,如-1表示从最后位置增加一个维度。
# 't' is a tensor of shape [2]shape(expand_dims(t, 0)) ==> [1, 2]shape(expand_dims(t, 1)) ==> [2, 1]shape(expand_dims(t, -1)) ==> [2, 1]# 't2' is a tensor of shape [2, 3, 5]shape(expand_dims(t2, 0)) ==> [1, 2, 3, 5]shape(expand_dims(t2, 2)) ==> [2, 3, 1, 5]shape(expand_dims(t2, 3)) ==> [2, 3, 5, 1]
4、tf.constantconstant( value, dtype=None, shape=None, name='Const', verify_shape=False)
创建一个常亮的张量其中value给出常亮的值,dtype和shape都是可选的,如果不指定则以value的准。
tensor = tf.constant([1, 2, 3, 4, 5, 6, 7]) => [1 2 3 4 5 6 7]
tensor = tf.constant(-1.0, shape=[2, 3]) => [[-1. -1. -1.] [-1. -1. -1.]]
5、tf.placeholder_with_default
placeholder_with_default( input, shape, name=None)
创建一个placeholder操作,如果在输出时没有给feed,则以input为值tf.placeholder_with_default(tf.constant(1.0),shape=[], name='use_dropout')
6、tf.global_variables
返回去全局变量。全局变量指的是在分布式环境中可以跨机器进行共享的变量。通过Variable()构造函数或get_variable()创建的新变量会自动添加到图的集合GraphKeys.GLOBAL_VARIABLES中,这个函数可以方便的返回这个集合的内容。
阅读全文
0 0
- tf函数总结(一)
- tf.nn函数总结
- tf教程(一):Introduction to tf
- TensorFlow 学习(一)—— tf.get_variable() vs tf.Variable(),tf.name_scope() vs tf.variable_scope()
- tf函数
- tensorflow(学习一)中的tf.app.flags函数定义命令行参数
- TF新手使用教程(一)
- Halcon函数总结(一)
- ITween函数总结(一)
- ThinkPHP函数总结(一)
- 学习tf.sparse_to_dense函数(代码实现)
- Tensorflow函数——tf.variable_scope()
- 自然语言处理模型(一):一文读懂TF-IDF
- TF-IDF计算一
- TF-IDF算法总结
- SD、TF、MMC总结
- 学习ROS笔记之TF——learning tf(一)
- 常用tf函数汇总
- 小总结
- codeforces 779C Dishonest Sellers
- HDU5809(KD-tree)
- BZOJ 2434 阿狸的打字机 补全AC自动机 ( Trie图 ) fail树 树状数组 DFS序列
- css3只让背景旋转
- tf函数总结(一)
- Fragment 实现底部导航栏的简单切换
- 【项目实战】自监控-08-DataFrame行列操作(下篇)
- day10 hashmap hashtable treemap等
- Android6.0 在framwoard 层系统拦截HOME键
- sql*plus
- 布局常用标签名
- BLUENESSG 早一日受苦、早一日解决、早一日浴火重生 Maven多模块,Dubbo分布式服务框架,SpringMVC,前后端分离项目,基础搭建,搭建过程出现的问题
- N皇后