作 者:marsggbo 出 处:https://www.cnblogs.com/marsggbo版权声明:署名 - 非商业性使用 - 禁止演绎,协议普通文本 | 协议法律文本. --------------------------------------------------------------------------------------------------------------- Tensorflow       tf.app  &  tf.app.flags    用法介绍…
TensorFlow tf.app&tf.app.flags用法介绍 TensorFlow tf.app argparse  tf.app.flags 下面介绍 tf.app.flags.FLAGS的使用,主要是在用命令行执行程序时,需要传些参数,其实也就可以理解成对argparse库进行的封装,示例代码如下 #coding:utf-8  # 学习使用 tf.app.flags 使用,全局变量  # 可以再命令行中运行也是比较方便,如果只写 python app_flags.py 则代码运行时默…
tf.ConfigProto()函数用在创建session的时候,用来对session进行参数配置: config = tf.ConfigProto(allow_soft_placement=True, allow_soft_placement=True) config.gpu_options.per_process_gpu_memory_fraction = 0.4 #占用40%显存 sess = tf.Session(config=config) 1. 记录设备指派情况 :  tf.Conf…
tf.nn.embedding_lookup函数的用法主要是选取一个张量里面索引对应的元素.tf.nn.embedding_lookup(tensor, id):tensor就是输入张量,id就是张量对应的索引,其他的参数不介绍. 例如: import tensorflow as tf; import numpy as np; c = np.random.random([10,1]) b = tf.nn.embedding_lookup(c, [1, 3]) with tf.Session()…
原文地址: https://blog.csdn.net/Enchanted_ZhouH/article/details/77571939 ------------------------------------------------------------------------------------------------------- tf.Session():创建一个会话 tf.Session().as_default():创建一个默认会话 那么问题来了,会话和默认会话有什么区别呢?T…
一 .tf.variable() 在模型中每次调用都会重建变量,使其存储相同变量而消耗内存,如: def repeat_value(): weight=tf.variable(tf.random_normal([5,5,6]),name='weight') return weight 如果多次调用函数如: result1=repeat_value() result2=repeat_value() # 重复调用 将会重复创建一份变量,却保存相同模型参数.若使用字典可以解决此类问题,却破坏模型封装性…
一.TensorFlow高层次机器学习API (tf.contrib.learn) 1.tf.contrib.learn.datasets.base.load_csv_with_header 加载csv格式数据 2.tf.contrib.learn.DNNClassifier 建立DNN模型(classifier) 3.classifer.fit 训练模型 4.classifier.evaluate 评价模型 5.classifier.predict 预测新样本 完整代码: from __fut…
转载请注明出处:http://www.cnblogs.com/willnote/p/6758953.html 官方API定义 tf.argmax(input, axis=None, name=None, dimension=None) Returns the index with the largest value across axes of a tensor. Args: input: A Tensor. Must be one of the following types: float32…
tf.concat, tf.stack和tf.unstack的用法 tf.concat相当于numpy中的np.concatenate函数,用于将两个张量在某一个维度(axis)合并起来,例如: a = tf.constant([[1,2,3],[3,4,5]]) # shape (2,3) b = tf.constant([[7,8,9],[10,11,12]]) # shape (2,3) ab1 = tf.concat([a,b], axis=0) # shape(4,3) ab2 = t…
关于np.random.RandomState.np.random.rand.np.random.random.np.random_sample参考https://blog.csdn.net/lanchunhui/article/details/50405670 tf.nn.embedding_lookup函数的用法主要是选取一个张量里面索引对应的元素.tf.nn.embedding_lookup(params, ids):params可以是张量也可以是数组等,id就是对应的索引,其他的参数不介…
转载http://blog.csdn.net/jerr__y/article/details/60877873 1. 首先看看比较简单的 tf.name_scope(‘scope_name’). tf.name_scope 主要结合 tf.Variable() 来使用,方便参数命名管理. ''' Signature: tf.name_scope(*args, **kwds) Docstring: Returns a context manager for use when defining a…
1.tf.reduce_max函数的作用:计算张量的各个维度上的元素的最大值.例子: import tensorflow as tfmax_value = tf.reduce_max([1, 3, 2])with tf.Session() as sess: max_value = sess.run(max_value) print(max_value)结果为3    2.tf.sequence_mask的作用是构建序列长度的mask标志 . 例子: import tensorflow as tf…
TensorFlow函数:tf.where 在之前版本对应函数tf.select 官方解释: tf.where(input, name=None)` Returns locations of true values in a boolean tensor. This operation returns the coordinates of true elements in input. The coordinates are returned in a 2-D tensor where the…
###python自带的zip函数 与 tf.data.Dataset.zip函数 功能用法相似 ''' zip([iterator1,iterator2,]) 将可迭代对象中对应的元素打包成一个元祖,返回有这些元祖组成的对象,用list把这个对象转化成列表 ''' a=[1,2,3] b = [4,5,6] c = [7,8,9,10,11] res1 = zip(a,b) res2 = zip(a,c) print('返回一个对象%s,用list转化成列表:'%res1,list(res1)…
函数原型:tf.placeholder(dtype, shape=None, name=None) 使用说明:该函数用于得到传递进来的真实的训练样本.同时也可以理解为形参, 用于定义过程,在执行的时候再赋具体的值.(相当于首先定义一个容器,包含容量.size等信息,真正调用的时候再往容器里面注入东西) 注意:不必指定初始值,可以在运行时,通过Session.run 函数的参数"feed_dict={x : value}"进行赋值 参数说明: dtype:数据类型.常用的是tf.floa…
最近在研究学习TensorFlow,在做识别手写数字的demo时,遇到了tf.nn.conv2d这个方法,查阅了官网的API 发现讲得比较简略,还是没理解.google了一下,参考了网上一些朋友写得博客,结合自己的理解,差不多整明白了. 方法定义tf.nn.conv2d (input, filter, strides, padding, use_cudnn_on_gpu=None, data_format=None, name=None) 参数:**input : ** 输入的要做卷积的图片,要…
1. tf.add(x,  y, name) Args: x: A `Tensor`. Must be one of the following types: `bfloat16`, `half`, `float32`, `float64`, `uint8`, `int8`, `int16`, `int32`, `int64`, `complex64`, `complex128`, `string`. y: A `Tensor`. Must have the same type as `x`.…
https://blog.csdn.net/lanchunhui/article/details/61712830 https://www.cnblogs.com/silence-tommy/p/7029561.html 二者的主要区别在于: tf.Variable:主要在于一些可训练变量(trainable variables),比如模型的权重(weights,W)或者偏执值(bias): 声明时,必须提供初始值: 名称的真实含义,在于变量,也即在真实训练时,其值是会改变的,自然事先需要指定初…
以下这些函数可以用于解决梯度消失或梯度爆炸问题上. 1. tf.clip_by_value tf.clip_by_value( t, clip_value_min, clip_value_max, name=None ) Returns:A clipped Tensor. 输入一个张量t,把t中的每一个元素的值都压缩在clip_value_min和clip_value_max之间.小于min的让它等于min,大于max的元素的值等于max. 例子: import tensorflow as tf…
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # number 1 to 10 data mnist = input_data.read_data_sets('MNIST_data', one_hot=True) def compute_accuracy(v_xs, v_ys): global prediction y_pre = sess.run(prediction, fe…
1. tf.add(a, b) 与 a+b 在神经网络前向传播的过程中,经常可见如下两种形式的代码: tf.add(tf.matmul(x, w), b) tf.matmul(x, w) + b 简而言之,就是 tf.add(a, b) 与 a + b二者的区别,类似的也有,tf.assign 与 =(赋值运算符)的差异. 在计算精度上,二者并没有差别.运算符重载的形式a+b,会在内部转换为,a.__add__(b),而a.__add__(b)会再一次地映射为tf.add,在 math_ops.…
____tz_zs tf.random_normal 从正态分布中输出随机值. . <span style="font-size:16px;">random_normal(shape,mean=0.0,stddev=1.0,dtype=tf.float32,seed=None,name=None)</span> . shape:一个一维整数张量或Python数组.代表张量的形状. mean:数据类型为dtype的张量值或Python值.是正态分布的均值. std…
转载:https://blog.csdn.net/akadiao/article/details/78552037 tf.FIFOQueue tf.FIFOQueue继承基类QueueBase. QueueBase主要包含入列(enqueue)和出列(dequeue)两个操作: enqueue操作返回计算图中的一个Operation节点,dequeue操作返回一个Tensor值.Tensor在创建时同样只是一个定义,需要放在Session中运行才能获得真正的数值. 参数: capacity:指定…
tf.random_normal 从正态分布输出随机值. random_normal(shape,mean=0.0,stddev=1.0,dtype=tf.float32,seed=None,name=None) shape:一个一维整数张量或Python数组.代表张量的形状.mean:数据类型为dtype的张量值或Python值.是正态分布的均值.stddev:数据类型为dtype的张量值或Python值.是正态分布的标准差dtype: 输出的数据类型.seed:一个Python整数.是随机种…
tensorflow中有很多需要变量共享的场合,比如在多个GPU上训练网络时网络参数和训练数据就需要共享. tf通过 tf.get_variable() 可以建立或者获取一个共享的变量. tf.get_variable函数的作用从tf的注释里就可以看出来-- 'Gets an existing variable with this name or create a new one'. 与 tf.get_variable 函数相对的还有一个 tf.Variable 函数,两者的区别是: tf.Va…
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))…
ValueError: Variable conv1/weights1 already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at: 在使用tensorflow 中的tf.variable_scope和tf.get_variable搭建网络时,重复运行程序会报以上的ValueError错误,这是因为第二次运行时,内存中已经存在名字相同的层或者参数,发生了冲突,所以会提示…
(一) tensorflow笔记:流程,概念和简单代码注释 (二) tensorflow笔记:多层CNN代码分析 (三) tensorflow笔记:多层LSTM代码分析 (四) tensorflow笔记:常用函数说明 (五) tensorflow笔记:模型的保存与训练过程可视化 (六)tensorflow笔记:使用tf来实现word2vec 时隔若干个月,又绕到了word2vec.关于word2vec的原理我就不叙述了,具体可见word2vec中的数学,写的非常好. 我后来自己用Python实现…
1. tf.add(a, b) 与 a+b 在神经网络前向传播的过程中,经常可见如下两种形式的代码: tf.add(tf.matmul(x, w), b) tf.matmul(x, w) + b 简而言之,就是 tf.add(a, b) 与 a + b二者的区别,类似的也有,tf.assign 与 =(赋值运算符)的差异. 在计算精度上,二者并没有差别.运算符重载的形式a+b,会在内部转换为,a.__add__(b),而a.__add__(b)会再一次地映射为tf.add,在 math_ops.…
import tensorflow as tfimport numpy as npsess=tf.Session()a=np.ones((5,6))c=tf.cast(tf.reduce_sum(a, axis=1),tf.bool) # tf.reduce_sum 表示按照axis方向求和c=sess.run(c)print('c=',c)print('c.shape',c.shape)k=tf.where(c) # 因为返回的是索引值为列表中k=sess.run(k)print('k=',k…