
Tensorflow
学习笔记
菜小白—NLP
这个作者很懒,什么都没留下…
展开
-
TensorFlow中expand_dim()
expand_dim():作用:使用tf.expand_dims(input, axis=None, name=None, dim=None)函数来给矩阵增加一个维度。例子:# 't' is a tensor of shape [2]shape(expand_dims(t, 0)) ==> [1, 2]shape(expand_dims(t, 1)) ==> [2, 1...原创 2019-02-17 12:48:45 · 1148 阅读 · 0 评论 -
tensorflow中tf.gather
tf.gather:函数原型:tf.gather( params, indices, validate_indices=None, name=None, axis=0)说明:根据indices中的索引从params中取出响应的元素来替换掉索引形成张量返回。例子:import tensorflow as tfa = tf.Variable...原创 2019-03-25 14:59:40 · 459 阅读 · 0 评论 -
tensorflow的乘法与转置: tf.multiply,tf.matmul和tf.transpose()
tf.multiply:函数原型:tf.math.multiply( x, y, name=None)说明:作用:对应元素相乘,并且具有广播作用。x: 类型为:half, float32, float64, uint8, int8, uint16, int16, int32, int64, complex64, complex128的张量。y: 类型跟...原创 2019-03-25 14:50:11 · 2480 阅读 · 0 评论 -
tensorflow中去上下三角矩阵:matrix_band_part 和tf.linalg.band_part
tf.linalg.band_part新版本:tf.matrix_band_part变成tf.linalg.band_par函数原型:tf.linalg.band_part( input, num_lower, num_upper, name=None)参数:作用:主要功能是以对角线为中心,取它的副对角线部分,其他部分用0填充。input:输入...原创 2019-03-25 11:47:52 · 9449 阅读 · 4 评论 -
tensorflow中的求和:tf.reduce_sum
tf.reduce_sum函数原型:tf.math.reduce_sum( input_tensor, axis=None, keepdims=None, name=None, reduction_indices=None, keep_dims=None)参数:input_tensor:需要求和的张量axis:指定求和的轴keep_...原创 2019-03-25 11:33:50 · 8546 阅读 · 0 评论 -
tensorflow中的平均值:tf.reduce_mean
tf.reduce_mean函数原型:tf.math.reduce_mean( input_tensor, axis=None, keepdims=None, name=None, reduction_indices=None, keep_dims=None)参数:input_tensor:需要求平均值的张量axis:指定求平均值的轴...原创 2019-03-25 11:24:25 · 2430 阅读 · 0 评论 -
tensorflow中的交叉熵之:tf.nn.sparse_softmax_cross_entropy_with_logits
tf.nn.sparse_softmax_cross_entropy_with_logits官方链接函数原型:tf.nn.sparse_softmax_cross_entropy_with_logits( _sentinel=None, labels=None, logits=None, name=None)参数说明:labels:一个长度为batc...原创 2019-03-25 11:03:03 · 1965 阅读 · 3 评论 -
tensorflow中的mask:tf.sequence_mask
tf.sequence_mask:函数原型:sequence_mask( lengths, maxlen=None, dtype=tf.bool, name=None)例子:import tensorflow as tfa = tf.sequence_mask([1, 2, 3], 4)b = tf.sequence_mask([[1, 2], [3...原创 2019-03-24 18:26:15 · 1993 阅读 · 0 评论 -
tensorflow中TensorBoard用法:
TensorBoard 工作原理:简单来说,TensorBoard 是通过一些操作(summary operations)将数据记录到文件(event files)中,然后再读取文件来完成作图的。工作步骤:Summary:对需要可视化的变量进行summary操作,以记录变量的日志信息。Merge:使用 tf.summary.merge_all 来将定义的多个summary操作聚合成一个...原创 2019-02-17 14:20:08 · 1625 阅读 · 1 评论 -
tf.train.AdamOptimizer
tf.train.AdamOptimizer作用:实现Adam算法的优化器函数原型:__init__( learning_rate=0.001, beta1=0.9, beta2=0.999, epsilon=1e-08, use_locking=False, name='Adam')方法:compute_gradients( ...原创 2019-02-17 13:34:08 · 1771 阅读 · 0 评论 -
tf.nn.softmax_cross_entropy_with_logits()
tf.nn.softmax_cross_entropy_with_logits函数原型:tf.nn.softmax_cross_entropy_with_logits(_sentinel=None,labels=None, logits=None, dim=-1, name=None)参数:logits:就是神经网络最后一层的输出,如果有batch的话,它的大小就是[batchs...原创 2019-02-17 13:30:09 · 230 阅读 · 0 评论 -
tf.argmax()
tf.argmax()函数原型:tf.argmax(input,axis=None,name=None,dimension=None, output_type=tf.int64)作用:返回最大值索引例子:import tensorflow as tfb = tf.constant([[1,2,3],[3,2,1],[4,5,6],[6,5,4]])c=tf.argmax(b...原创 2019-02-17 13:27:26 · 188 阅读 · 0 评论 -
tf.nn.xw_plus_b()
tf.nn.xw_plus_b()函数原型:tf.nn.xw_plus_b(x, weights, biases, name=None)作用:matmul(x, weights) + biases原创 2019-02-17 13:21:40 · 352 阅读 · 0 评论 -
tf.nn.l2_loss()
tf.nn.l2_loss()函数原型:tf.nn.l2_loss(t, name=None)作用:计算张量t的L2范数,但是没有开方并而是除2,具体如下:L2=12∗∑i=1nti2L_2=\frac{1}{2}*\sum_{i=1}^{n}t_i^2L2=21∗i=1∑nti2...原创 2019-02-17 13:17:36 · 645 阅读 · 0 评论 -
tf.concat
tf.concat:函数原型:tf.concat(values,axis,name='concat')作用:按指定轴(axis)进行张量连接操作(Concatenates Tensors)合并方式:将axis指定维度上的元素进行合并即增加axis维度元素例子:import tensorflow as tft1 = [[1, 2, 3], [4, 5, 6]]t2 =...原创 2019-02-17 13:10:31 · 153 阅读 · 0 评论 -
tf.nn.max_pool()
tf.nn.max_pool()函数原型:tf.nn.max_pool(value,ksize,strides,padding,data_format='NHWC', name=None)参数:value:需要池化的输入,一般池化层链接在卷积层的后面,所以输入通常是feature map,形状为:[batch,height,width,channels]。ksize:池化窗口的...原创 2019-02-17 12:56:07 · 408 阅读 · 0 评论 -
tf.nn.conv2d()
tf.nn.conv2d()函数原型:tf.nn.conv2d(input,filter,strides,padding,use_cudnn_on_gpu=True, data_format='NHWC', dilations=[1, 1, 1, 1],name=None)参数:input:张量tensor,每个元素的格式必须float32或者float64。input的形状:[...原创 2019-02-17 12:53:26 · 168 阅读 · 0 评论 -
tensorflow中tf.flags的基本用法
直接上例子代码:# coding=utf-8import tensorflow as tfflags = tf.flags#flags是一个文件:flags.py,用于处理命令行参数的解析工作FLAGS = flags.FLAGS#FLAGS是一个对象,保存了解析后的命令行参数#第一个是参数名称,第二个参数是默认值,第三个是参数描述flags.DEFINE_string("input_...原创 2019-04-03 16:13:59 · 2111 阅读 · 1 评论