tensorflow 基本函数(1.tf.split, 2.tf.concat,3.tf.squeeze, 4.tf.less_equal, 5.tf.where, 6.tf.gather, 7.tf.cast, 8.tf.expand_dims, 9.tf.argmax, 10.tf.reshape, 11.tf.stack, 12tf.less, 13.tf.boolean_mask
1. tf.split(3, group, input) # 拆分函数
3 表示的是在第三个维度上, group表示拆分的次数, input 表示输入的值
import tensorflow as tf
import numpy as np x = [[1, 2], [3, 4]]
Y = tf.split(axis=1, num_or_size_splits=2, value=x) sess = tf.Session()
for y in Y:
print(sess.run(y))
2. tf.concat(3, input) # 串接函数
3 表示的是在第三个维度上, input表示的是输入,输入一般都是列表
import tensorflow as tf x = [[1, 2], [3, 4]]
y = tf.concat(x, axis=0) sess = tf.Session()
print(sess.run(y))
3. tf.squeeze(input, squeeze_dims=[1, 2]) # 表示的是去除列数为1的维度, squeeze_dim 指定维度
import tensorflow as tf
import numpy as np x = [[1, 2]]
print(np.array(x).shape)
y = tf.squeeze(x, axis=[0]) sess = tf.Session() print(sess.run(y))
4. tf.less_equal(a, b) a 可以是一个列表, b表示需要比较的数,如果比b大返回false,否者返回True
import tensorflow as tf
import numpy as np raw_gt = [1, 2, 3, 4] y = tf.where(tf.less_equal(raw_gt, 2)) sess = tf.Session() print(sess.run(y))
5.tf.where(input) # 返回是真的序号,通过tf.where找出小于等于2的数的序号
import tensorflow as tf
import numpy as np raw_gt = [1, 2, 3, 4] y = tf.where(tf.less_equal(raw_gt, 2)) sess = tf.Session()
print(sess.run(y))
6. tf.gather # 根据序列号对数据进行取值,输入的是input, index
import tensorflow as tf
import numpy as np raw_gt = [3, 4, 5, 6] y = tf.gather(raw_gt, [[0], [1]]) sess = tf.Session()
print(sess.run(y))
7. tf.cast(input, tf.float32) # 主要目的是进行数值类型转换
import tensorflow as tf
import numpy as np raw_gt = [3.0, 4.0, 5.0, 6.0] y = tf.cast(raw_gt, tf.int32) sess = tf.Session()
print(sess.run(y))
8. tf.expand_dims(input, axis=1) # 进行矩阵维度的扩增
import tensorflow as tf
import numpy as np raw_gt = [3.0, 4.0, 5.0, 6.0] y = tf.expand_dims(raw_gt, axis=1) sess = tf.Session()
print(sess.run(tf.shape(y)))
9. tf.argmax(input, axis=1) 根据维度找出这个维度下的最大值的序号, axis=0 表示找出每一行中的最大值, axis=1,表示找出每一列的最大值
import tensorflow as tf
import numpy as np raw_gt = [[3.0, 4.0], [5.0, 3]] y = tf.argmax(raw_gt, axis=1) sess = tf.Session()
print(sess.run(y))
1o. tf.reshape(input, shape) # tf.reshape主要用于数据的shape重新组合
import tensorflow as tf
import numpy as np a = [[1, 2], [3, 4]]
y = tf.reshape(a, [-1, 4]) sess = tf.Session()
print(sess.run(y))
11. tf.stack(input, axis) # 进行数据的拼接,为了去除一个维度
import tensorflow as tf
distort_left_right_random = tf.random_uniform([1], 0, 1.0, dtype=tf.float32)[0]
mirror = tf.less(tf.stack([1.0, 0.8, 1.0]), 0.5)
sess = tf.Session()
print(sess.run(mirror))
mirror = tf.boolean_mask([0, 1, 2], mirror) sess = tf.Session()
print(sess.run(mirror))
12.tf.less(a, b) # 如果a小于b返回True
13.tf.boolean_mask # 找出数据中是True的位置
mirror = tf.boolean_mask([0, 1, 2], [True, False, False]) sess = tf.Session()
print(sess.run(mirror))
13 tf.slice # 根据给出的起始位置进行数据的抽取
# tf.slice
# import tensorflow as tf
# import numpy as np
# x=[[1,2,3],[4,5,6]]
# y=np.arange(24).reshape([2,3,4])
# z=tf.constant([[[1,2,3],[4,5,6]], [[7,8,9],[10,11,12]], [[13,14,15],[16,17,18]]])
# sess=tf.Session()
# begin_x=[1,0] #第一个1,决定了从x的第二行[4,5,6]开始,第二个0,决定了从[4,5,6] 中的4开始抽取
# size_x=[1,2] # 第一个1决定了,从第二行以起始位置抽取1行,也就是只抽取[4,5,6] 这一行,在这一行中从4开始抽取2个元素
# out=tf.slice(x,begin_x,size_x)
# print(sess.run(out))
14 .tf.reduce_sum(input) 表示将所有的进行相加
15 .tf.gfile.MakeDirs(train_dir) # 根据train_dir创建文件夹
import tensorflow as tf train_dir = 'make/'
tf.gfile.MakeDirs(train_dir)
16. tf.gfile.IsDirectory(train_dir) # 判断是否是文件夹
if tf.gfile.IsDirectory(train_dir):
print('')
else:
print('')
17.tf.transpose(input, [1, 0]) # 表示将第一维的大小与第二维度进行调换
import tensorflow as tf
import numpy as np x = [[1, 2, 3, 4], [1, 2, 4, 3]]
print(np.shape(x))
sess = tf.Session()
# 进行维度的变化,perm表示将第一二维度转换为第一个维度
print(sess.run(tf.transpose(x, perm=[1, 0])))
tensorflow 基本函数(1.tf.split, 2.tf.concat,3.tf.squeeze, 4.tf.less_equal, 5.tf.where, 6.tf.gather, 7.tf.cast, 8.tf.expand_dims, 9.tf.argmax, 10.tf.reshape, 11.tf.stack, 12tf.less, 13.tf.boolean_mask的更多相关文章
- 深度学习原理与框架-Alexnet(迁移学习代码) 1.sys.argv[1:](控制台输入的参数获取第二个参数开始) 2.tf.split(对数据进行切分操作) 3.tf.concat(对数据进行合并操作) 4.tf.variable_scope(指定w的使用范围) 5.tf.get_variable(构造和获得参数) 6.np.load(加载.npy文件)
1. sys.argv[1:] # 在控制台进行参数的输入时,只使用第二个参数以后的数据 参数说明:控制台的输入:python test.py what, 使用sys.argv[1:],那么将获得w ...
- tf.split函数的用法(tensorflow1.13.0)
tf.split(input, num_split, dimension): dimension指输入张量的哪一个维度,如果是0就表示对第0维度进行切割:num_split就是切割的数量,如果是2就表 ...
- tensorflow 的tf.split函数的用法
将张量进行切分 tf.split( value, num_or_size_splits, axis=0, num=None, name='split' ) value: 待切分的张量 num_or_s ...
- tf.split
tf.split(dimension, num_split, input):dimension的意思就是输入张量的哪一个维度,如果是0就表示对第0维度进行切割.num_split就是切割的数量,如果是 ...
- 【转载】 tf.split函数的用法
原文地址: https://blog.csdn.net/uestc_c2_403/article/details/73350457 由于tensorflow 版本更新问题 用法略有修改 ----- ...
- tf.split( )和tf.unstack( )
import tensorflow as tf A = [[1, 2, 3], [4, 5, 6]] a0 = tf.split(A, num_or_size_splits=3, axis=1)#不改 ...
- Tensorflow | 基本函数介绍 简单详细的教程。 有用, 很棒
http://blog.csdn.net/xxzhangx/article/details/54606040 Tensorflow | 基本函数介绍 2017-01-18 23:04 1404人阅读 ...
- D3_book 11.2 stack
<!-- book :interactive data visualization for the web 11.2 stack 一个堆叠图的例子 --> <!DOCTYPE htm ...
- GTAC 2015将于11月10号和11号召开
今年的GTAC注册已经结束,将会在11月10号和11号在Google马萨诸塞州剑桥办公室召开.大家可以关注https://developers.google.com/google-test-autom ...
随机推荐
- 转载 ORACLE中实现表变量的方法
源文地址:http://blog.itpub.net/750077/viewspace-2134222/ 经常看到SQLSERVER 中用表变量类型的方式就能做到缓存一个比较大的中间结果, 然后再对这 ...
- halcon之共线连接union_collinear_contours_xld
union_collinear_contours_xld 很多时候当我们用edges_sub_pix, threshold_sub_pix 等算子得到边缘后,因为有噪声.物体本身断裂等原因 很多边缘 ...
- 重构 demo篇
本文背景为学习重构一书中的一些信息的记录. 该篇以一个影片租赁为背景.通过一层层的重构,最终实现相对来说比较完美的代码. 文中经典语句摘要: “如果它没有坏,就不要动它 .” 用来形容我们工作中一些比 ...
- New Concept English Two 15 37
listening speaking reading writing and translating $课文35 捉贼! 355. Roy Trenton used to drive a taxi. ...
- pandas groupby 使用
so useful~ refer to: http://kekefund.com/2016/06/17/pandas-groupby/
- prisma graphql 集成timescaledb
prisma 官方文档说明了因为支持pg 所以相关的timescaledb.cockroachdb 应该也是支持的 但是测试之后timescaledb 支持cockroachdb有问题(事务处理模型支 ...
- Oracle Client 10g (instantclient) 精简版安装
今天遇到个软件要求安装oracle client端,于是考虑装精简版本的,就从http://www.oracle.com/technology/software/tech/oci/instantcli ...
- 【转】linux中inittab文件详解
原文网址:http://www.2cto.com/os/201108/98426.html linux中inittab文件详解 init的进程号是1(ps -aux | less),从这一点就能看出, ...
- C语言:宽字符集操作函数(unicode编码)
C语言:宽字符集操作函数(unicode编码) 字符分类: 宽字符函数 普通C函数描述 iswalnum() isalnum() 测试字符是否为数字或字母 iswalpha() isalpha() 测 ...
- PAT 甲级 1008 Elevator (20)(20 分)模拟水题
题目翻译: 1008.电梯 在我们的城市里,最高的建筑物里只有一部电梯.有一份由N个正数组成的请求列表.这些数表示电梯将会以规定的顺序在哪些楼层停下.电梯升高一层需要6秒,下降一层需要4秒.每次停下电 ...