首页 技术 正文
技术 2022年11月17日
0 收藏 825 点赞 4,668 浏览 3087 个字

1.  tf.split(3, group, input)  # 拆分函数
    3 表示的是在第三个维度上, group表示拆分的次数, input 表示输入的值

import tensorflow as tf
import numpy as npx = [[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 tfx = [[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 npx = [[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 npraw_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 npraw_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 npraw_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 npraw_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 npraw_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 npraw_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 npa = [[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 tftrain_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 npx = [[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])))
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,075
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,551
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,399
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,811
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,893