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的更多相关文章

  1. 深度学习原理与框架-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 ...

  2. tf.split函数的用法(tensorflow1.13.0)

    tf.split(input, num_split, dimension): dimension指输入张量的哪一个维度,如果是0就表示对第0维度进行切割:num_split就是切割的数量,如果是2就表 ...

  3. tensorflow 的tf.split函数的用法

    将张量进行切分 tf.split( value, num_or_size_splits, axis=0, num=None, name='split' ) value: 待切分的张量 num_or_s ...

  4. tf.split

    tf.split(dimension, num_split, input):dimension的意思就是输入张量的哪一个维度,如果是0就表示对第0维度进行切割.num_split就是切割的数量,如果是 ...

  5. 【转载】 tf.split函数的用法

    原文地址: https://blog.csdn.net/uestc_c2_403/article/details/73350457 由于tensorflow 版本更新问题   用法略有修改 ----- ...

  6. 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)#不改 ...

  7. Tensorflow | 基本函数介绍 简单详细的教程。 有用, 很棒

     http://blog.csdn.net/xxzhangx/article/details/54606040 Tensorflow | 基本函数介绍 2017-01-18 23:04 1404人阅读 ...

  8. D3_book 11.2 stack

    <!-- book :interactive data visualization for the web 11.2 stack 一个堆叠图的例子 --> <!DOCTYPE htm ...

  9. GTAC 2015将于11月10号和11号召开

    今年的GTAC注册已经结束,将会在11月10号和11号在Google马萨诸塞州剑桥办公室召开.大家可以关注https://developers.google.com/google-test-autom ...

随机推荐

  1. 使用Jenkins来实现内部的持续集成流程(上)

    前言 Jenkins和TeamCity都是大杀器,用于搭建内部持续集成环境都是妥妥的.本篇主要介绍Jenkins的安装,下篇将介绍相关配置和使用. 目录 安装和配置 第一次启动 插件安装,第一次进入时 ...

  2. HDU 1045 dfs + 回溯

    题目链接:http://acm.hrbust.edu.cn/vj/index.php?/vj/index.php?c=&c=contest-contest&cid=134#proble ...

  3. jsr303 参考表

    下面是主要的验证注解及说明: 注解 适用的数据类型 说明 @AssertFalse Boolean, boolean 验证注解的元素值是false @AssertTrue Boolean, boole ...

  4. FOR UPDATE

    1. for update的使用场景 `如果遇到存在高并发并且对于数据的准确性很有要求的场景,是需要了解和使用for update的.    比如涉及到金钱.库存等.一般这些操作都是很长一串并且是开启 ...

  5. 分析器错误信息: 服务器标记不能包含 <% ... %> 构造

    我的程序如下:<form runat="server"><TABLE><TR><TD>用户名:</TD><TD&g ...

  6. HDU5296 Annoying problem(LCA)

    //#pragma comment(linker, "/STACK:1677721600") #include <map> #include <set> # ...

  7. cocos2dx 安卓真机调试问题汇总

    cocos compile编译apk问题汇总: 1,dx编译报错,没有足够的空间 ANTBUILD : [dx] error : Could not create the Java Virtual M ...

  8. FastAdmin bootstrap-table 分页手动输入跳转

    FastAdmin bootstrap-table 分页手动输入跳转 Bootstrap-Table (V1.11.0)默认是没有这个功能的,不过作者有写的扩展. https://github.com ...

  9. Git自动换行符

    http://blog.csdn.net/jonathan321/article/details/51988242?locationNum=2 不同的操作系统有不同的换行符格式,跨平台协作时需要考虑版 ...

  10. UOJ 54 【WC2014】时空穿梭——莫比乌斯反演

    题目:http://uoj.ac/problem/54 想写20分. Subtask 2 就是枚举4个维度的值的比例,可算对于一个比例有多少个值可以选,然后就是组合数.结果好像不对. 因为模数太小,组 ...