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 ...
随机推荐
- web sql 基本操作 - 增删改查
不喜欢看md原文的 可以访问这个链接:http://note.youdao.com/noteshare?id=6a91e3dea7cdf5195bb0e851d9fcb5a5 # web sql 增删 ...
- 【css】 文本超出2行显示省略号
首先,要知道css的三条属性. overflow:hidden; //超出的文本隐藏 text-overflow:ellipsis; //溢出用省略号显示 white-space:nowrap; // ...
- WIN8.1 PRO RTM VOL.2013.09.18
文件名:cn_windows_8_1_pro_vl_x64_dvd_2791218.isoSHA1:61C002551763E22B64EB1BACEFFE83620114C3D6 文件名:cn_wi ...
- L185 Ocean Shock
This is part of "Ocean Shock," a Reuters series exploring climate change's impact on sea c ...
- DDMS介绍
DDMS全称:Dalvik Debug Monitor Service 一,DDMS的作用 它提供了截屏.查看线程和堆信息.logcat.进程.广播状态信息.模拟来电呼叫和短信.虚拟地理坐标等等. 二 ...
- Ethereum以太网搭建本地开放环境简明教程
引言: 区块链技术的风起云涌预示着一个去中心化时代的来临,ethereum技术栈是目前业界最为应用广泛的基于区块链技术的技术方案,本文将记录如何基于本地环境来搭建私有区块链的开发环境. 部署私有区块链 ...
- js 判断哪个获得焦点
if(document.activeElement.id="txtIdHouse") { } var xx = document.activeElement.id; xx就是现 ...
- 第11课 enum,sizeof,typedef分析
枚举类型的使用方法: enum的地位和struct是相等的,enum主要用来根据需要定义一些离散的值. 枚举类型的特殊意义: 工程中常用无名枚举来定义常量. 程序示例: #include <st ...
- BZOJ3207: 花神的嘲讽计划Ⅰ(hash)
3207: 花神的嘲讽计划Ⅰ Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3569 Solved: 1258[Submit][Status][Di ...
- DELL E7240超极本
一.图片展示 1.整体图 2.扩展坞的后卡槽附带挡板 3.电源线 4.边框指示灯 5.平躺展示摄像头 二.参数配置 1.i5的 2.i7的 3.手写 处理器:英特尔四代处理器 i7-4600U双 ...