ImageVerifierCode 换一换
格式:DOCX , 页数:19 ,大小:35.97KB ,
资源ID:10982630      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10982630.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(tensorflow基本概念.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

tensorflow基本概念.docx

1、tensorflow基本概念1、tensorflow的基本运作为了快速的熟悉TensorFlow编程,下面从一段简单的代码开始:importtensorflowastf#定义符号变量,也称为占位符 a = tf.placeholder(float) b = tf.placeholder(float) y = tf.mul(a, b) #构造一个op节点sess = tf.Session()#建立会话#运行会话,输入数据,并计算节点,同时打印结果printsess.run(y, feed_dict=a: 3, b: 3)# 任务完成, 关闭会话.sess.close() 1 2 3 4 5 6

2、7 8 9 10 11 12其中tf.mul(a, b)函数便是tf的一个基本的算数运算,接下来介绍跟多的相关函数。2、tf函数TensorFlow 将图形定义转换成分布式执行的操作, 以充分利用可用的计算资源(如 CPU 或 GPU。一般你不需要显式指定使用 CPU 还是 GPU, TensorFlow 能自动检测。如果检测到 GPU, TensorFlow 会尽可能地利用找到的第一个 GPU 来执行操作.并行计算能让代价大的算法计算加速执行,TensorFlow也在实现上对复杂操作进行了有效的改进。大部分核相关的操作都是设备相关的实现,比如GPU。下面是一些重要的操作/核: 1 2 3操作

3、组操作MathsAdd, Sub, Mul, Div, Exp, Log, Greater, Less, EqualArrayConcat, Slice, Split, Constant, Rank, Shape, ShuffleMatrixMatMul, MatrixInverse, MatrixDeterminantNeuronal NetworkSoftMax, Sigmoid, ReLU, Convolution2D, MaxPoolCheckpointingSave, RestoreQueues and syncronizationsEnqueue, Dequeue, MutexAc

4、quire, MutexReleaseFlow controlMerge, Switch, Enter, Leave, NextIterationTensorFlow的算术操作如下:操作描述tf.add(x, y, name=None)求和tf.sub(x, y, name=None)减法tf.mul(x, y, name=None)乘法tf.div(x, y, name=None)除法tf.mod(x, y, name=None)取模tf.abs(x, name=None)求绝对值tf.neg(x, name=None)取负 (y = -x).tf.sign(x, name=None)返回符

5、号 y = sign(x) = -1 if x 0.tf.inv(x, name=None)取反tf.square(x, name=None)计算平方 (y = x * x = x2).tf.round(x, name=None)舍入最接近的整数# a is 0.9, 2.5, 2.3, -4.4tf.round(a) = 1.0, 3.0, 2.0, -4.0 tf.sqrt(x, name=None)开根号 (y = sqrtx = x1/2).tf.pow(x, y, name=None)幂次方# tensor x is 2, 2, 3, 3# tensor y is 8, 16, 2,

6、 3tf.pow(x, y) = 256, 65536, 9, 27tf.exp(x, name=None)计算e的次方tf.log(x, name=None)计算log,一个输入计算e的ln,两输入以第二输入为底tf.maximum(x, y, name=None)返回最大值 (x y ? x : y)tf.minimum(x, y, name=None)返回最小值 (x 1, 2 # dtype=tf.int32 形状操作Shapes and Shaping操作描述tf.shape(input, name=None)返回数据的shape# t is 1, 1, 1, 2, 2, 2, 3,

7、 3, 3, 4, 4, 4shape(t) = 2, 2, 3tf.size(input, name=None)返回数据的元素数量# t is 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4size(t) = 12tf.rank(input, name=None)返回tensor的rank注意:此rank不同于矩阵的rank,tensor的rank表示一个tensor需要的索引数目来唯一表示任何一个元素也就是通常所说的 “order”, “degree”或”ndims”#t is 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4# shape of

8、tensor t is 2, 2, 3rank(t) = 3tf.reshape(tensor, shape, name=None)改变tensor的形状# tensor t is 1, 2, 3, 4, 5, 6, 7, 8, 9# tensor t has shape 9reshape(t, 3, 3) =1, 2, 3,4, 5, 6,7, 8, 9#如果shape有元素-1,表示在该维度打平至一维# -1 将自动推导得为 9:reshape(t, 2, -1) =1, 1, 1, 2, 2, 2, 3, 3, 3,4, 4, 4, 5, 5, 5, 6, 6, 6tf.expand_d

9、ims(input, dim, name=None)插入维度1进入一个tensor中#该操作要求-1-input.dims()# t is a tensor of shape 2shape(expand_dims(t, 0) = 1, 2shape(expand_dims(t, 1) = 2, 1shape(expand_dims(t, -1) = 2, 1 = dim = input.dims() 切片与合并(Slicing and Joining)操作描述tf.slice(input_, begin, size, name=None)对tensor进行切片操作其中sizei = input

10、.dim_size(i) - begini该操作要求 0 = begini = begini + sizei 3, 3, 3tf.slice(input, 1, 0, 0, 1, 2, 3) =3, 3, 3,4, 4, 4tf.slice(input, 1, 0, 0, 2, 1, 3) =3, 3, 3,5, 5, 5tf.split(split_dim, num_split, value, name=split)沿着某一维度将tensor分离为num_split tensors# value is a tensor with shape 5, 30# Split value into 3

11、 tensors along dimension 1split0, split1, split2 = tf.split(1, 3, value)tf.shape(split0) = 5, 10tf.concat(concat_dim, values, name=concat)沿着某一维度连结tensort1 = 1, 2, 3, 4, 5, 6t2 = 7, 8, 9, 10, 11, 12tf.concat(0, t1, t2) = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12tf.concat(1, t1, t2) = 1, 2, 3, 7, 8, 9, 4,

12、 5, 6, 10, 11, 12如果想沿着tensor一新轴连结打包,那么可以:tf.concat(axis, tf.expand_dims(t, axis) for t in tensors)等同于tf.pack(tensors, axis=axis)tf.pack(values, axis=0, name=pack)将一系列rank-R的tensor打包为一个rank-(R+1)的tensor# x is 1, 4, y is 2, 5, z is 3, 6pack(x, y, z) = 1, 4, 2, 5, 3, 6# 沿着第一维packpack(x, y, z, axis=1) =

13、 1, 2, 3, 4, 5, 6等价于tf.pack(x, y, z) = np.asarray(x, y, z)tf.reverse(tensor, dims, name=None)沿着某维度进行序列反转其中dim为列表,元素为bool型,size等于rank(tensor)# tensor t is 0, 1, 2, 3,# 4, 5, 6, 7,# 8, 9, 10, 11,#12, 13, 14, 15,#16, 17, 18, 19,#20, 21, 22, 23# tensor t shape is 1, 2, 3, 4# dims is False, False, False,

14、 Truereverse(t, dims) = 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8,15, 14, 13, 12,19, 18, 17, 16,23, 22, 21, 20tf.transpose(a, perm=None, name=transpose)调换tensor的维度顺序按照列表perm的维度排列调换tensor顺序,如为定义,则perm为(n-10)# x is 1 2 3,4 5 6tf.transpose(x) = 1 4, 2 5,3 6# Equivalentlytf.transpose(x, perm=1, 0) = 1 4,2 5,

15、 3 6tf.gather(params, indices, validate_indices=None, name=None)合并索引indices所指示params中的切片tf.one_hot(indices, depth, on_value=None, off_value=None,axis=None, dtype=None, name=None)indices = 0, 2, -1, 1depth = 3on_value = 5.0off_value = 0.0axis = -1#Then output is 4 x 3:output =5.0 0.0 0.0 / one_hot(0)

16、0.0 0.0 5.0 / one_hot(2)0.0 0.0 0.0 / one_hot(-1)0.0 5.0 0.0 / one_hot(1)矩阵相关运算操作描述tf.diag(diagonal, name=None)返回一个给定对角值的对角tensor# diagonal is 1, 2, 3, 4tf.diag(diagonal) =1, 0, 0, 00, 2, 0, 00, 0, 3, 00, 0, 0, 4tf.diag_part(input, name=None)功能与上面相反tf.trace(x, name=None)求一个2维tensor足迹,即对角值diagonal之和t

17、f.transpose(a, perm=None, name=transpose)调换tensor的维度顺序按照列表perm的维度排列调换tensor顺序,如为定义,则perm为(n-10)# x is 1 2 3,4 5 6tf.transpose(x) = 1 4, 2 5,3 6# Equivalentlytf.transpose(x, perm=1, 0) = 1 4,2 5, 3 6tf.matmul(a, b, transpose_a=False,transpose_b=False, a_is_sparse=False,b_is_sparse=False, name=None)矩阵

18、相乘tf.matrix_determinant(input, name=None)返回方阵的行列式tf.matrix_inverse(input, adjoint=None, name=None)求方阵的逆矩阵,adjoint为True时,计算输入共轭矩阵的逆矩阵tf.cholesky(input, name=None)对输入方阵cholesky分解,即把一个对称正定的矩阵表示成一个下三角矩阵L和其转置的乘积的分解A=LLTtf.matrix_solve(matrix, rhs, adjoint=None, name=None)求解tf.matrix_solve(matrix,rhs, adj

19、oint=None, name=None)matrix为方阵shape为M,M,rhs的shape为M,K,output为M,K复数操作操作描述plex(real, imag, name=None)将两实数转换为复数形式# tensor real is 2.25, 3.25# tensorimagis 4.75, 5.75plex(real, imag) = 2.25 + 4.75j, 3.25 + 5.75jplex_abs(x, name=None)计算复数的绝对值,即长度。# tensor x is -2.25 + 4.75j, -3.25 + 5.75jplex_abs(x) = 5.

20、25594902, 6.60492229tf.conj(input, name=None)计算共轭复数tf.imag(input, name=None)tf.real(input, name=None)提取复数的虚部和实部tf.fft(input, name=None)计算一维的离散傅里叶变换,输入数据类型为complex64归约计算(Reduction)操作描述tf.reduce_sum(input_tensor, reduction_indices=None,keep_dims=False, name=None)计算输入tensor元素的和,或者安照reduction_indices指定的

21、轴进行求和# x is 1, 1, 1# 1, 1, 1tf.reduce_sum(x) = 6tf.reduce_sum(x, 0) = 2, 2, 2tf.reduce_sum(x, 1) = 3, 3tf.reduce_sum(x, 1, keep_dims=True) = 3, 3tf.reduce_sum(x, 0, 1) = 6tf.reduce_prod(input_tensor,reduction_indices=None,keep_dims=False, name=None)计算输入tensor元素的乘积,或者安照reduction_indices指定的轴进行求乘积tf.re

22、duce_min(input_tensor,reduction_indices=None,keep_dims=False, name=None)求tensor中最小值tf.reduce_max(input_tensor,reduction_indices=None,keep_dims=False, name=None)求tensor中最大值tf.reduce_mean(input_tensor,reduction_indices=None,keep_dims=False, name=None)求tensor中平均值tf.reduce_all(input_tensor,reduction_ind

23、ices=None,keep_dims=False, name=None)对tensor中各个元素求逻辑与# x is# True, True# False, Falsetf.reduce_all(x) = Falsetf.reduce_all(x, 0) = False, Falsetf.reduce_all(x, 1) = True, Falsetf.reduce_any(input_tensor,reduction_indices=None,keep_dims=False, name=None)对tensor中各个元素求逻辑或tf.accumulate_n(inputs, shape=N

24、one,tensor_dtype=None, name=None)计算一系列tensor的和# tensor a is 1, 2, 3, 4# tensorbis 5, 0, 0, 6tf.accumulate_n(a, b, a) = 7, 4, 6, 14tf.cumsum(x, axis=0, exclusive=False,reverse=False, name=None)求累积和tf.cumsum(a, b, c) = a, a + b, a + b + ctf.cumsum(a, b, c, exclusive=True) = 0, a, a + btf.cumsum(a, b,

25、c, reverse=True) = a + b + c, b + c, ctf.cumsum(a, b, c, exclusive=True, reverse=True) = b + c, c, 0分割(Segmentation)操作描述tf.segment_sum(data, segment_ids, name=None)根据segment_ids的分段计算各个片段的和其中segment_ids为一个size与data第一维相同的tensor其中id为int型数据,最大id不大于sizec = tf.constant(1,2,3,4, -1,-2,-3,-4, 5,6,7,8)tf.seg

26、ment_sum(c, tf.constant(0, 0, 1)=0 0 0 05 6 7 8上面例子分为0,1两id,对相同id的data相应数据进行求和,并放入结果的相应id中,且segment_ids只升不降tf.segment_prod(data, segment_ids, name=None)根据segment_ids的分段计算各个片段的积tf.segment_min(data, segment_ids, name=None)根据segment_ids的分段计算各个片段的最小值tf.segment_max(data, segment_ids, name=None)根据segment_ids的分段计算各个片段的最大

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1